Java Code Examples for com.google.common.collect.TreeMultimap

The following examples show how to use com.google.common.collect.TreeMultimap. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private Multimap<Scope, String> getClassnames(final ASTNode node) {
	final ClassnameFinder cf = new ClassnameFinder(methodsAsRoots);
	node.accept(cf);

	final Multimap<Scope, String> classnames = TreeMultimap.create();

	for (final Entry<ASTNode, String> classname : cf.types.entries()) {
		final ASTNode parentNode = classname.getKey();
		final Scope sc = new Scope(
				classname.getKey().toString(),
				parentNode.getNodeType() == ASTNode.METHOD_DECLARATION ? ScopeType.SCOPE_METHOD
						: ScopeType.SCOPE_CLASS, TYPENAME,
				parentNode.getNodeType(), -1);
		classnames.put(sc, classname.getValue());
	}
	return classnames;
}
 
Example 2
/**
 * Return a multimap containing all the (local) variables of the given
 * scope.
 * 
 * @param cu
 * @return Multimap<Snippet, VariableName>
 */
public static Multimap<Scope, String> getScopeSnippets(final ASTNode cu) {
	final VariableScopeFinder scopeFinder = new VariableScopeFinder();
	cu.accept(scopeFinder);

	final Multimap<Scope, String> scopes = TreeMultimap.create();
	for (final Entry<ASTNode, Variable> variable : scopeFinder.variableScopes
			.entries()) {
		final int astNodeType = variable.getKey().getNodeType();
		final int astNodeParentType;
		if (variable.getKey().getParent() == null) {
			astNodeParentType = -1;
		} else {
			astNodeParentType = variable.getKey().getParent().getNodeType();
		}
		scopes.put(
				new Scope(variable.getKey().toString(),
						variable.getValue().scope,
						variable.getValue().type, astNodeType,
						astNodeParentType), variable.getValue().name);
	}

	return scopes;

}
 
Example 3
Source Project: datawave   Source File: Intersection.java    License: Apache License 2.0 6 votes vote down vote up
static TreeMultimap<String,IndexStream> nextAll(String key, Collection<IndexStream> streams) {
    TreeMultimap<String,IndexStream> newChildren = TreeMultimap.create(Ordering.natural(), Ordering.arbitrary());
    for (IndexStream itr : streams) {
        if (!isDay(key) && isDay(key(itr.peek()))) {
            newChildren.put(itr.peek().first(), itr);
        } else {
            itr.next();
            if (itr.hasNext()) {
                newChildren.put(itr.peek().first(), itr);
            } else {
                return TreeMultimap.create(Ordering.natural(), Ordering.arbitrary());
            }
        }
    }
    return newChildren;
}
 
Example 4
public static Multimap<Scope, String> getScopeSnippets(final ASTNode node,
		final boolean methodAsRoots) {
	final ScopeFinder scopeFinder = new ScopeFinder(methodAsRoots);
	node.accept(scopeFinder);

	final Multimap<Scope, String> scopes = TreeMultimap.create();
	for (final Entry<ASTNode, Method> method : scopeFinder.methods
			.entries()) {
		scopes.put(new Scope(method.getKey().toString(),
				method.getValue().type, METHOD_CALL, 0, 0), method
				.getValue().name);
	}

	return scopes;

}
 
Example 5
public void build() {
    groups = TreeMultimap.create(new Comparator<String>() {
        public int compare(String string1, String string2) {
            return string1.compareToIgnoreCase(string2);
        }
    }, new Comparator<TaskDetails>() {
        public int compare(TaskDetails task1, TaskDetails task2) {
            return task1.getPath().compareTo(task2.getPath());
        }
    });
    for (TaskReportModel project : projects) {
        for (String group : project.getGroups()) {
            for (final TaskDetails task : project.getTasksForGroup(group)) {
                groups.put(group, mergeTasksWithSameName ? new MergedTaskDetails(task) : task);
            }
        }
    }
}
 
