Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
The BSD License Copyright (c) 2010-2012 RIPE NCC All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the RIPE NCC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 package net.ripe.rpki.commons.validation;
 
 
 import java.net.URI;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 public final class ValidationResult implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
 
 
 
     private ValidationResult(ValidationLocation location) {
         setLocation(location);
     }
 
     public static ValidationResult withLocation(URI uri) {
         return new ValidationResult(new ValidationLocation(uri));
     }
 
     public static ValidationResult withLocation(String name) {
         return new ValidationResult(new ValidationLocation(name));
     }
 
     public static ValidationResult withLocation(ValidationLocation location) {
         return new ValidationResult(location);
     }
 
     public void setLocation(ValidationLocation location) {
          = location;
 
         if (!.containsKey()) {
             Map<ValidationStatusList<ValidationCheck>> locationResults = new LinkedHashMap<ValidationStatusList<ValidationCheck>>();
             locationResults.put(.new ArrayList<ValidationCheck>());
             locationResults.put(.new ArrayList<ValidationCheck>());
             locationResults.put(.new ArrayList<ValidationCheck>());
             .put(locationResults);
         }
     }
 
     private void setValidationCheckForCurrentLocation(ValidationStatus statusString keyString... param) {
         Map<ValidationStatusList<ValidationCheck>> currentResults = .get();
         List<ValidationCheckchecksForStatus = currentResults.get(status);
         checksForStatus.add(new ValidationCheck(statuskeyparam));
     }
 
     public void pass(String keyString... param) {
     }
 
     public void warn(String keyString... param) {
     }
 
    public void error(String keyString... param) {
    }
    public boolean warnIfFalse(boolean conditionString keyString... param) {
        Validate.notNull(key"key is required");
        if (condition) {
            setValidationCheckForCurrentLocation(.keyparam);
        } else {
            warn(keyparam);
        }
        return condition;
    }
    public boolean warnIfTrue(boolean conditionString keyString... param) {
        return warnIfFalse(!conditionkeyparam);
    }
    public boolean warnIfNull(Object objectString keyString... param) {
        return warnIfTrue(object == nullkeyparam);
    }
    public boolean warnIfNotNull(Object objectString keyString... param) {
        return warnIfTrue(object != nullkeyparam);
    }
    public void rejectForLocation(ValidationLocation locationString keyString... param) {
        ValidationLocation locationBefore = ;
        setLocation(location);
        setLocation(locationBefore);
    }
    public void warnForLocation(ValidationLocation locationString keyString... param) {
        ValidationLocation locationBefore = ;
        setLocation(location);
        setLocation(locationBefore);
    }
    public boolean rejectIfFalse(boolean conditionString keyString... param) {
        Validate.notNull(key"key is required");
        if (condition) {
            setValidationCheckForCurrentLocation(.keyparam);
        } else {
            setValidationCheckForCurrentLocation(.keyparam);
        }
        return condition;
    }
    public boolean rejectIfTrue(boolean conditionString keyString... param) {
        return rejectIfFalse(!conditionkeyparam);
    }
    public boolean rejectIfNull(Object objectString keyString... param) {
        return rejectIfTrue(object == nullkeyparam);
    }
    public boolean rejectIfNotNull(Object objectString keyString... param) {
        return rejectIfTrue(object != nullkeyparam);
    }
    public void addMetric(String nameString value) {
        if (!.containsKey()) {
            .put(new ArrayList<ValidationMetric>());
        }
        .get().add(new ValidationMetric(namevalue, DateTimeUtils.currentTimeMillis()));
    }
    // Accessors
        return .keySet();
    }
        return ;
    }
    public boolean hasFailures() {
        return !getFailuresForAllLocations().isEmpty();
    }
    public boolean hasWarnings() {
        return !getWarnings().isEmpty();
    }
    public boolean hasNoFailuresOrWarnings() {
        return !hasFailures() && !hasWarnings();
    }
        return new HashSet<ValidationCheck>(getFailures());
    }
        List<ValidationCheckfailures = new ArrayList<ValidationCheck>();
        for (ValidationLocation location : getValidatedLocations()) {
            failures.addAll(getChecks(location.));
        }
        return failures;
    }
    public List<ValidationCheckgetFailures(ValidationLocation location) {
        return getChecks(location.);
    }
    public boolean hasFailureForCurrentLocation() {
        return hasFailureForLocation();
    }
    public boolean hasFailureForLocation(ValidationLocation location) {
        return !getFailures(location).isEmpty();
    }
    public List<ValidationCheckgetWarnings() {
        List<ValidationCheckwarnings = new ArrayList<ValidationCheck>();
        for (ValidationLocation location : getValidatedLocations()) {
            warnings.addAll(getChecks(location.));
        }
        return warnings;
    }
    private List<ValidationCheckgetChecks(ValidationLocation locationValidationStatus status) {
        if (.containsKey(location)) {
            return .get(location).get(status);
        } else {
            return new ArrayList<ValidationCheck>();
        }
    }
    }
        ArrayList<ValidationCheckallChecks = new ArrayList<ValidationCheck>();
        if (.containsKey(location)) {
            Map<ValidationStatusList<ValidationCheck>> locationChecksMap = .get(location);
            allChecks.addAll(locationChecksMap.get(.));
            allChecks.addAll(locationChecksMap.get(.));
            allChecks.addAll(locationChecksMap.get(.));
        }
        return allChecks;
    }
        return getResult(checkKey);
    }
    public ValidationCheck getResult(ValidationLocation locationString checkKey) {
        List<ValidationCheckallChecks = getAllValidationChecksForLocation(location);
        for (ValidationCheck check : allChecks) {
            if (check.getKey().equals(checkKey)) {
                return check;
            }
        }
        return null;
    }
    public List<ValidationMetricgetMetrics(ValidationLocation location) {
        if (.containsKey(location)) {
            return Collections.unmodifiableList(.get(location));
        } else {
            return Collections.emptyList();
        }
    }
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this.);
    }
    public void addAll(ValidationResult that) {
        for (Entry<ValidationLocationMap<ValidationStatusList<ValidationCheck>>> resultsByLocation : that.results.entrySet()) {
            Map<ValidationStatusList<ValidationCheck>> map = .get(resultsByLocation.getKey());
            if (map == null) {
                map = new LinkedHashMap<ValidationStatusList<ValidationCheck>>();
                this..put(resultsByLocation.getKey(), map);
            }
            for (Entry<ValidationStatusList<ValidationCheck>> checks : resultsByLocation.getValue().entrySet()) {
                List<ValidationChecklist = map.get(checks.getKey());
                if (list == null) {
                    list = new ArrayList<ValidationCheck>();
                    map.put(checks.getKey(), list);
                }
                list.addAll(checks.getValue());
            }
        }
    }
New to GrepCode? Check out our FAQ X