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.AbstractDataStore.java
@Override public final CompletableFuture<ImmutableSubjectData> setData(String type, String identifier, ImmutableSubjectData data) {// w w w . j a v a 2 s.c o m Objects.requireNonNull(type, "type"); Objects.requireNonNull(identifier, "identifier"); final Map.Entry<String, String> lookupKey = Maps.immutableEntry(type, identifier); return setDataInternal(type, identifier, data).thenApply(newData -> { if (newData != null) { listeners.call(lookupKey, newData); } return newData; }); }
From source file:io.atomix.core.map.impl.TranscodingAsyncAtomicMap.java
public TranscodingAsyncAtomicMap(AsyncAtomicMap<K2, V2> backingMap, Function<K1, K2> keyEncoder, Function<K2, K1> keyDecoder, Function<V1, V2> valueEncoder, Function<V2, V1> valueDecoder) { super(backingMap); this.backingMap = backingMap; this.keyEncoder = k -> k == null ? null : keyEncoder.apply(k); this.keyDecoder = k -> k == null ? null : keyDecoder.apply(k); this.valueEncoder = v -> v == null ? null : valueEncoder.apply(v); this.valueDecoder = v -> v == null ? null : valueDecoder.apply(v); this.versionedValueDecoder = v -> v == null ? null : v.map(valueDecoder); this.versionedValueEncoder = v -> v == null ? null : v.map(valueEncoder); this.entryDecoder = e -> e == null ? null : Maps.immutableEntry(keyDecoder.apply(e.getKey()), versionedValueDecoder.apply(e.getValue())); this.entryEncoder = e -> e == null ? null : Maps.immutableEntry(keyEncoder.apply(e.getKey()), versionedValueEncoder.apply(e.getValue())); }
From source file:com.facebook.swift.codec.internal.reflection.ReflectionThriftUnionCodec.java
@Override public T read(TProtocol protocol) throws Exception { TProtocolReader reader = new TProtocolReader(protocol); reader.readStructBegin();//from w ww . j a v a2 s .c o m Map.Entry<Short, Object> data = null; Short fieldId = null; while (reader.nextField()) { checkState(fieldId == null, "Received Union with more than one value (seen id %s, now id %s)", fieldId, reader.getFieldId()); fieldId = reader.getFieldId(); // do we have a codec for this field ThriftCodec<?> codec = fields.get(fieldId); if (codec == null) { reader.skipFieldData(); } else { // is this field readable ThriftFieldMetadata field = metadata.getField(fieldId); if (field.isWriteOnly() || field.getType() != THRIFT_FIELD) { reader.skipFieldData(); continue; } // read the value Object value = reader.readField(codec); if (value == null) { continue; } data = Maps.immutableEntry(fieldId, value); } } reader.readStructEnd(); // build the struct return constructStruct(data); }
From source file:org.onosproject.store.primitives.impl.TranscodingAsyncConsistentTreeMap.java
@Override public CompletableFuture<Map.Entry<String, Versioned<V1>>> lowerEntry(String key) { return backingMap.lowerEntry(key).thenApply( entry -> Maps.immutableEntry(entry.getKey(), versionedValueTransform.apply(entry.getValue()))); }
From source file:ninja.leaping.permissionsex.subject.InheritanceSubjectDataBaker.java
@Override public BakedSubjectData bake(CalculatedSubject data, Set<Entry<String, String>> activeContexts) throws ExecutionException { final Map.Entry<String, String> subject = data.getIdentifier(); final BakeState state = new BakeState(data, processContexts(data.getManager(), activeContexts)); final Set<Map.Entry<String, String>> visitedSubjects = new HashSet<>(); visitSubject(state, subject, visitedSubjects, 0); Entry<String, String> defIdentifier = data.data().getCache().getDefaultIdentifier(); if (!subject.equals(defIdentifier)) { visitSubject(state, defIdentifier, visitedSubjects, 1); visitSubject(state,/*from w w w .ja va 2s . co m*/ Maps.immutableEntry(PermissionsEx.SUBJECTS_DEFAULTS, PermissionsEx.SUBJECTS_DEFAULTS), visitedSubjects, 2); // Force in global defaults } return new BakedSubjectData(NodeTree.of(state.combinedPermissions, state.defaultValue), ImmutableList.copyOf(state.parents), ImmutableMap.copyOf(state.options)); }
From source file:ninja.leaping.permissionsex.extrabackends.groupmanager.GroupManagerDataStore.java
@Override protected void initializeInternal() throws PermissionsLoadingException { final Path rootFile = Paths.get(groupManagerRoot); if (!Files.isDirectory(rootFile)) { throw new PermissionsLoadingException(t("GroupManager directory %s does not exist", rootFile)); // TODO: Actual translations }//from w ww .j a v a2 s . co m try { config = getLoader(rootFile.resolve("config.yml")).load(); globalGroups = getLoader(rootFile.resolve("globalgroups.yml")).load(); worldUserGroups = new HashMap<>(); Files.list(rootFile.resolve("worlds")).filter(Files::isDirectory).forEach(world -> { try { worldUserGroups.put(world.getFileName().toString(), Maps.immutableEntry(getLoader(world.resolve("users.yml")).load(), getLoader(world.resolve("groups.yml")).load())); } catch (IOException e) { throw new RuntimeException(e); // TODO } }); contextInheritance = new GroupManagerContextInheritance(config.getNode("settings", "mirrors")); } catch (IOException e) { throw new PermissionsLoadingException(e); } }
From source file:me.lucko.luckperms.common.commands.generic.other.HolderShowTracks.java
@Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) { if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), holder)) { Message.COMMAND_NO_PERMISSION.send(sender); return CommandResult.NO_PERMISSION; }//from w w w. java 2 s.c om try { plugin.getStorage().loadAllTracks().get(); } catch (Exception e) { e.printStackTrace(); Message.TRACKS_LOAD_ERROR.send(sender); return CommandResult.LOADING_ERROR; } List<Map.Entry<Track, String>> lines = new ArrayList<>(); if (holder.getType().isUser()) { // if the holder is a user, we want to query parent groups for tracks Set<Node> nodes = holder.enduringData().immutable().values().stream().filter(Node::isGroupNode) .filter(Node::getValue).filter(Node::isPermanent).collect(Collectors.toSet()); for (Node node : nodes) { String groupName = node.getGroupName(); List<Track> tracks = plugin.getTrackManager().getAll().values().stream() .filter(t -> t.containsGroup(groupName)).collect(Collectors.toList()); for (Track t : tracks) { lines.add(Maps.immutableEntry(t, MessageUtils.getAppendableNodeContextString(plugin.getLocaleManager(), node) + "\n" + MessageUtils.listToArrowSep(t.getGroups(), groupName))); } } } else { // otherwise, just lookup for the actual group String groupName = ((Group) holder).getName(); List<Track> tracks = plugin.getTrackManager().getAll().values().stream() .filter(t -> t.containsGroup(groupName)).collect(Collectors.toList()); for (Track t : tracks) { lines.add(Maps.immutableEntry(t, MessageUtils.listToArrowSep(t.getGroups(), groupName))); } } if (lines.isEmpty()) { Message.LIST_TRACKS_EMPTY.send(sender, holder.getFriendlyName()); return CommandResult.SUCCESS; } Message.LIST_TRACKS.send(sender, holder.getFriendlyName()); for (Map.Entry<Track, String> line : lines) { Message.LIST_TRACKS_ENTRY.send(sender, line.getKey().getName(), line.getValue()); } return CommandResult.SUCCESS; }
From source file:org.trancecode.concurrent.ParallelIterators.java
/** * @see Iterators#filter(Iterable, Predicate) *///from www . j ava 2 s.com public static <T> Iterator<T> filter(final Iterator<T> unfiltered, final Predicate<? super T> predicate, final ExecutorService executor) { final Function<? super T, Entry<T, Boolean>> evaluateFunction = (Function<T, Entry<T, Boolean>>) element -> Maps .immutableEntry(element, predicate.apply(element)); final Iterator<Entry<T, Boolean>> unfilteredWithPredicateEvaluated = transform(unfiltered, evaluateFunction, executor); final Function<Entry<T, Boolean>, Boolean> getValueFunction = MapFunctions.getValue(); final Iterator<Entry<T, Boolean>> filtered = Iterators.filter(unfilteredWithPredicateEvaluated, TcPredicates.asPredicate(getValueFunction)); final Function<Entry<T, Boolean>, T> getKeyFunction = MapFunctions.getKey(); return Iterators.transform(filtered, getKeyFunction); }
From source file:com.palantir.atlasdb.keyvalue.api.RowResult.java
public Iterable<Map.Entry<Cell, T>> getCells() { return Iterables.transform(columns.entrySet(), new Function<Map.Entry<byte[], T>, Map.Entry<Cell, T>>() { @Override/* w ww . j av a2s.c om*/ public Entry<Cell, T> apply(Entry<byte[], T> from) { return Maps.immutableEntry(Cell.create(row, from.getKey()), from.getValue()); } }); }
From source file:de.cosmocode.collections.event.EventMap.java
@Override public V remove(Object object) { final boolean contained = containsKey(object); final V value = super.remove(object); if (contained) { @SuppressWarnings("unchecked") final K key = (K) object; listener.removed(Maps.immutableEntry(key, value)); }/*from www. j a v a 2 s.com*/ return value; }