Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2013, Francis Galiegue <fgaliegue@gmail.com>
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the Lesser GNU General Public License as
   * published by the Free Software Foundation, either version 3 of the
   * License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * Lesser GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 package com.github.fge.jsonschema.keyword.validator.common;
 
 
 import java.util.Map;
 import java.util.Set;
 
 import static com.github.fge.jsonschema.messages.KeywordValidationMessages.*;
 
 /*
  * In spite of syntax differences, the digested data is the same, which is why
  * this validator is in common/
  */
 public final class DependenciesValidator
     extends AbstractKeywordValidator
 {
     private final Multimap<StringStringpropertyDeps;
     private final Set<StringschemaDeps;
 
     public DependenciesValidator(final JsonNode digest)
     {
         super("dependencies");
 
         /*
          * Property dependencies
          */
         final ImmutableMultimap.Builder<StringStringmapBuilder
             = ImmutableMultimap.builder();
         final Map<StringJsonNodemap
             = JacksonUtils.asMap(digest.get("propertyDeps"));
 
         String key;
         for (final Map.Entry<StringJsonNodeentrymap.entrySet()) {
             key = entry.getKey();
             for (final JsonNode elemententry.getValue())
                 mapBuilder.put(keyelement.textValue());
         }
 
          = mapBuilder.build();
 
         /*
          * Schema dependencies
          */
         final ImmutableSet.Builder<StringsetBuilder
             = ImmutableSet.builder();
 
         for (final JsonNode nodedigest.get("schemaDeps"))
             setBuilder.add(node.textValue());
 
          = setBuilder.build();
     }
 
     @Override
     public void validate(
         final Processor<ValidationDataProcessingReportprocessor,
         final ProcessingReport reportfinal ValidationData data)
         throws ProcessingException
     {
         final JsonNode instance = data.getInstance().getNode();
         final Set<Stringfields = Sets.newHashSet(instance.fieldNames());
 
         Collection<Stringcollection;
         Set<Stringset;
 
         for (final String field.keySet()) {
             if (!fields.contains(field))
                 continue;
             collection = .get(field);
             set = Sets.newLinkedHashSet(collection);
            set.removeAll(fields);
            if (!set.isEmpty())
                report.error(newMsg(data).message()
                    .put("property"field).put("required"collection)
                    .put("missing"set));
        }
        if (.isEmpty())
            return;
        final SchemaTree tree = data.getSchema();
        ValidationData newData;
        JsonPointer pointer;
        for (final String field) {
            if (!fields.contains(field))
                continue;
            pointer = JsonPointer.of(field);
            newData = data.withSchema(tree.append(pointer));
            processor.process(reportnewData);
        }
    }
    @Override
    public String toString()
    {
        return  + ": " + .size() + " property dependencies, "
            + .size() + " schema dependencies";
    }
New to GrepCode? Check out our FAQ X