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:me.lucko.luckperms.common.commands.impl.misc.SearchCommand.java
private static Map.Entry<Component, String> searchGroupResultToMessage(List<HeldPermission<String>> results, String label, int pageNumber) { if (results.isEmpty()) { return Maps.immutableEntry(TextComponent.builder("None").color(TextColor.DARK_AQUA).build(), null); }//from w ww .j a va2 s .co m List<HeldPermission<String>> sorted = new ArrayList<>(results); sorted.sort(Comparator.comparing(HeldPermission::getHolder)); int index = pageNumber - 1; List<List<HeldPermission<String>>> pages = CommandUtils.divideList(sorted, 15); if (index < 0 || index >= pages.size()) { pageNumber = 1; index = 0; } List<HeldPermission<String>> page = pages.get(index); TextComponent.Builder message = TextComponent.builder(""); String title = "&7(page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + sorted.size() + "&7 entries)"; for (HeldPermission<String> ent : page) { String s = "&3> &b" + ent.getHolder() + " &7- " + (ent.getValue() ? "&a" : "&c") + ent.getValue() + getNodeExpiryString(ent.asNode()) + CommandUtils.getAppendableNodeContextString(ent.asNode()) + "\n"; message.append(TextUtils.fromLegacy(s, Constants.FORMAT_CHAR).toBuilder() .applyDeep(makeFancy(ent.getHolder(), true, label, ent)).build()); } return Maps.immutableEntry(message.build(), title); }
From source file:cosmos.sql.impl.LogicVisitor.java
protected Iterable<MultimapRecord> apply(OrOperator andOp) { Iterable<MultimapRecord> iter = Collections.emptyList(); Iterable<ChildVisitor> children = Iterables.filter(andOp.getChildren(), new FilterFilter()); Iterator<ChildVisitor> childIter = children.iterator(); while (childIter.hasNext()) { FieldEquality equality = (FieldEquality) childIter.next(); iter = Iterables.concat(iter, apply(equality)); }// ww w . ja v a 2 s .c om Store meatadata = new Store(sortRes.connector(), sortRes.auths(), sortRes.columnsToIndex()); try { cosmosRef.register(meatadata); cosmosRef.addResults(meatadata, iter); iter = Collections.emptyList(); HashFunction hf = Hashing.md5(); HashCode hc = hf.newHasher().putObject(andOp, andOp).hash(); tempTableCache.put(hc.toString(), Maps.immutableEntry(cosmosRef, meatadata)); return cosmosRef.fetch(meatadata); } catch (Exception e) { log.error("Could not fetch results", e); } return iter; }
From source file:me.lucko.luckperms.common.commands.impl.group.GroupListMembers.java
private static Map.Entry<Component, String> searchGroupResultToMessage(List<HeldPermission<String>> results, String label, int pageNumber) { if (results.isEmpty()) { return Maps.immutableEntry(TextComponent.builder("None").color(TextColor.DARK_AQUA).build(), null); }/*from www . j av a 2 s. co m*/ List<HeldPermission<String>> sorted = new ArrayList<>(results); sorted.sort(Comparator.comparing(HeldPermission::getHolder)); int index = pageNumber - 1; List<List<HeldPermission<String>>> pages = CommandUtils.divideList(sorted, 15); if (index < 0 || index >= pages.size()) { pageNumber = 1; index = 0; } List<HeldPermission<String>> page = pages.get(index); TextComponent.Builder message = TextComponent.builder(""); String title = "&7(page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + sorted.size() + "&7 entries)"; for (HeldPermission<String> ent : page) { String s = "&3> &b" + ent.getHolder() + " " + getNodeExpiryString(ent.asNode()) + CommandUtils.getAppendableNodeContextString(ent.asNode()) + "\n"; message.append(TextUtils.fromLegacy(s, Constants.FORMAT_CHAR).toBuilder() .applyDeep(makeFancy(ent.getHolder(), true, label, ent)).build()); } return Maps.immutableEntry(message.build(), title); }
From source file:org.onosproject.store.primitives.impl.DefaultDatabaseState.java
@Override public Set<Entry<String, Versioned<byte[]>>> mapEntrySet(String mapName) { return ImmutableSet.copyOf(getMap(mapName).entrySet().stream() .map(entry -> Maps.immutableEntry(entry.getKey(), entry.getValue())).collect(Collectors.toSet())); }
From source file:org.spongepowered.api.service.permission.MemorySubjectData.java
@Override public boolean addParent(Set<Context> contexts, Subject parent) { contexts = ImmutableSet.copyOf(contexts); while (true) { Map.Entry<String, String> newEnt = Maps.immutableEntry(parent.getContainingCollection().getIdentifier(), parent.getIdentifier()); List<Map.Entry<String, String>> oldParents = this.parents.get(contexts); List<Map.Entry<String, String>> newParents = ImmutableList.<Map.Entry<String, String>>builder() .addAll(oldParents == null ? Collections.<Map.Entry<String, String>>emptyList() : oldParents) .add(newEnt).build();//from w w w .j a va 2 s . c om if (oldParents != null && oldParents.contains(newEnt)) { return false; } if (updateCollection(this.parents, contexts, oldParents, newParents)) { return true; } } }
From source file:org.apache.hoya.yarn.appmaster.web.view.ContainerStatsBlock.java
@Override protected void render(Block html) { // TODO Probably better to just get a copy of this list for us to avoid the repeated synchronization? // does this change if we have 50 node, 100node, 500 node hoya clusters? final Map<String, RoleInstance> containerInstances = getContainerInstances( hoya.getAppState().cloneActiveContainerList()); for (Entry<String, RoleStatus> entry : hoya.getRoleStatusByName().entrySet()) { final String name = entry.getKey(); final RoleStatus roleStatus = entry.getValue(); DIV<Hamlet> div = html.div("role-info ui-widget-content ui-corner-all"); List<ClusterNode> nodesInRole; try {/*from www. j av a 2 s . c om*/ nodesInRole = clusterOps.listClusterNodesInRole(name); } catch (Exception e) { log.error("Could not fetch containers for role: " + name, e); nodesInRole = Collections.emptyList(); } div.h2(BOLD, StringUtils.capitalize(name)); // Generate the details on this role Iterable<Entry<String, Integer>> stats = roleStatus.buildStatistics().entrySet(); generateRoleDetails(div, "role-stats-wrap", "Specifications", Iterables.transform(stats, stringIntPairFunc)); // Sort the ClusterNodes by their name (containerid) Collections.sort(nodesInRole, new ClusterNodeNameComparator()); // Generate the containers running this role generateRoleDetails(div, "role-stats-containers", "Containers", Iterables.transform(nodesInRole, new Function<ClusterNode, Entry<TableContent, String>>() { @Override public Entry<TableContent, String> apply(ClusterNode input) { final String containerId = input.name; if (containerInstances.containsKey(containerId)) { RoleInstance roleInst = containerInstances.get(containerId); if (roleInst.container.getNodeHttpAddress() != null) { return Maps.<TableContent, String>immutableEntry( new TableAnchorContent(containerId, buildNodeUrlForContainer( roleInst.container.getNodeHttpAddress(), containerId)), null); } } return Maps.immutableEntry(new TableContent(input.name), null); } })); ClusterDescription desc = hoya.getAppState().getClusterStatus(); Map<String, String> options = desc.getRole(name); Iterable<Entry<TableContent, String>> tableContent; // Generate the pairs of data in the expected form if (null != options) { tableContent = Iterables.transform(options.entrySet(), stringStringPairFunc); } else { // Or catch that we have no options and provide "empty" tableContent = Collections.<Entry<TableContent, String>>emptySet(); } // Generate the options used by this role generateRoleDetails(div, "role-options-wrap", "Role Options", tableContent); // Close the div for this role div._(); } }
From source file:io.prestosql.Session.java
public Session(QueryId queryId, Optional<TransactionId> transactionId, boolean clientTransactionSupport, Identity identity, Optional<String> source, Optional<String> catalog, Optional<String> schema, SqlPath path, Optional<String> traceToken, TimeZoneKey timeZoneKey, Locale locale, Optional<String> remoteUserAddress, Optional<String> userAgent, Optional<String> clientInfo, Set<String> clientTags, Set<String> clientCapabilities, ResourceEstimates resourceEstimates, long startTime, Map<String, String> systemProperties, Map<ConnectorId, Map<String, String>> connectorProperties, Map<String, Map<String, String>> unprocessedCatalogProperties, SessionPropertyManager sessionPropertyManager, Map<String, String> preparedStatements) { this.queryId = requireNonNull(queryId, "queryId is null"); this.transactionId = requireNonNull(transactionId, "transactionId is null"); this.clientTransactionSupport = clientTransactionSupport; this.identity = requireNonNull(identity, "identity is null"); this.source = requireNonNull(source, "source is null"); this.catalog = requireNonNull(catalog, "catalog is null"); this.schema = requireNonNull(schema, "schema is null"); this.path = requireNonNull(path, "path is null"); this.traceToken = requireNonNull(traceToken, "traceToken is null"); this.timeZoneKey = requireNonNull(timeZoneKey, "timeZoneKey is null"); this.locale = requireNonNull(locale, "locale is null"); this.remoteUserAddress = requireNonNull(remoteUserAddress, "remoteUserAddress is null"); this.userAgent = requireNonNull(userAgent, "userAgent is null"); this.clientInfo = requireNonNull(clientInfo, "clientInfo is null"); this.clientTags = ImmutableSet.copyOf(requireNonNull(clientTags, "clientTags is null")); this.clientCapabilities = ImmutableSet .copyOf(requireNonNull(clientCapabilities, "clientCapabilities is null")); this.resourceEstimates = requireNonNull(resourceEstimates, "resourceEstimates is null"); this.startTime = startTime; this.systemProperties = ImmutableMap.copyOf(requireNonNull(systemProperties, "systemProperties is null")); this.sessionPropertyManager = requireNonNull(sessionPropertyManager, "sessionPropertyManager is null"); this.preparedStatements = requireNonNull(preparedStatements, "preparedStatements is null"); ImmutableMap.Builder<ConnectorId, Map<String, String>> catalogPropertiesBuilder = ImmutableMap.builder(); connectorProperties.entrySet().stream() .map(entry -> Maps.immutableEntry(entry.getKey(), ImmutableMap.copyOf(entry.getValue()))) .forEach(catalogPropertiesBuilder::put); this.connectorProperties = catalogPropertiesBuilder.build(); ImmutableMap.Builder<String, Map<String, String>> unprocessedCatalogPropertiesBuilder = ImmutableMap .builder();/* w w w.ja v a2s . c om*/ unprocessedCatalogProperties.entrySet().stream() .map(entry -> Maps.immutableEntry(entry.getKey(), ImmutableMap.copyOf(entry.getValue()))) .forEach(unprocessedCatalogPropertiesBuilder::put); this.unprocessedCatalogProperties = unprocessedCatalogPropertiesBuilder.build(); checkArgument(!transactionId.isPresent() || unprocessedCatalogProperties.isEmpty(), "Catalog session properties cannot be set if there is an open transaction"); checkArgument(catalog.isPresent() || !schema.isPresent(), "schema is set but catalog is not"); }
From source file:org.apache.slider.server.appmaster.web.view.ContainerStatsBlock.java
@Override protected void render(Block html) { // TODO Probably better to just get a copy of this list for us to avoid the repeated synchronization? // does this change if we have 50 node, 100node, 500 node clusters? final Map<String, RoleInstance> containerInstances = getContainerInstances( slider.getAppState().cloneOwnedContainerList()); for (Entry<String, RoleStatus> entry : slider.getRoleStatusByName().entrySet()) { final String name = entry.getKey(); final RoleStatus roleStatus = entry.getValue(); DIV<Hamlet> div = html.div("role-info ui-widget-content ui-corner-all"); List<ClusterNode> nodesInRole; try {//from ww w. j av a 2 s. c o m nodesInRole = clusterOps.listClusterNodesInRole(name); } catch (Exception e) { log.error("Could not fetch containers for role: " + name, e); nodesInRole = Collections.emptyList(); } div.h2(BOLD, StringUtils.capitalize(name)); // Generate the details on this role Iterable<Entry<String, Integer>> stats = roleStatus.buildStatistics().entrySet(); generateRoleDetails(div, "role-stats-wrap", "Specifications", Iterables.transform(stats, stringIntPairFunc)); // Sort the ClusterNodes by their name (containerid) Collections.sort(nodesInRole, new ClusterNodeNameComparator()); // Generate the containers running this role generateRoleDetails(div, "role-stats-containers", "Containers", Iterables.transform(nodesInRole, new Function<ClusterNode, Entry<TableContent, String>>() { @Override public Entry<TableContent, String> apply(ClusterNode input) { final String containerId = input.name; if (containerInstances.containsKey(containerId)) { RoleInstance roleInst = containerInstances.get(containerId); if (roleInst.container.getNodeHttpAddress() != null) { return Maps.<TableContent, String>immutableEntry( new TableAnchorContent(containerId, buildNodeUrlForContainer( roleInst.container.getNodeHttpAddress(), containerId)), null); } } return Maps.immutableEntry(new TableContent(input.name), null); } })); ClusterDescription desc = slider.getAppState().getClusterStatus(); Map<String, String> options = desc.getRole(name); Iterable<Entry<TableContent, String>> tableContent; // Generate the pairs of data in the expected form if (null != options) { tableContent = Iterables.transform(options.entrySet(), stringStringPairFunc); } else { // Or catch that we have no options and provide "empty" tableContent = Collections.<Entry<TableContent, String>>emptySet(); } // Generate the options used by this role generateRoleDetails(div, "role-options-wrap", "Role Options", tableContent); // Close the div for this role div._(); } }
From source file:com.infinities.keystone4j.AbstractAction.java
private Entry<Boolean, List<T>> limit(List<T> refs, Hints hints) { boolean NOT_LIMITED = false; boolean LIMITED = true; if (hints == null || hints.getLimit() == null) { return Maps.immutableEntry(NOT_LIMITED, refs); }/* w w w . ja v a 2s .c om*/ if (hints.getLimit().isTruncated()) { return Maps.immutableEntry(LIMITED, refs); } if (refs.size() > hints.getLimit().getLimit()) { return Maps.immutableEntry(LIMITED, refs.subList(0, hints.getLimit().getLimit())); } return Maps.immutableEntry(NOT_LIMITED, refs); }
From source file:org.apache.calcite.util.CompatibleGuava11.java
private static <K, V> Iterator<Map.Entry<K, V>> asSetEntryIterator(Set<K> set, final Function<? super K, V> function) { return new TransformedIterator<K, Map.Entry<K, V>>(set.iterator()) { @Override/*w w w .ja v a 2 s. com*/ Map.Entry<K, V> transform(K key) { return Maps.immutableEntry(key, function.apply(key)); } }; }