Example 6
Source Project: datawave   Source File: OrIterator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Allows creators of this iterator to defer creating the sorted mapping of values to iterators until some condition is met. This is intended to let us
 * build the tree of iterators in <code>init()</code> and defer sorting the iterators until after <code>seek()</code> is called.
 */
public void initialize() {
    Comparator<T> keyComp = Util.keyComparator();
    // nestedIteratorComparator will keep a deterministic ordering, unlike hashCodeComparator
    Comparator<NestedIterator<T>> itrComp = Util.nestedIteratorComparator();
    
    transformer = Util.keyTransformer();
    transforms = new HashMap<>();
    
    includeHeads = TreeMultimap.create(keyComp, itrComp);
    initSubtree(includeHeads, includes, transformer, transforms, false);
    
    if (contextIncludes.size() > 0) {
        contextIncludeHeads = TreeMultimap.create(keyComp, itrComp);
        contextIncludeNullHeads = TreeMultimap.create(keyComp, itrComp);
    }
    
    if (contextExcludes.size() > 0) {
        contextExcludeHeads = TreeMultimap.create(keyComp, itrComp);
        contextExcludeNullHeads = TreeMultimap.create(keyComp, itrComp);
    }
    
    next();
}
 
Example 7
Source Project: datawave   Source File: NestedIteratorContextUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Process moves against the set of sources. Set the context and move each. Will update the headMap with new references except for null responses. A null
 * response indicates that the iterator had no key's left when moving to context
 * 
 * @param context
 * @param sourcesToMove
 * @param headMap
 * @param transformer
 * @param <T>
 * @return non-null Set of null response iterators
 */
private static <T> Set<NestedIterator<T>> processMoves(T context, Set<NestedIterator<T>> sourcesToMove, TreeMultimap<T,NestedIterator<T>> headMap,
                Util.Transformer<T> transformer) {
    Set<NestedIterator<T>> nullSources = new HashSet<>();
    for (NestedIterator<T> contextRequiredIterator : sourcesToMove) {
        contextRequiredIterator.setContext(context);
        T result = contextRequiredIterator.move(context);
        if (result == null) {
            // beyond the end of the iterator
            nullSources.add(contextRequiredIterator);
        } else {
            T transformed = transformer.transform(result);
            headMap.put(transformed, contextRequiredIterator);
        }
    }
    
    return nullSources;
}
 
Example 8
Source Project: datawave   Source File: NegationFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Throwable {
    List<String> filterSet1 = Lists.newArrayList("a", "b", "c", "q", "r", "s");
    Itr<String> f1 = new Itr<>(filterSet1);
    List<String> filterSet2 = Lists.newArrayList("a", "b", "c", "d", "e", "f");
    Itr<String> f2 = new Itr<>(filterSet2);
    TreeMultimap<String,NestedIterator<String>> mmap = TreeMultimap.create(Util.keyComparator(), Util.hashComparator());
    mmap.put(f1.next(), f1);
    mmap.put(f2.next(), f2);
    
    assertTrue(NegationFilter.isFiltered("e", mmap, Util.keyTransformer()));
    assertEquals(2, mmap.keySet().size());
    assertNotEquals(null, mmap.get("e"));
    assertNotEquals(null, mmap.get("q"));
    assertEquals(2, mmap.values().size());
}
 
Example 9
Source Project: j2objc   Source File: ASTClassInfoPrinter.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String... args) {
  // Clear saved state for new calls.
  tree = TreeMultimap.create();
  astLookup = Sets.newHashSet();
  ClassPath cp = null;
  try {
    cp = ClassPath.from(ClassLoader.getSystemClassLoader());
  } catch (IOException e) {
    ErrorUtil.error(e.getMessage());
    System.exit(1);
  }
  for (ClassInfo c : cp.getTopLevelClasses("org.eclipse.jdt.core.dom")){
    astLookup.add(c.getSimpleName());
  }
  for (ClassInfo ci : cp.getTopLevelClasses("com.google.devtools.j2objc.ast")) {
    // Ignore package-info and JUnit tests.
    if (ci.getSimpleName().equals("package-info") || TestCase.class.isAssignableFrom(ci.load())) {
      continue;
    }
    walkSuperclassHierarchy(ci.load());
  }
  // Print hierarchy descending from Object.
  printClassHierarchy("Object", "");
}
 
