public static <K, V> Pair<K, V> detect( Map<K, V> map, Predicate2<? super K, ? super V> predicate) { if (map == null) { throw new IllegalArgumentException("Cannot perform a detect on null"); } if (map instanceof ImmutableMap || map instanceof MutableMap) { RichIterable<Pair<K, V>> entries; if (map instanceof ImmutableMap) { entries = ((ImmutableMap<K, V>) map).keyValuesView(); } else { entries = LazyIterate.adapt(map.entrySet()).collect(AbstractImmutableEntry.getPairFunction()); } return entries.detect(each -> predicate.accept(each.getOne(), each.getTwo())); } for (Map.Entry<K, V> entry : map.entrySet()) { if (predicate.accept(entry.getKey(), entry.getValue())) { return Tuples.pairFrom(entry); } } return null; }
public static <K, V> Pair<K, V> detect( Map<K, V> map, Predicate2<? super K, ? super V> predicate) { if (map == null) { throw new IllegalArgumentException("Cannot perform a detect on null"); } if (map instanceof ImmutableMap || map instanceof MutableMap) { RichIterable<Pair<K, V>> entries; if (map instanceof ImmutableMap) { entries = ((ImmutableMap<K, V>) map).keyValuesView(); } else { entries = LazyIterate.adapt(map.entrySet()).collect(AbstractImmutableEntry.getPairFunction()); } return entries.detect(each -> predicate.accept(each.getOne(), each.getTwo())); } for (Map.Entry<K, V> entry : map.entrySet()) { if (predicate.accept(entry.getKey(), entry.getValue())) { return Tuples.pairFrom(entry); } } return null; }
public static <K, V> Pair<K, V> detect( Map<K, V> map, Predicate2<? super K, ? super V> predicate) { if (map == null) { throw new IllegalArgumentException("Cannot perform a detect on null"); } if (map instanceof ImmutableMap || map instanceof MutableMap) { RichIterable<Pair<K, V>> entries; if (map instanceof ImmutableMap) { entries = ((ImmutableMap<K, V>) map).keyValuesView(); } else { entries = LazyIterate.adapt(map.entrySet()).collect(AbstractImmutableEntry.getPairFunction()); } return entries.detect(each -> predicate.accept(each.getOne(), each.getTwo())); } for (Map.Entry<K, V> entry : map.entrySet()) { if (predicate.accept(entry.getKey(), entry.getValue())) { return Tuples.pairFrom(entry); } } return null; }
private ChangeTypeInfo determineChangeType(final String wholeFileString) { RichIterable<ChangeTypeInfo> changeTypeInfos = this.patternMap.keyValuesView().collect( new Function<Pair<ChangeType, Pattern>, ChangeTypeInfo>() { @Override public ChangeTypeInfo valueOf(Pair<ChangeType, Pattern> object) { Pair<Integer, String> contentInfo = getStartIndex(wholeFileString, object.getTwo()); return new ChangeTypeInfo(object.getOne() , contentInfo.getOne() , contentInfo.getTwo() ); } }); ChangeTypeInfo chosenChangeTypeInfo = changeTypeInfos.minBy(ChangeTypeInfo.TO_START_INDEX); if (chosenChangeTypeInfo.getStartIndex() == Integer.MAX_VALUE) { return new ChangeTypeInfo(UnclassifiedChangeType.INSTANCE, Integer.MAX_VALUE, null); } else { return chosenChangeTypeInfo; } }
private ChangeTypeInfo determineChangeType(final String wholeFileString) { RichIterable<ChangeTypeInfo> changeTypeInfos = this.patternMap.keyValuesView().collect( new Function<Pair<ChangeType, Pattern>, ChangeTypeInfo>() { @Override public ChangeTypeInfo valueOf(Pair<ChangeType, Pattern> object) { Pair<Integer, String> contentInfo = getStartIndex(wholeFileString, object.getTwo()); return new ChangeTypeInfo(object.getOne() , contentInfo.getOne() , contentInfo.getTwo() ); } }); ChangeTypeInfo chosenChangeTypeInfo = changeTypeInfos.minBy(ChangeTypeInfo.TO_START_INDEX); if (chosenChangeTypeInfo.getStartIndex() == Integer.MAX_VALUE) { return new ChangeTypeInfo(UnclassifiedChangeType.INSTANCE, Integer.MAX_VALUE, null); } else { return chosenChangeTypeInfo; } }
public void mergeAttributes(TextMarkupDocumentSection other) { if (other == null) { return; } this.attrs = this.attrs.toMap() .withAllKeyValues(other.attrs.select(new Predicate2<String, String>() { @Override public boolean accept(String key, String value) { return !TextMarkupDocumentSection.this.attrs.contains(key); } }).keyValuesView()) .toImmutable(); this.toggles = this.toggles.newWithAll(other.toggles.select(new Predicate<String>() { @Override public boolean accept(String key) { return !TextMarkupDocumentSection.this.toggles.contains(key); } })); }
public void mergeAttributes(TextMarkupDocumentSection other) { if (other == null) { return; } this.attrs = this.attrs.toMap() .withAllKeyValues(other.attrs.select(new Predicate2<String, String>() { @Override public boolean accept(String key, String value) { return !TextMarkupDocumentSection.this.attrs.contains(key); } }).keyValuesView()) .toImmutable(); this.toggles = this.toggles.newWithAll(other.toggles.select(new Predicate<String>() { @Override public boolean accept(String key) { return !TextMarkupDocumentSection.this.toggles.contains(key); } })); }