List of usage examples for com.google.common.base Functions forMap
public static <K, V> Function<K, V> forMap(Map<K, V> map)
From source file:com.facebook.buck.util.FakeListeningProcessExecutor.java
public FakeListeningProcessExecutor(Multimap<ProcessExecutorParams, FakeListeningProcessState> processStates, SettableFakeClock clock) { this(Functions.forMap(processStates.asMap()), clock); }
From source file:net.derquinse.common.collect.RegularImmutableIndexedHierarchy.java
/** * Constructor./* w ww .j ava 2 s .c o m*/ * @param map Backing map. * @param keys Keys hierarchy. */ RegularImmutableIndexedHierarchy(ImmutableBiMap<K, V> map, ImmutableHierarchy<K> keys) { check(map, keys); this.map = map; ImmutableHierarchy.Builder<V> builder = ImmutableHierarchy.builder(true); for (K key : keys) { final K parentKey = keys.getParent(key); final V parentValue = parentKey != null ? map.get(parentKey) : null; builder.add(parentValue, map.get(key)); } this.values = ImmutableHierarchy.<V>builder().addHierarchy(null, keys, null, false, Functions.forMap(map)) .get(); this.keys = keys; }
From source file:com.github.jonross.seq4j.SeqMisc.java
/** * Wraps {@link Functions#forMap(Map)}; returns a function that looks up its * argument in a map.//from w w w.jav a 2s.c o m */ public static <K, V> Function<K, V> lookup(Map<K, V> map) { return Functions.forMap(map); }
From source file:org.eclipse.viatra.dse.util.ValueComparableEObjectStringMap.java
private ValueComparableEObjectStringMap(Map<EObject, String> innerMap) { super(Ordering.natural().onResultOf(Functions.forMap(innerMap)).compound(new EObjectComparator())); this.innerMap = innerMap; }
From source file:de.cubeisland.engine.core.util.matcher.StringMatcher.java
/** * Returns all matches with their editDistance, having an editDistance <= maxDistance * * @param search the String to search for * @param in the Strings to match in/* ww w. j a v a2 s . c om*/ * @param maxDistance the maximum editDistance * @param ignoreCase * @return a map of all matches sorted by their editDistance */ public TreeMap<String, Integer> getMatches(String search, Collection<String> in, int maxDistance, boolean ignoreCase) { if (maxDistance < 1) { CubeEngine.getLog().warn(new Throwable(), "Checking EditDistance lower than 1!"); return new TreeMap<>(); } Map<String, Integer> matches = new HashMap<>(); Ordering<String> comparator = Ordering.natural().onResultOf(Functions.forMap(matches)) .compound(Ordering.natural()); for (String target : in) { int distance = target.length() - search.length(); if (distance > maxDistance || -distance > maxDistance) // too long/short to match { continue; } if (ignoreCase) { distance = this.editDistance.executeIgnoreCase(search, target); } else { distance = this.editDistance.execute(search, target); } if (distance <= maxDistance) { matches.put(target, distance); } } TreeMap<String, Integer> result = new TreeMap<>(comparator); result.putAll(matches); return result; }
From source file:de.tuberlin.uebb.jdae.hlmsl.specials.ConstantLinear.java
@Override public GlobalEquation bind(Map<Unknown, GlobalVariable> ctxt) { return new LinearGlobalEquation(timeCoefficient, constant, coefficients, Lists.transform(variables, Functions.forMap(ctxt))); }
From source file:org.apache.ctakes.relationextractor.ae.IdentifiedAnnotationExpander.java
public static List<Integer> expandToNP(JCas jCas, IdentifiedAnnotation identifiedAnnotation) { // preserve the original begin and end of the annotation List<Integer> originalSpan = Lists.newArrayList(identifiedAnnotation.getBegin(), identifiedAnnotation.getEnd()); // map each covering treebank node to its character length Map<TreebankNode, Integer> treebankNodeSizes = new HashMap<TreebankNode, Integer>(); for (TreebankNode treebankNode : JCasUtil.selectCovering(jCas, TreebankNode.class, identifiedAnnotation.getBegin(), identifiedAnnotation.getEnd())) { // only expand nouns (and not verbs or adjectives) if (treebankNode instanceof TerminalTreebankNode) { if (!treebankNode.getNodeType().startsWith("N")) { return originalSpan; }/* ww w . jav a2s .c om*/ } // because only nouns are expanded, look for covering NPs if (treebankNode.getNodeType().equals("NP")) { treebankNodeSizes.put(treebankNode, treebankNode.getCoveredText().length()); } } // find the shortest covering treebank node List<TreebankNode> sortedTreebankNodes = new ArrayList<TreebankNode>(treebankNodeSizes.keySet()); Function<TreebankNode, Integer> getValue = Functions.forMap(treebankNodeSizes); Collections.sort(sortedTreebankNodes, Ordering.natural().onResultOf(getValue)); if (sortedTreebankNodes.size() > 0) { identifiedAnnotation.setBegin(sortedTreebankNodes.get(0).getBegin()); identifiedAnnotation.setEnd(sortedTreebankNodes.get(0).getEnd()); } return originalSpan; }
From source file:es.usc.citius.composit.core.matcher.MatchTable.java
public SortedSet<E> getSortedSourceElemsThatMatch(E targetElement) { // Get the map with matcher -> type Map<E, T> sourceElements = matchTable.column(targetElement); // Order elements by the match type values Ordering<E> matchTypeComparator = Ordering.natural().onResultOf(Functions.forMap(sourceElements)); return ImmutableSortedMap.copyOf(sourceElements, matchTypeComparator).keySet(); }
From source file:dagger.internal.codegen.SimpleAnnotationMirror.java
private SimpleAnnotationMirror(TypeElement annotationType, Map<String, ? extends AnnotationValue> namedValues) { checkArgument(annotationType.getKind().equals(ElementKind.ANNOTATION_TYPE), "annotationType must be an annotation: %s", annotationType); checkArgument(FluentIterable.from(methodsIn(annotationType.getEnclosedElements())) .transform(element -> element.getSimpleName().toString()).toSet().equals(namedValues.keySet()), "namedValues must have values for exactly the members in %s: %s", annotationType, namedValues); this.annotationType = annotationType; this.namedValues = ImmutableMap.copyOf(namedValues); this.elementValues = Maps.toMap(methodsIn(annotationType.getEnclosedElements()), Functions.compose(Functions.forMap(namedValues), element -> element.getSimpleName().toString())); }
From source file:org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestConfiguration.java
void setProducts(Map<String, Product> products) { Function<Product, String> getName = new Function<Product, String>() { public String apply(Product item) { return item.getName(); }//w w w . j a va 2 s . c o m }; Function<String, String> comparatorFunction = Functions.compose(getName, Functions.forMap(products)); Ordering<String> comparator = Ordering.natural().onResultOf(comparatorFunction); this.products = ImmutableSortedMap.copyOf(products, comparator); }