Example 10
Source Project: datawave   Source File: NegationFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testContains() throws Throwable {
    List<String> filterSet1 = Lists.newArrayList("a", "b");
    Itr<String> f1 = new Itr<>(filterSet1);
    List<String> filterSet2 = Lists.newArrayList("a", "b", "c", "d", "e", "f");
    Itr<String> f2 = new Itr<>(filterSet2);
    TreeMultimap<String,NestedIterator<String>> mmap = TreeMultimap.create(Util.keyComparator(), Util.hashComparator());
    mmap.put(f1.next(), f1);
    mmap.put("c", f2);
    
    assertTrue(NegationFilter.isFiltered("c", mmap, Util.keyTransformer()));
    // even though filterSet1 is outside the bounds, the contains check doesn't move anything, this is expected and good
    assertEquals(2, mmap.keySet().size());
    Iterator<String> i = mmap.keySet().iterator();
    assertEquals("a", i.next());
    assertEquals("c", i.next());
    assertFalse(i.hasNext());
    assertEquals(2, mmap.values().size());
}
 
Example 11
Source Project: snowblossom   Source File: WalletUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static Collection<AddressSpecHash> getAddressesByAge(WalletDatabase db, NetworkParams params)
{
  TreeMultimap<Long, AddressSpecHash> age_map = TreeMultimap.create();
  for(AddressSpec spec : db.getAddressesList())
  {
    String addr = AddressUtil.getAddressString(spec, params);
    long tm = 0;
    if (db.getAddressCreateTimeMap().containsKey(addr))
    {
      tm = db.getAddressCreateTimeMap().get(addr);
    }
    age_map.put(tm, AddressUtil.getHashForSpec(spec));

  }

  return age_map.values();

}
 
Example 12
Source Project: incubator-pinot   Source File: EntityUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Encodes dimensions multimap to filter strings.
 *
 * @param filters dimensions multimap
 * @return filter string fragments
 */
public static List<String> encodeDimensions(Multimap<String, String> filters) {
  List<String> output = new ArrayList<>();

  Multimap<String, String> sorted = TreeMultimap.create(filters);
  for(Map.Entry<String, String> entry : sorted.entries()) {
    String operator = "=";
    String value = entry.getValue();

    // check for exclusion case
    for (Map.Entry<String, String> prefix : FILTER_TO_OPERATOR.entrySet()) {
      if (entry.getValue().startsWith(prefix.getKey())) {
        operator = prefix.getValue();
        value = entry.getValue().substring(prefix.getKey().length());
        break;
      }
    }

    output.add(EntityUtils.encodeURNComponent(String.format("%s%s%s", entry.getKey(), operator, value)));
  }

  return output;
}
 
Example 13
Source Project: snowblossom   Source File: RocksDBMapMutationSet.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void addAll(TreeMultimap<ByteString, ByteString> map)
{
  try(WriteBatch batch = new WriteBatch())
  {
    byte b[]=new byte[0];

    for(Map.Entry<ByteString, ByteString> me : map.entries())
    {
      ByteString w = getDBKey(me.getKey(), me.getValue());
      batch.put(w.toByteArray(), b);
    }

    db.write(jdb.getWriteOption(), batch);
  }
  catch(RocksDBException e)
  {
    throw new RuntimeException(e);
  }

}
 
