List of usage examples for com.google.common.collect Maps immutableEntry
@GwtCompatible(serializable = true) public static <K, V> Entry<K, V> immutableEntry(@Nullable K key, @Nullable V value)
From source file:ninja.leaping.permissionsex.backend.file.SchemaMigrations.java
static ConfigurationTransformation twoTo3() { final Map<String, List<Map.Entry<String, Integer>>> convertedRanks = new HashMap<>(); return ConfigurationTransformation .chain(tBuilder().addAction(new Object[] { WILDCARD_OBJECT }, (nodePath, configurationNode) -> { if (configurationNode.hasMapChildren()) { String lastPath = nodePath.get(0).toString(); if (lastPath.endsWith("s")) { lastPath = lastPath.substring(0, lastPath.length() - 1); }//from www . jav a 2s . c om return new Object[] { "subjects", lastPath }; } else { return null; } }).build(), tBuilder().addAction(new Object[] { "subjects", "group", WILDCARD_OBJECT }, (nodePath, configurationNode) -> { for (ConfigurationNode child : configurationNode.getChildrenList()) { if (child.getNode(FileSubjectData.KEY_CONTEXTS).isVirtual() || child.getNode(FileSubjectData.KEY_CONTEXTS).getChildrenMap().isEmpty()) { ConfigurationNode optionsNode = child.getNode("options"); if (optionsNode.isVirtual()) { return null; } ConfigurationNode rank = optionsNode.getNode("rank"); if (!rank.isVirtual()) { final String rankLadder = optionsNode.getNode("rank-ladder") .getString("default"); List<Map.Entry<String, Integer>> tempVals = convertedRanks .get(rankLadder.toLowerCase()); if (tempVals == null) { tempVals = new ArrayList<>(); convertedRanks.put(rankLadder.toLowerCase(), tempVals); } tempVals.add(Maps.immutableEntry(configurationNode.getKey().toString(), rank.getInt())); rank.setValue(null); optionsNode.getNode("rank-ladder").setValue(null); if (optionsNode.getChildrenMap().isEmpty()) { optionsNode.setValue(null); } } } } return null; }).build(), tBuilder().addAction(new Object[0], (nodePath, configurationNode) -> { for (Map.Entry<String, List<Map.Entry<String, Integer>>> ent : convertedRanks .entrySet()) { Collections.sort(ent.getValue(), (a, b) -> b.getValue().compareTo(a.getValue())); ConfigurationNode ladderNode = configurationNode .getNode(FileDataStore.KEY_RANK_LADDERS, ent.getKey()); for (Map.Entry<String, Integer> grp : ent.getValue()) { ladderNode.getAppendedNode().setValue("group:" + grp.getKey()); } } return null; }).build()); }
From source file:org.apache.accumulo.cluster.standalone.StandaloneClusterControl.java
protected Entry<Integer, String> exec(String hostname, String[] command) throws IOException { RemoteShell shell = new RemoteShell(hostname, command, options); try {// w w w. j a v a 2s . c o m shell.execute(); } catch (ExitCodeException e) { // capture the stdout of the process as well. String output = shell.getOutput(); // add output for the ExitCodeException. ExitCodeException ece = new ExitCodeException(e.getExitCode(), "stderr: " + e.getMessage() + ", stdout: " + output); log.error("Failed to run command", ece); return Maps.immutableEntry(e.getExitCode(), output); } return Maps.immutableEntry(shell.getExitCode(), shell.getOutput()); }
From source file:co.cask.tigon.sql.io.GDATEncoder.java
@Override public Encoder writeString(String s) throws IOException { // String data to be inserted at location -> buffer.size() byte[] stringBytes = s.getBytes(Charsets.UTF_8); stringPayloadSize += stringBytes.length; stringOffsetLocations.add(Maps.immutableEntry(buffer.size(), stringBytes)); return this; }
From source file:me.lucko.luckperms.common.commands.impl.misc.SearchCommand.java
private static Map.Entry<Component, String> searchUserResultToMessage(List<HeldPermission<UUID>> results, Function<UUID, String> uuidLookup, String label, int pageNumber) { if (results.isEmpty()) { return Maps.immutableEntry(TextComponent.builder("None").color(TextColor.DARK_AQUA).build(), null); }//from ww w. ja v a2s . c o m List<HeldPermission<UUID>> sorted = new ArrayList<>(results); sorted.sort(Comparator.comparing(HeldPermission::getHolder)); int index = pageNumber - 1; List<List<HeldPermission<UUID>>> pages = CommandUtils.divideList(sorted, 15); if (index < 0 || index >= pages.size()) { pageNumber = 1; index = 0; } List<HeldPermission<UUID>> page = pages.get(index); List<Map.Entry<String, HeldPermission<UUID>>> uuidMappedPage = page.stream() .map(hp -> Maps.immutableEntry(uuidLookup.apply(hp.getHolder()), hp)).collect(Collectors.toList()); TextComponent.Builder message = TextComponent.builder(""); String title = "&7(page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + sorted.size() + "&7 entries)"; for (Map.Entry<String, HeldPermission<UUID>> ent : uuidMappedPage) { String s = "&3> &b" + ent.getKey() + " &7- " + (ent.getValue().getValue() ? "&a" : "&c") + ent.getValue().getValue() + getNodeExpiryString(ent.getValue().asNode()) + CommandUtils.getAppendableNodeContextString(ent.getValue().asNode()) + "\n"; message.append(TextUtils.fromLegacy(s, Constants.FORMAT_CHAR).toBuilder() .applyDeep(makeFancy(ent.getKey(), false, label, ent.getValue())).build()); } return Maps.immutableEntry(message.build(), title); }
From source file:google.registry.tools.UpdateTldCommand.java
@Override Optional<Map.Entry<DateTime, TldState>> getTldStateTransitionToAdd() { return setCurrentTldState != null ? Optional.of(Maps.immutableEntry(DateTime.now(DateTimeZone.UTC), setCurrentTldState)) : Optional.<Map.Entry<DateTime, TldState>>absent(); }
From source file:be.nbb.demetra.dotstat.DotStatProvider.java
private static Optional<Map.Entry<String, String>> getNodeDimension(DataSet dataSet) { String[] dimColumns = DbBean.getDimArray(dataSet.getDataSource()); int length = dimColumns.length; while (length > 0 && dataSet.get(dimColumns[length - 1]) == null) { length--;//w w w . j a va2s . co m } String[] dimValues = new String[length]; for (int i = 0; i < length; i++) { dimValues[i] = dataSet.get(dimColumns[i]); } return length > 0 ? Optional.<Map.Entry<String, String>>of( Maps.immutableEntry(dimColumns[length - 1], dimValues[length - 1])) : Optional.<Map.Entry<String, String>>absent(); }
From source file:ninja.leaping.permissionsex.backend.AbstractDataStore.java
/** * Apply default data when creating a new file. * * This consists of/* w w w . ja va 2 s. c om*/ * <ul> * <li>Modifying default data to give all permissions to a user connecting locally</li> * </ul> */ protected final void applyDefaultData() { setData(PermissionsEx.SUBJECTS_DEFAULTS, PermissionsEx.SUBJECTS_DEFAULTS, getData(PermissionsEx.SUBJECTS_DEFAULTS, PermissionsEx.SUBJECTS_DEFAULTS, null) .setDefaultValue(ImmutableSet.of(Maps.immutableEntry("srcip", "127.0.0.1")), 1)); }
From source file:me.lucko.luckperms.common.commands.impl.group.GroupListMembers.java
private static Map.Entry<Component, String> searchUserResultToMessage(List<HeldPermission<UUID>> results, Function<UUID, String> uuidLookup, String label, int pageNumber) { if (results.isEmpty()) { return Maps.immutableEntry(TextComponent.builder("None").color(TextColor.DARK_AQUA).build(), null); }/*from ww w .j a v a 2 s. c om*/ List<HeldPermission<UUID>> sorted = new ArrayList<>(results); sorted.sort(Comparator.comparing(HeldPermission::getHolder)); int index = pageNumber - 1; List<List<HeldPermission<UUID>>> pages = CommandUtils.divideList(sorted, 15); if (index < 0 || index >= pages.size()) { pageNumber = 1; index = 0; } List<HeldPermission<UUID>> page = pages.get(index); List<Map.Entry<String, HeldPermission<UUID>>> uuidMappedPage = page.stream() .map(hp -> Maps.immutableEntry(uuidLookup.apply(hp.getHolder()), hp)).collect(Collectors.toList()); TextComponent.Builder message = TextComponent.builder(""); String title = "&7(page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + sorted.size() + "&7 entries)"; for (Map.Entry<String, HeldPermission<UUID>> ent : uuidMappedPage) { String s = "&3> &b" + ent.getKey() + " " + getNodeExpiryString(ent.getValue().asNode()) + CommandUtils.getAppendableNodeContextString(ent.getValue().asNode()) + "\n"; message.append(TextUtils.fromLegacy(s, Constants.FORMAT_CHAR).toBuilder() .applyDeep(makeFancy(ent.getKey(), false, label, ent.getValue())).build()); } return Maps.immutableEntry(message.build(), title); }
From source file:org.onosproject.store.primitives.impl.TranscodingAsyncConsistentTreeMap.java
@Override public CompletableFuture<Map.Entry<String, Versioned<V1>>> pollFirstEntry() { return backingMap.pollFirstEntry().thenApply( entry -> Maps.immutableEntry(entry.getKey(), versionedValueTransform.apply(entry.getValue()))); }
From source file:org.onosproject.persistence.impl.PersistentMap.java
@Override public Set<Entry<K, V>> entrySet() { Set<Entry<K, V>> entries = Sets.newHashSet(); items.entrySet().forEach(e -> entries .add(Maps.immutableEntry(serializer.decode(e.getKey()), serializer.decode(e.getValue())))); return entries; }