List of usage examples for com.google.common.collect Maps filterEntries
@CheckReturnValue public static <K, V> BiMap<K, V> filterEntries(BiMap<K, V> unfiltered, Predicate<? super Entry<K, V>> entryPredicate)
From source file:org.janusgraph.diskstorage.configuration.builder.ReadConfigurationBuilder.java
private Map<ConfigElement.PathIdentifier, Object> getGlobalSubset(Map<ConfigElement.PathIdentifier, Object> m) { return Maps.filterEntries(m, entry -> { assert entry.getKey().element.isOption(); return ((ConfigOption) entry.getKey().element).isGlobal(); });/* w w w . jav a 2s . c o m*/ }
From source file:org.janusgraph.diskstorage.configuration.builder.ReadConfigurationBuilder.java
private Map<ConfigElement.PathIdentifier, Object> getManagedSubset( Map<ConfigElement.PathIdentifier, Object> m) { return Maps.filterEntries(m, entry -> { assert entry.getKey().element.isOption(); return ((ConfigOption) entry.getKey().element).isManaged(); });//from www. ja va2 s .c o m }
From source file:com.google.gerrit.httpd.rpc.project.ProjectAccessFactory.java
private Map<AccountGroup.UUID, GroupInfo> buildGroupInfo(List<AccessSection> local) { Map<AccountGroup.UUID, GroupInfo> infos = new HashMap<>(); for (AccessSection section : local) { for (Permission permission : section.getPermissions()) { for (PermissionRule rule : permission.getRules()) { if (rule.getGroup() != null) { AccountGroup.UUID uuid = rule.getGroup().getUUID(); if (uuid != null && !infos.containsKey(uuid)) { GroupDescription.Basic group = groupBackend.get(uuid); infos.put(uuid, group != null ? new GroupInfo(group) : null); }/*from w ww. ja va2s . co m*/ } } } } return Maps.filterEntries(infos, in -> in.getValue() != null); }
From source file:ezbakehelpers.accumulo.NamespacedTableOperations.java
@Override public Map<String, String> tableIdMap() { return Maps.filterEntries(operations.tableIdMap(), new Predicate<Map.Entry<String, String>>() { @Override//from w w w. j ava 2 s .c o m public boolean apply(Map.Entry<String, String> input) { return input.getKey().startsWith(namespace); } }); }
From source file:com.github.tomakehurst.wiremock.core.WireMockConfiguration.java
@Override @SuppressWarnings("unchecked") public <T extends Extension> Map<String, T> extensionsOfType(final Class<T> extensionType) { return (Map<String, T>) Maps.filterEntries(extensions, valueAssignableFrom(extensionType)); }
From source file:com.android.tools.idea.avdmanager.AvdEditWizard.java
@Override public void performFinishingActions() { Device device = myState.get(DEVICE_DEFINITION_KEY); assert device != null; // Validation should be done by individual steps SystemImageDescription systemImageDescription = myState.get(SYSTEM_IMAGE_KEY); assert systemImageDescription != null; ScreenOrientation orientation = myState.get(DEFAULT_ORIENTATION_KEY); if (orientation == null) { orientation = device.getDefaultState().getOrientation(); }// w w w . ja v a 2 s . c o m Map<String, String> hardwareProperties = DeviceManager.getHardwareProperties(device); Map<String, Object> userEditedProperties = myState.flatten(); // Remove the SD card setting that we're not using String sdCard = null; Boolean useExternalSdCard = myState.get(DISPLAY_USE_EXTERNAL_SD_KEY); boolean useExisting = useExternalSdCard != null && useExternalSdCard; if (!useExisting) { if (Objects.equal(myState.get(SD_CARD_STORAGE_KEY), myState.get(DISPLAY_SD_SIZE_KEY))) { // unchanged, use existing card useExisting = true; } } boolean hasSdCard; if (!useExisting) { userEditedProperties.remove(EXISTING_SD_LOCATION.name); Storage storage = myState.get(DISPLAY_SD_SIZE_KEY); myState.put(SD_CARD_STORAGE_KEY, storage); if (storage != null) { sdCard = toIniString(storage, false); } hasSdCard = storage != null && storage.getSize() > 0; } else { sdCard = myState.get(DISPLAY_SD_LOCATION_KEY); myState.put(EXISTING_SD_LOCATION, sdCard); userEditedProperties.remove(SD_CARD_STORAGE_KEY.name); assert sdCard != null; hasSdCard = true; hardwareProperties.put(HardwareProperties.HW_SDCARD, toIniString(true)); } hardwareProperties.put(HardwareProperties.HW_SDCARD, toIniString(hasSdCard)); // Remove any internal keys from the map userEditedProperties = Maps.filterEntries(userEditedProperties, new Predicate<Map.Entry<String, Object>>() { @Override public boolean apply(Map.Entry<String, Object> input) { return !input.getKey().startsWith(WIZARD_ONLY) && input.getValue() != null; } }); // Call toString() on all remaining values hardwareProperties.putAll( Maps.transformEntries(userEditedProperties, new Maps.EntryTransformer<String, Object, String>() { @Override public String transformEntry(String key, Object value) { if (value instanceof Storage) { if (key.equals(AvdWizardConstants.RAM_STORAGE_KEY.name) || key.equals(AvdWizardConstants.VM_HEAP_STORAGE_KEY.name)) { return toIniString((Storage) value, true); } else { return toIniString((Storage) value, false); } } else if (value instanceof Boolean) { return toIniString((Boolean) value); } else if (value instanceof AvdScaleFactor) { return toIniString((AvdScaleFactor) value); } else if (value instanceof File) { return toIniString((File) value); } else if (value instanceof Double) { return toIniString((Double) value); } else { return value.toString(); } } })); File skinFile = myState.get(CUSTOM_SKIN_FILE_KEY); if (skinFile == null) { skinFile = resolveSkinPath(device.getDefaultHardware().getSkinFile(), systemImageDescription); } File backupSkinFile = myState.get(BACKUP_SKIN_FILE_KEY); if (backupSkinFile != null) { hardwareProperties.put(AvdManager.AVD_INI_BACKUP_SKIN_PATH, backupSkinFile.getPath()); } // Add defaults if they aren't already set differently if (!hardwareProperties.containsKey(AvdManager.AVD_INI_SKIN_DYNAMIC)) { hardwareProperties.put(AvdManager.AVD_INI_SKIN_DYNAMIC, toIniString(true)); } if (!hardwareProperties.containsKey(HardwareProperties.HW_KEYBOARD)) { hardwareProperties.put(HardwareProperties.HW_KEYBOARD, toIniString(false)); } boolean isCircular = device.isScreenRound(); String tempAvdName = myState.get(AvdWizardConstants.AVD_ID_KEY); if (tempAvdName == null || tempAvdName.isEmpty()) { tempAvdName = calculateAvdName(myAvdInfo, hardwareProperties, device, myForceCreate); } final String avdName = tempAvdName; // If we're editing an AVD and we downgrade a system image, wipe the user data with confirmation if (myAvdInfo != null && !myForceCreate) { IAndroidTarget target = myAvdInfo.getTarget(); if (target != null) { int oldApiLevel = target.getVersion().getFeatureLevel(); int newApiLevel = systemImageDescription.getVersion().getFeatureLevel(); final String oldApiName = target.getVersion().getApiString(); final String newApiName = systemImageDescription.getVersion().getApiString(); if (oldApiLevel > newApiLevel || (oldApiLevel == newApiLevel && target.getVersion().isPreview() && !systemImageDescription.getVersion().isPreview())) { final AtomicReference<Boolean> shouldContinue = new AtomicReference<Boolean>(); ApplicationManager.getApplication().invokeAndWait(new Runnable() { @Override public void run() { String message = String.format(Locale.getDefault(), "You are about to downgrade %1$s from API level %2$s to API level %3$s.\n" + "This requires a wipe of the userdata partition of the AVD.\nDo you wish to " + "continue with the data wipe?", avdName, oldApiName, newApiName); int result = Messages.showYesNoDialog((Project) null, message, "Confirm Data Wipe", AllIcons.General.QuestionDialog); shouldContinue.set(result == Messages.YES); } }, ModalityState.any()); if (shouldContinue.get()) { AvdManagerConnection.getDefaultAvdManagerConnection().wipeUserData(myAvdInfo); } else { return; } } } } AvdManagerConnection connection = AvdManagerConnection.getDefaultAvdManagerConnection(); connection.createOrUpdateAvd(myForceCreate ? null : myAvdInfo, avdName, device, systemImageDescription, orientation, isCircular, sdCard, skinFile, hardwareProperties, false); }
From source file:org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorState.java
/** * Applies an {@link AtomixLeaderElectorCommands.GetElectedTopics} commit. * @param commit commit entry/* w w w.ja va 2 s.c o m*/ * @return set of topics for which the node is the leader */ public Set<String> electedTopics(Commit<? extends GetElectedTopics> commit) { try { NodeId nodeId = commit.operation().nodeId(); return ImmutableSet.copyOf(Maps.filterEntries(elections, e -> { Leader leader = leadership(e.getKey()).leader(); return leader != null && leader.nodeId().equals(nodeId); }).keySet()); } catch (Exception e) { log.error("State machine operation failed", e); throw Throwables.propagate(e); } finally { commit.close(); } }
From source file:org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorService.java
/** * Applies an {@link AtomixLeaderElectorOperations.GetElectedTopics} commit. * @param commit commit entry/* w w w . jav a2s . c om*/ * @return set of topics for which the node is the leader */ public Set<String> electedTopics(Commit<? extends GetElectedTopics> commit) { try { NodeId nodeId = commit.value().nodeId(); return ImmutableSet.copyOf(Maps.filterEntries(elections, e -> { Leader leader = leadership(e.getKey()).leader(); return leader != null && leader.nodeId().equals(nodeId); }).keySet()); } catch (Exception e) { logger().error("State machine operation failed", e); throw new IllegalStateException(e); } }
From source file:org.apache.druid.indexing.overlord.hrtr.HttpRemoteTaskRunner.java
private ImmutableWorkerInfo findWorkerToRunTask(Task task) { WorkerBehaviorConfig workerConfig = workerConfigRef.get(); WorkerSelectStrategy strategy;//from w w w . ja v a2 s .co m if (workerConfig == null || workerConfig.getSelectStrategy() == null) { strategy = WorkerBehaviorConfig.DEFAULT_STRATEGY; log.debug("No worker selection strategy set. Using default of [%s]", strategy.getClass().getSimpleName()); } else { strategy = workerConfig.getSelectStrategy(); } return strategy.findWorkerForTask(config, ImmutableMap.copyOf( Maps.transformEntries(Maps.filterEntries(workers, new Predicate<Map.Entry<String, WorkerHolder>>() { @Override public boolean apply(Map.Entry<String, WorkerHolder> input) { return !lazyWorkers.containsKey(input.getKey()) && !workersWithUnacknowledgedTask.containsKey(input.getKey()) && !blackListedWorkers.containsKey(input.getKey()); } }), new Maps.EntryTransformer<String, WorkerHolder, ImmutableWorkerInfo>() { @Override public ImmutableWorkerInfo transformEntry(String key, WorkerHolder value) { return value.toImmutable(); } })), task); }
From source file:org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.AttributesTable.java
private void validateFields(boolean swallowValidationExceptions) throws InvalidValueException { // Some fields may or may not be selected. We have to consider this in the overall validation // therefore we filter out all not selected element. final Map<Object, Field<String>> filteredFieldsToValidate = Maps.filterEntries(aliasFieldsMap, new Predicate<Map.Entry<Object, Field<String>>>() { @Override/*from ww w . j a va 2 s .co m*/ public boolean apply(Map.Entry<Object, Field<String>> input) { return getContainerDataSource().isSelected((T) input.getKey()); } }); UIHelper.validateFields(new ArrayList<Field<?>>(filteredFieldsToValidate.values()), swallowValidationExceptions); }