Example 14
Source Project: emissary   Source File: MetadataDictionaryUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Read each line of input, tokenize them into key/value pairs, perform a lookup/transformation of the keys via the
 * MetadataDictionary where applicable, and return the results as a map.
 * 
 * @param input the bytes to convert
 * @param output a ByteArrayOutputStream to write failed parse attempts to
 * @return a Map containing each line converted to a key/value pair and sorted alphabetically by key
 * @throws IOException If there is some I/O problem.
 */
public Map<String, Collection<String>> convertLinesToMap(final byte[] input, final ByteArrayOutputStream output) throws IOException {
    final TreeMultimap<String, String> kv = TreeMultimap.create();
    final LineTokenizer ltok = new LineTokenizer(input, this.charset);

    // Look at each line for a key value and run it through the dictionary
    while (ltok.hasMoreTokens()) {
        final String line = ltok.nextToken();
        final int pos = line.indexOf(SEP);
        if (pos == -1) {
            output.write(line.getBytes());
            output.write('\n');
            this.logger.debug("Found no key/value pair on line " + line);
        } else {
            final String key = line.substring(0, pos);
            final String value = line.substring(pos + 1);
            final String nkey = this.dict.map(this.servicePrefix + key);
            kv.put(nkey, value.trim());
            this.logger.debug("Mapped key " + key + " to " + nkey + ": " + value);
        }
    }
    return new TreeMap<>(kv.asMap());
}
 
Example 15
Source Project: Elasticsearch   Source File: ExpressionFormatter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String visitObjectLiteral(ObjectLiteral node, Void context) {
    StringBuilder builder = new StringBuilder("{");
    boolean first = true;
    TreeMultimap<String, Expression> sorted = TreeMultimap.create(
            Ordering.natural().nullsLast(),
            Ordering.usingToString().nullsLast()
    );
    sorted.putAll(node.values());
    for (Map.Entry<String, Expression> entry : sorted.entries()) {
        if (!first) {
            builder.append(", ");
        } else {
            first = false;
        }
        builder.append(formatIdentifier(entry.getKey()))
               .append("= ")
               .append(entry.getValue().accept(this, context));

    }
    return builder.append("}").toString();
}
 
Example 16
public static Multimap<Scope, String> getScopeSnippets(final ASTNode node,
		final boolean methodAsRoots) {
	final ScopeFinder scopeFinder = new ScopeFinder(methodAsRoots);
	node.accept(scopeFinder);

	final Multimap<Scope, String> scopes = TreeMultimap.create();
	for (final Entry<ASTNode, Method> method : scopeFinder.methods
			.entries()) {
		scopes.put(new Scope(method.getKey().toString(),
				method.getValue().type, METHOD_CALL, 0, 0), method
				.getValue().name);
	}

	return scopes;

}
 
Example 17
/**
 * Return a multimap containing all the (local) variables of the given
 * scope.
 * 
 * @param cu
 * @return Multimap<Snippet, VariableName>
 */
public static Multimap<Scope, String> getScopeSnippets(final ASTNode cu) {
	final VariableScopeFinder scopeFinder = new VariableScopeFinder();
	cu.accept(scopeFinder);

	final Multimap<Scope, String> scopes = TreeMultimap.create();
	for (final Entry<ASTNode, Variable> variable : scopeFinder.variableScopes
			.entries()) {
		final int astNodeType = variable.getKey().getNodeType();
		final int astNodeParentType;
		if (variable.getKey().getParent() == null) {
			astNodeParentType = -1;
		} else {
			astNodeParentType = variable.getKey().getParent().getNodeType();
		}
		scopes.put(
				new Scope(variable.getKey().toString(),
						variable.getValue().scope,
						variable.getValue().type, astNodeType,
						astNodeParentType), variable.getValue().name);
	}

	return scopes;

}
 
Example 18
Source Project: tracecompass   Source File: TreeMapStore.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Constructor
 */
