List of usage examples for com.google.common.collect Maps filterKeys
@CheckReturnValue public static <K, V> BiMap<K, V> filterKeys(BiMap<K, V> unfiltered, final Predicate<? super K> keyPredicate)
From source file:io.druid.storage.s3.S3DataSegmentMover.java
@Override public DataSegment move(DataSegment segment, Map<String, Object> targetLoadSpec) throws SegmentLoadingException { try {// ww w. j a va 2 s.c o m Map<String, Object> loadSpec = segment.getLoadSpec(); String s3Bucket = MapUtils.getString(loadSpec, "bucket"); String s3Path = MapUtils.getString(loadSpec, "key"); String s3DescriptorPath = S3Utils.descriptorPathForSegmentPath(s3Path); final String targetS3Bucket = MapUtils.getString(targetLoadSpec, "bucket"); final String targetS3BaseKey = MapUtils.getString(targetLoadSpec, "baseKey"); final String targetS3Path = S3Utils.constructSegmentPath(targetS3BaseKey, segment); String targetS3DescriptorPath = S3Utils.descriptorPathForSegmentPath(targetS3Path); if (targetS3Bucket.isEmpty()) { throw new SegmentLoadingException("Target S3 bucket is not specified"); } if (targetS3Path.isEmpty()) { throw new SegmentLoadingException("Target S3 baseKey is not specified"); } safeMove(s3Bucket, s3Path, targetS3Bucket, targetS3Path); safeMove(s3Bucket, s3DescriptorPath, targetS3Bucket, targetS3DescriptorPath); return segment.withLoadSpec(ImmutableMap.<String, Object>builder() .putAll(Maps.filterKeys(loadSpec, new Predicate<String>() { @Override public boolean apply(String input) { return !(input.equals("bucket") || input.equals("key")); } })).put("bucket", targetS3Bucket).put("key", targetS3Path).build()); } catch (ServiceException e) { throw new SegmentLoadingException(e, "Unable to move segment[%s]: [%s]", segment.getIdentifier(), e); } }
From source file:org.jclouds.internal.FilterStringsBoundToInjectorByName.java
@Override public Map<String, String> apply(Predicate<String> filter) { List<Binding<String>> stringBindings = injector.findBindingsByType(TypeLiteral.get(String.class)); Iterable<Binding<String>> annotatedWithName = Iterables.filter(stringBindings, new Predicate<Binding<String>>() { @Override/*from ww w .ja v a 2 s .co m*/ public boolean apply(Binding<String> input) { Annotation annotation = input.getKey().getAnnotation(); if (annotation == null) return false; return (annotation instanceof javax.inject.Named) || (annotation instanceof com.google.inject.name.Named); } }); Map<String, Binding<String>> bindingsByName = Maps.uniqueIndex(annotatedWithName, new Function<Binding<String>, String>() { @Override public String apply(Binding<String> input) { Annotation annotation = input.getKey().getAnnotation(); return (annotation instanceof javax.inject.Named) ? javax.inject.Named.class.cast(annotation).value() : com.google.inject.name.Named.class.cast(annotation).value(); } }); Map<String, Binding<String>> filteredBindingsByName = Maps.filterKeys(bindingsByName, filter); Map<String, String> stringBoundByName = Maps.transformValues(filteredBindingsByName, new Function<Binding<String>, String>() { @Override public String apply(Binding<String> input) { return input.getProvider().get(); } }); return stringBoundByName; }
From source file:org.jfrog.build.extractor.BuildInfoExtractorUtils.java
public static Properties filterDynamicProperties(Properties source, Predicate<Object> filter) { Properties properties = new Properties(); if (source != null) { properties.putAll(Maps.filterKeys(source, filter)); }/*from w w w . j a v a 2s . co m*/ return properties; }
From source file:dagger.internal.codegen.BindingGraphPlugins.java
private void initializePlugin(BindingGraphPlugin plugin) { plugin.initFiler(filer);/*from w w w . j a v a 2s.com*/ plugin.initTypes(types); plugin.initElements(elements); Set<String> supportedOptions = plugin.supportedOptions(); if (!supportedOptions.isEmpty()) { plugin.initOptions(Maps.filterKeys(processingOptions, supportedOptions::contains)); } }
From source file:org.locationtech.geogig.model.internal.CachingDAGStorageProvider.java
@Override public void save(Map<TreeId, DAG> dags) { Map<TreeId, DAG> cached = Maps.filterKeys(dags, heapTrees); heap().save(cached);//from ww w . j ava 2s .c o m if (cached.size() < dags.size()) { disk().save(Maps.filterKeys(dags, diskTrees)); } }
From source file:org.richfaces.ui.iteration.list.AbstractList.java
private Iterator<UIComponent> getFacetsIterator(Predicate<? super String> namePredicate) { if (getFacetCount() > 0) { return Maps.filterKeys(getFacets(), namePredicate).values().iterator(); }/*from w ww. j ava2s. c o m*/ return Iterators.emptyIterator(); }
From source file:ru.codeinside.gses.activiti.behavior.TaskFields.java
public void verify() { Collection<FieldDeclaration> declarations = Maps.filterKeys(fields, not(in(validNames))).values(); if (!declarations.isEmpty()) { throw new IllegalArgumentException("?? ? {" + Joiner.on(" | ").join(transform(declarations, new Names())) + "}"); }//from ww w .j av a 2 s . c om }
From source file:eu.lp0.cursus.scoring.scores.impl.GenericRaceLapsData.java
@Override protected List<Pilot> calculateRaceLapsInOrder(Race race, Map<Pilot, Integer> laps) { ListMultimap<Integer, Pilot> raceOrder = ArrayListMultimap.create(EXPECTED_MAXIMUM_LAPS, scores.getPilots().size());// w w w.j a va 2s. c o m extractRaceLaps(race, laps, raceOrder, null); // Get penalties for each pilot ListMultimap<Pilot, Penalty> cancelLaps = ArrayListMultimap.create(EXPECTED_MAXIMUM_PENALTIES, scores.getPilots().size()); ListMultimap<Pilot, Penalty> adjustLaps = ArrayListMultimap.create(EXPECTED_MAXIMUM_PENALTIES, scores.getPilots().size()); for (RaceAttendee attendee : Maps.filterKeys(race.getAttendees(), Predicates.in(scores.getPilots())) .values()) { for (Penalty penalty : Iterables.concat(Ordering.natural().immutableSortedCopy(attendee.getPenalties()), scores.getSimulatedRacePenalties(attendee.getPilot(), race))) { if (penalty.getValue() != 0) { switch (penalty.getType()) { case CANCEL_LAPS: cancelLaps.put(attendee.getPilot(), penalty); break; case ADJUST_LAPS: adjustLaps.put(attendee.getPilot(), penalty); break; default: break; } } } } // Apply lap cancellation penalties if (!cancelLaps.isEmpty()) { final Multiset<Pilot> pilotLaps = HashMultiset.create(laps.size()); for (Map.Entry<Pilot, Integer> pilotLapCount : laps.entrySet()) { pilotLaps.setCount(pilotLapCount.getKey(), pilotLapCount.getValue()); } for (Map.Entry<Pilot, Penalty> entry : cancelLaps.entries()) { int value = entry.getValue().getValue(); if (value > 0) { pilotLaps.remove(entry.getKey(), value); } else { pilotLaps.add(entry.getKey(), Math.abs(value)); } } extractRaceLaps(race, laps, raceOrder, new Predicate<Pilot>() { @Override public boolean apply(@Nullable Pilot pilot) { return pilotLaps.remove(pilot); } }); } // Save pilot order List<Pilot> origPilotOrder = getPilotOrder(raceOrder); SortedSet<Pilot> noLaps = new TreeSet<Pilot>(new PilotRaceNumberComparator()); Set<Integer> changed = new HashSet<Integer>(); // It is intentional that pilots can end up having 0 laps but be considered to have completed the race for (Map.Entry<Pilot, Penalty> entry : adjustLaps.entries()) { Pilot pilot = entry.getKey(); int lapCount = laps.get(pilot); raceOrder.remove(lapCount, pilot); changed.add(lapCount); lapCount += entry.getValue().getValue(); if (lapCount <= 0) { lapCount = 0; noLaps.add(pilot); } laps.put(pilot, lapCount); raceOrder.put(lapCount, pilot); changed.add(lapCount); } // Apply original pilot order if (!changed.isEmpty()) { origPilotOrder.addAll(noLaps); for (Integer lapCount : changed) { raceOrder.replaceValues(lapCount, Ordering.explicit(origPilotOrder).immutableSortedCopy(raceOrder.get(lapCount))); } return getPilotOrder(raceOrder); } else { return origPilotOrder; } }
From source file:com.facebook.presto.tests.tpch.TpchIndexMetadata.java
@Override public Optional<ConnectorResolvedIndex> resolveIndex(ConnectorSession session, ConnectorTableHandle tableHandle, Set<ColumnHandle> indexableColumns, Set<ColumnHandle> outputColumns, TupleDomain<ColumnHandle> tupleDomain) { TpchTableHandle tpchTableHandle = (TpchTableHandle) tableHandle; // Keep the fixed values that don't overlap with the indexableColumns // Note: technically we could more efficiently utilize the overlapped columns, but this way is simpler for now Map<ColumnHandle, NullableValue> fixedValues = TupleDomain.extractFixedValues(tupleDomain) .orElse(ImmutableMap.of()).entrySet().stream() .filter(entry -> !indexableColumns.contains(entry.getKey())) .filter(entry -> !entry.getValue().isNull()) // strip nulls since meaningless in index join lookups .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); // determine all columns available for index lookup Set<String> lookupColumnNames = ImmutableSet.<String>builder() .addAll(handleToNames(ImmutableList.copyOf(indexableColumns))) .addAll(handleToNames(ImmutableList.copyOf(fixedValues.keySet()))).build(); // do we have an index? if (!indexedData.getIndexedTable(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames).isPresent()) { return Optional.empty(); }/*from www. j a v a2 s . co m*/ TupleDomain<ColumnHandle> filteredTupleDomain = tupleDomain; if (!tupleDomain.isNone()) { filteredTupleDomain = TupleDomain.withColumnDomains( Maps.filterKeys(tupleDomain.getDomains().get(), not(in(fixedValues.keySet())))); } TpchIndexHandle indexHandle = new TpchIndexHandle(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames, TupleDomain.fromFixedValues(fixedValues)); return Optional.of(new ConnectorResolvedIndex(indexHandle, filteredTupleDomain)); }
From source file:com.uber.tchannel.tracing.PrefixedHeadersCarrier.java
Map<String, String> getNonTracingHeaders() { return Maps.filterKeys(headers, new Predicate<String>() { @Override//from www . j a v a 2s.c o m public boolean apply(String key) { return !key.startsWith(prefix); } }); }