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:org.apache.slider.server.appmaster.web.view.ContainerStatsBlock.java
protected static <T> Function<Entry<String, T>, Entry<TableContent, T>> toTableContentFunction() { return new Function<Entry<String, T>, Entry<TableContent, T>>() { @Override//from www .j a v a2 s. c o m public Entry<TableContent, T> apply(Entry<String, T> input) { return Maps.immutableEntry(new TableContent(input.getKey()), input.getValue()); } }; }
From source file:com.facebook.presto.server.ResourceUtil.java
private static void parseSessionHeader(String header, Multimap<String, Entry<String, String>> sessionPropertiesByCatalog, SessionPropertyManager sessionPropertyManager) { List<String> nameValue = Splitter.on('=').limit(2).trimResults().splitToList(header); assertRequest(nameValue.size() == 2, "Invalid %s header", PRESTO_SESSION); String fullPropertyName = nameValue.get(0); String catalog;/*from ww w . ja v a 2 s. c o m*/ String name; List<String> nameParts = Splitter.on('.').splitToList(fullPropertyName); if (nameParts.size() == 1) { catalog = null; name = nameParts.get(0); } else if (nameParts.size() == 2) { catalog = nameParts.get(0); name = nameParts.get(1); } else { throw badRequest(format("Invalid %s header", PRESTO_SESSION)); } assertRequest(catalog == null || !catalog.isEmpty(), "Invalid %s header", PRESTO_SESSION); assertRequest(!name.isEmpty(), "Invalid %s header", PRESTO_SESSION); String value = nameValue.get(1); // validate session property value PropertyMetadata<?> metadata = sessionPropertyManager.getSessionPropertyMetadata(fullPropertyName); try { sessionPropertyManager.decodeProperty(fullPropertyName, value, metadata.getJavaType()); } catch (RuntimeException e) { throw badRequest(format("Invalid %s header", PRESTO_SESSION)); } sessionPropertiesByCatalog.put(catalog, Maps.immutableEntry(name, value)); }
From source file:io.atlassian.fugue.extras.ImmutableMaps.java
/** * Returns an immutable map that applies the keyTransformer and * valueTransformer functions to each entry of {@code fromMap}. If for any * entry, a <code>null</code> key or value is returned, that entry is * discarded in the result. If the keyTransformer function returns the same * key for multiple entries, {@link java.lang.IllegalArgumentException} will * be thrown.//from w w w .j ava 2s . c om * * @param <K1> the input key type * @param <K2> the output key type * @param <V1> the input value type * @param <V2> the output value type * @param from the map we use as the source * @param keyTransformer transform keys * @param valueTransformer transform values * @return the transformed map */ public static <K1, K2, V1, V2> ImmutableMap<K2, V2> transform(Map<K1, V1> from, final Function<? super K1, ? extends K2> keyTransformer, final Function<? super V1, ? extends V2> valueTransformer) { return toMap(com.google.common.collect.Iterables.transform(from.entrySet(), entry -> Maps .immutableEntry(keyTransformer.apply(entry.getKey()), valueTransformer.apply(entry.getValue())))); }
From source file:com.appenginefan.toolkit.persistence.EntityBasedPersistence.java
public List<Entry<String, Entity>> scan(String start, String end, int max, SortDirection direction, boolean keysOnly) { Preconditions.checkNotNull(start);/* www . ja va 2 s .c o m*/ Preconditions.checkNotNull(end); Preconditions.checkArgument(max > -1); if (max == 0) { return Lists.newArrayList(); } Query query = new Query(kind); query.addFilter("__key__", FilterOperator.GREATER_THAN_OR_EQUAL, KeyFactory.createKey(kind, escape(start))); query.addFilter("__key__", FilterOperator.LESS_THAN, KeyFactory.createKey(kind, escape(end))); query.addSort("__key__", direction); if (keysOnly) { query.setKeysOnly(); } PreparedQuery preparedQuery = service.prepare(query); List<Entry<String, Entity>> result = Lists.newArrayList(); for (Entity entity : preparedQuery.asIterable(FetchOptions.Builder.withLimit(max))) { if (keysOnly) { result.add(Maps.immutableEntry(unescape(entity.getKey().getName()), (Entity) null)); } else { result.add(Maps.immutableEntry(unescape(entity.getKey().getName()), entity)); } } return result; }
From source file:ome.services.blitz.repo.ManagedRepositoryI.java
/** * Split a template path into the root- and user-owned segments * @param templatePath a template path/*w w w. j av a 2s.c om*/ * @return the root- and user-owned segments * @throws ApiUsageException if there are no user-owned components */ private static Map.Entry<FsFile, FsFile> splitPath(String templatePath) throws omero.ApiUsageException { int splitPoint = templatePath.lastIndexOf("//"); if (splitPoint < 0) { splitPoint = 0; } final FsFile rootPath = new FsFile(templatePath.substring(0, splitPoint)); final FsFile userPath = new FsFile(templatePath.substring(splitPoint)); if (FsFile.emptyPath.equals(userPath)) { throw new omero.ApiUsageException(null, null, "no user-owned directories in managed repository template path"); } return Maps.immutableEntry(rootPath, userPath); }
From source file:tech.beshu.ror.settings.RorSettings.java
@SuppressWarnings("unchecked") public RorSettings(RawSettings raw_global) { final RawSettings raw = raw_global.opt(ATTRIBUTE_NAME).isPresent() ? raw_global.inner(ATTRIBUTE_NAME) : raw_global;/*from w w w . ja v a 2 s . c o m*/ LdapSettingsCollection ldapSettingsCollection = LdapSettingsCollection.from(raw); UserGroupsProviderSettingsCollection userGroupsProviderSettingsCollection = UserGroupsProviderSettingsCollection .from(raw); ProxyAuthDefinitionSettingsCollection proxyAuthDefinitionSettingsCollection = ProxyAuthDefinitionSettingsCollection .from(raw); ExternalAuthenticationServiceSettingsCollection externalAuthenticationServiceSettingsCollection = ExternalAuthenticationServiceSettingsCollection .from(raw); JwtAuthDefinitionSettingsCollection jwtAuthDefinitionSettingsCollection = JwtAuthDefinitionSettingsCollection .from(raw); RorKbnAuthDefinitionSettingsCollection rorKbnAuthDefinitionSettingsCollection = RorKbnAuthDefinitionSettingsCollection .from(raw); AuthMethodCreatorsRegistry authMethodCreatorsRegistry = new AuthMethodCreatorsRegistry( proxyAuthDefinitionSettingsCollection, ldapSettingsCollection, jwtAuthDefinitionSettingsCollection, rorKbnAuthDefinitionSettingsCollection); this.forbiddenMessage = raw.stringOpt(ATTRIBUTE_FORBIDDEN_RESPONSE).orElse(DEFAULT_FORBIDDEN_MESSAGE); this.blocksSettings = raw.notEmptyListOpt(BlockSettings.ATTRIBUTE_NAME).orElse(DEFAULT_BLOCK_SETTINGS) .stream() .map(block -> BlockSettings.from(new RawSettings((Map<String, ?>) block, raw.getLogger()), authMethodCreatorsRegistry, ldapSettingsCollection, userGroupsProviderSettingsCollection, externalAuthenticationServiceSettingsCollection, UserSettingsCollection.from(raw, authMethodCreatorsRegistry))) .collect(Collectors.toList()); List<String> blockNames = this.blocksSettings.stream().map(BlockSettings::getName) .collect(Collectors.toList()); blockNames.forEach(name -> { if (Collections.frequency(blockNames, name) > 1) { throw new SettingsMalformedException( "__old_ACL __old_Block names should be unique! Found more than one __old_ACL block with the same name: " + name); } }); // This is useful for LDAP AUTHZ multitenancy available groups list this.ldapConnector2allowedGroups = new HashMap<>(); for (BlockSettings bs : blocksSettings) { Optional<Map.Entry<String, Set<String>>> ldapAuthorizationAsyncRuleO = bs.getRules().stream().map(r -> { if (r instanceof LdapAuthorizationAsyncRule) { LdapAuthorizationRuleSettings s = (LdapAuthorizationRuleSettings) r; return Maps.immutableEntry(s.getLdapSettings().getName(), s.getGroups()); } else if (r instanceof LdapAuthRuleSettings) { LdapAuthRuleSettings s = (LdapAuthRuleSettings) r; return Maps.immutableEntry(s.getLdapSettings().getName(), s.getGroups()); } else { return null; } }).filter(Objects::nonNull).findFirst(); ldapAuthorizationAsyncRuleO.ifPresent(entry -> { String ldapConnectorName = entry.getKey(); Set<String> groupsForThisLdapConnector = ldapConnector2allowedGroups.getOrDefault(ldapConnectorName, Sets.newHashSet()); groupsForThisLdapConnector.addAll(entry.getValue()); ldapConnector2allowedGroups.put(ldapConnectorName, groupsForThisLdapConnector); }); } ldapConnector2allowedGroups.keySet().stream().forEach(connectorName -> ldapSettingsCollection .get(connectorName).setAvailableGroups(ldapConnector2allowedGroups.get(connectorName))); this.enable = raw.booleanOpt(ATTRIBUTE_ENABLE).orElse(!blocksSettings.isEmpty()); this.promptForBasicAuth = raw.booleanOpt(PROMPT_FOR_BASIC_AUTH).orElse(true); this.verbosity = raw.stringOpt(VERBOSITY) .map(value -> Verbosity.fromString(value).<SettingsMalformedException>orElseThrow( () -> new SettingsMalformedException("Unknown verbosity value: " + value))) .orElse(DEFAULT_VERBOSITY); this.auditCollector = raw.booleanOpt(AUDIT_COLLECTOR).orElse(false); // SSL Optional<RawSettings> sslSettingsOpt = raw.innerOpt(PREFIX_SSL.replaceFirst(".$", "")); Optional sslEnableOpt = raw.booleanOpt(PREFIX_SSL + "enable"); Optional<String> ksOpt = raw.stringOpt(PREFIX_SSL + ATTRIBUTE_SSL_KEYSTORE_FILE); if (!sslSettingsOpt.isPresent() || (sslEnableOpt.isPresent() && sslEnableOpt.get().equals(false)) || !ksOpt.isPresent()) { this.sslEnabled = false; } else { this.sslEnabled = true; } if (sslEnabled) { this.keystoreFile = raw.stringReq(PREFIX_SSL + ATTRIBUTE_SSL_KEYSTORE_FILE); this.keyAlias = raw.stringOpt(PREFIX_SSL + ATTRIBUTE_SSL_KEY_ALIAS); this.keyPass = raw.stringOpt(PREFIX_SSL + ATTRIBUTE_SSL_KEY_PASS); this.keystorePass = raw.stringOpt(PREFIX_SSL + ATTRIBUTE_SSL_KEYSTORE_PASS); } }
From source file:ninja.leaping.permissionsex.extrabackends.groupmanager.GroupManagerSubjectData.java
@Override public Set<Set<Map.Entry<String, String>>> getActiveContexts() { ImmutableSet.Builder<Set<Map.Entry<String, String>>> activeContextsBuilder = ImmutableSet.builder(); if (getNodeForContexts(PermissionsEx.GLOBAL_CONTEXT) != null) { activeContextsBuilder.add(PermissionsEx.GLOBAL_CONTEXT); }/* w w w .j av a 2s. c om*/ for (String world : this.dataStore.getKnownWorlds()) { final Set<Map.Entry<String, String>> worldContext = ImmutableSet .of(Maps.immutableEntry("world", world)); if (getNodeForContexts(worldContext) != null) { activeContextsBuilder.add(worldContext); } } return activeContextsBuilder.build(); }
From source file:com.facebook.presto.metadata.DatabaseShardManager.java
@Override public Multimap<Long, Entry<Long, String>> getCommittedPartitionShardNodes(TableHandle tableHandle) { checkNotNull(tableHandle, "tableHandle is null"); checkState(tableHandle instanceof NativeTableHandle, "tableHandle not a native table"); final long tableId = ((NativeTableHandle) tableHandle).getTableId(); ImmutableMultimap.Builder<Long, Entry<Long, String>> map = ImmutableMultimap.builder(); List<ShardNode> shardNodes = dao.getCommittedShardNodesByTableId(tableId); for (ShardNode shardNode : shardNodes) { map.put(shardNode.getPartitionId(), Maps.immutableEntry(shardNode.getShardId(), shardNode.getNodeIdentifier())); }// w w w. j a v a2 s . co m return map.build(); }
From source file:me.lucko.luckperms.common.node.NodeFactory.java
public static Map.Entry<String, String> parseMetaNode(String s) { if (!s.startsWith("meta.")) { return null; }//from w w w . j av a 2 s. com Iterator<String> metaParts = META_SPLITTER.split(s.substring("meta.".length())).iterator(); if (!metaParts.hasNext()) return null; String key = metaParts.next(); if (!metaParts.hasNext()) return null; String value = metaParts.next(); return Maps.immutableEntry(LegacyNodeFactory.unescapeCharacters(key).intern(), LegacyNodeFactory.unescapeCharacters(value).intern()); }
From source file:co.cask.cdap.data.stream.StreamDataFileIndex.java
private Map.Entry<LongList, LongList> loadIndex(InputStream input) throws IOException { byte[] magic = new byte[INDEX_MAGIC_HEADER.length]; ByteStreams.readFully(input, magic); if (!Arrays.equals(magic, INDEX_MAGIC_HEADER)) { throw new IOException("Unsupported index file format. Expected magic bytes as 'I' '1'"); }/*from w w w . j a v a2 s. c o m*/ // Decode the properties map. In current version, it is not used. StreamUtils.decodeMap(new BinaryDecoder(input)); // Read in all index (timestamp, position pairs). LongList timestamps = new LongArrayList(1000); LongList positions = new LongArrayList(1000); byte[] buf = new byte[Longs.BYTES * 2]; while (ByteStreams.read(input, buf, 0, buf.length) == buf.length) { timestamps.add(Bytes.toLong(buf, 0)); positions.add(Bytes.toLong(buf, Longs.BYTES)); } return Maps.immutableEntry(timestamps, positions); }