public TreeMapStore() {
    /*
     * For the start times index, the "key comparator" will compare the
     * start times as longs directly. This is the primary comparator for its
     * tree map.
     *
     * The secondary "value" comparator will check the end times first, and
     * in the event of a tie, defer to the ISegment's Comparable
     * implementation, a.k.a. its natural ordering.
     */
    fStartTimesIndex = TreeMultimap.create(Comparator.<Long>naturalOrder(),
            Comparator.comparingLong(E::getEnd).thenComparing(Function.identity()));

    fSize = 0;
}
 
Example 19
Source Project: kylin-on-parquet-v2   Source File: SortUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static <T extends Comparable, E extends Comparable> Iterator<T> extractAndSort(Iterator<T> input, Function<T, E> extractor) {
    TreeMultimap<E, T> reorgnized = TreeMultimap.create();
    while (input.hasNext()) {
        T t = input.next();
        E e = extractor.apply(t);
        reorgnized.put(e, t);
    }
    return reorgnized.values().iterator();
}
 
Example 20
Source Project: onos   Source File: MetricsListCommand.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    MetricsService metricsService = get(MetricsService.class);

    MetricFilter filter = metricName != null ? (name, metric) -> name.equals(metricName) : MetricFilter.ALL;

    TreeMultimap<String, Metric> matched = listMetrics(metricsService, filter);
    matched.asMap().forEach((name, metrics) -> {
        if (outputJson()) {
            metrics.forEach(metric -> print("%s", json(metric)));
        } else {
            metrics.forEach(metric -> printMetric(name, metric));
        }
    });
}
 
Example 21
public void build(TaskReportModel model) {
    Comparator<String> keyComparator = GUtil.last(GUtil.last(STRING_COMPARATOR, OTHER_GROUP), DEFAULT_GROUP);
    Comparator<TaskDetails> taskComparator = new Comparator<TaskDetails>() {
        public int compare(TaskDetails task1, TaskDetails task2) {
            int diff = STRING_COMPARATOR.compare(task1.getPath().getName(), task2.getPath().getName());
            if (diff != 0) {
                return diff;
            }
            Path parent1 = task1.getPath().getParent();
            Path parent2 = task2.getPath().getParent();
            if (parent1 == null && parent2 != null) {
                return -1;
            }
            if (parent1 != null && parent2 == null) {
                return 1;
            }
            if (parent1 == null) {
                return 0;
            }
            return parent1.compareTo(parent2);
        }
    };
    groups = TreeMultimap.create(keyComparator, taskComparator);
    for (String group : model.getGroups()) {
        groups.putAll(group, model.getTasksForGroup(group));
    }
    String otherGroupName = findOtherGroup(groups.keySet());
    if (otherGroupName != null && groups.keySet().contains(DEFAULT_GROUP)) {
        groups.putAll(otherGroupName, groups.removeAll(DEFAULT_GROUP));
    }
    if (groups.keySet().contains(DEFAULT_GROUP) && groups.keySet().size() > 1) {
        groups.putAll(OTHER_GROUP, groups.removeAll(DEFAULT_GROUP));
    }
}
 
Example 22
Source Project: batfish   Source File: ConvertConfigurationAnswerElement.java    License: Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
@JsonCreator
ConvertConfigurationAnswerElement(
    @JsonProperty(PROP_DEFINED_STRUCTURES)
        SortedMap<String, SortedMap<String, SortedMap<String, DefinedStructureInfo>>>
            definedStructures,
    @JsonProperty(PROP_REFERENCED_STRUCTURES)
        SortedMap<
                String,
                SortedMap<String, SortedMap<String, SortedMap<String, SortedSet<Integer>>>>>
            referencedstructures,
    @JsonProperty(PROP_CONVERT_STATUS) SortedMap<String, ConvertStatus> convertStatus,
    @JsonProperty(PROP_ERRORS) SortedMap<String, BatfishException.BatfishStackTrace> errors,
    @JsonProperty(PROP_ERROR_DETAILS) SortedMap<String, ErrorDetails> errorDetails,
    @JsonProperty(PROP_UNDEFINED_REFERENCES)
        SortedMap<
                String,
                SortedMap<String, SortedMap<String, SortedMap<String, SortedSet<Integer>>>>>
            undefinedReferences,
    @JsonProperty(PROP_VERSION) String version,
    @JsonProperty(PROP_WARNINGS) SortedMap<String, Warnings> warnings,
    @JsonProperty(PROP_FILE_MAP) @Nullable Multimap<String, String> fileMap) {
  _definedStructures = firstNonNull(definedStructures, new TreeMap<>());
  _errors = firstNonNull(errors, new TreeMap<>());
  _errorDetails = firstNonNull(errorDetails, new TreeMap<>());
  _fileMap = firstNonNull(fileMap, TreeMultimap.create());
  _convertStatus = firstNonNull(convertStatus, new TreeMap<>());

  _referencedStructures = firstNonNull(referencedstructures, new TreeMap<>());
  _undefinedReferences = firstNonNull(undefinedReferences, new TreeMap<>());
  _version = firstNonNull(version, BatfishVersion.getVersionStatic());
  _warnings = firstNonNull(warnings, new TreeMap<>());
}
 
Example 23
Source Project: datawave   Source File: PropogatingIteratorTest.java    License: Apache License 2.0 5 votes vote down vote up
private SortedMultiMapIterator createSourceWithTestData() {
    TreeMultimap<Key,Value> map = TreeMultimap.create();
    
    map.put(newKey(SHARD, FIELD_TO_AGGREGATE, "abc", true), new Value(createValueWithUid("abc.0").build().toByteArray()));
    map.put(newKey(SHARD, FIELD_TO_AGGREGATE, "abc"), new Value(createValueWithUid("abc.1").build().toByteArray()));
    map.put(newKey(SHARD, FIELD_TO_AGGREGATE, "abc"), new Value(createValueWithUid("abc.2").build().toByteArray()));
    map.put(newKey(SHARD, FIELD_TO_AGGREGATE, "abc"), new Value(createValueWithUid("abc.3").build().toByteArray()));
    map.put(newKey(SHARD, FIELD_TO_AGGREGATE, "abc"), new Value(createValueWithUid("abc.4").build().toByteArray()));
    
    map.put(newKey(SHARD, FIELD_TO_AGGREGATE, "abd"), new Value(createValueWithUid("abc.3").build().toByteArray()));
    
    return new SortedMultiMapIterator(map);
}
 
Example 24
Source Project: cukes   Source File: DocumentationGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private static Map<CukesComponent, Multimap<StepType, StepDefinition>> createStepsStubs() {
    Map<CukesComponent, Multimap<StepType, StepDefinition>> steps = new LinkedHashMap<>();
    for (CukesComponent component : CukesComponent.values()) {
        Multimap<StepType, StepDefinition> stepsMap = TreeMultimap.create(StepType.comparator, StepDefinition.comparator);
        steps.put(component, stepsMap);
    }
    return steps;
}
 
Example 25
Source Project: datawave   Source File: PropogatingIteratorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testNoAggregatorWithDeepCopy() throws IOException {
    TreeMultimap<Key,Value> map = TreeMultimap.create();
    
    map.put(newKey(SHARD, FIELD_TO_AGGREGATE, "abc"), new Value(createValueWithUid("abc.0").build().toByteArray()));
    map.put(newKey(SHARD, FIELD_TO_AGGREGATE, "abc"), new Value(createValueWithRemoveUid("abc.0").build().toByteArray()));
    
    map.put(newKey(SHARD, FIELD_TO_AGGREGATE, "abd"), new Value(createValueWithUid("abc.3").build().toByteArray()));
    
    SortedMultiMapIterator data = new SortedMultiMapIterator(map);
    
    PropogatingIterator iter = new PropogatingIterator();
    Map<String,String> options = Maps.newHashMap();
    
    IteratorEnvironment env = new MockIteratorEnvironment(false);
    
    iter.init(data, options, env);
    iter = iter.deepCopy(env);
    
    iter.seek(new Range(), Collections.emptyList(), false);
    
    Assert.assertTrue(iter.hasTop());
    
    Key topKey = iter.getTopKey();
    
    Assert.assertEquals(newKey(SHARD, FIELD_TO_AGGREGATE, "abc"), topKey);
    validateUids(iter.getTopValue(), "abc.0");
    iter.next();
    Assert.assertEquals(newKey(SHARD, FIELD_TO_AGGREGATE, "abc"), topKey);
    validateRemoval(iter.getTopValue(), "abc.0");
    iter.next();
    topKey = iter.getTopKey();
    Assert.assertEquals(newKey(SHARD, FIELD_TO_AGGREGATE, "abd"), topKey);
    
}
 
Example 26
Source Project: api-mining   Source File: AllScopeExtractor.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public Multimap<Scope, String> getFromNode(ASTNode node) {
	final Multimap<Scope, String> scopes = TreeMultimap.create();
	for (final IScopeExtractor extractor : allExtractors) {
		scopes.putAll(extractor.getFromNode(node));
	}
	return scopes;
}
 
Example 27
Source Project: datawave   Source File: JsonObjectFlattenerImplTest.java    License: Apache License 2.0 5 votes vote down vote up
private void printMap(Multimap<String,String> fieldMap) {
    TreeMultimap<String,String> sorted = TreeMultimap.create(fieldMap);
    for (String key : sorted.keySet()) {
        System.out.print(key + ": ");
        Collection<String> values = fieldMap.get(key);
        for (String value : values) {
            System.out.print("[" + value + "]");
        }
        System.out.print("\n");
    }
    System.out.println();
}
 
Example 28
Source Project: datawave   Source File: Intersection.java    License: Apache License 2.0 5 votes vote down vote up
static TreeMultimap<String,IndexStream> pivot(TreeMultimap<String,IndexStream> children) {
    TreeMultimap<String,IndexStream> newChildren = TreeMultimap.create(Ordering.natural(), Ordering.arbitrary());
    final String max = children.keySet().last();
    newChildren.putAll(max, children.removeAll(max));
    for (IndexStream itr : children.values()) {
        // move this iterator forward until we get to a key past the max processed thus far
        String dayOrShard = null;
        while (itr.hasNext()) {
            
            dayOrShard = key(itr.peek());
            if (dayOrShard.compareTo(max) >= 0) {
                break;
            }
            if (isDay(dayOrShard) && max.startsWith(dayOrShard)) {
                // use the existing max instead of the day to add to the list
                dayOrShard = max;
                break;
            }
            itr.next();
        }
        // add the item into our map
        if (itr.hasNext()) {
            newChildren.put(dayOrShard, itr);
        } else {
            // nobody has anything past max, so no intersection
            return TreeMultimap.create(Ordering.natural(), Ordering.arbitrary());
        }
    }
    return newChildren;
}
 
Example 29
Source Project: usergrid   Source File: OrderedMerge.java    License: Apache License 2.0 5 votes vote down vote up
private SubscriberCoordinator( final Comparator<T> comparator, final Subscriber<? super T> subscriber,
                               final int innerSize ) {
    //we only want to emit events serially
    this.subscriber = new SerializedSubscriber( subscriber );
    this.innerSubscribers = new ArrayList<>( innerSize );
    this.nextValues = TreeMultimap.create( comparator, InnerObserverComparator.INSTANCE );
    this.toProduce = new ArrayDeque<>( innerSize );
}
 
Example 30
public ParseVendorConfigurationAnswerElement() {
  _fileMap = TreeMultimap.create();
  _parseStatus = new TreeMap<>();
  _parseTrees = new TreeMap<>();
  _warnings = new TreeMap<>();
  _errors = new TreeMap<>();
  _errorDetails = new TreeMap<>();
}