Example usage for com.google.common.collect Maps immutableEntry

List of usage examples for com.google.common.collect Maps immutableEntry

Introduction

In this page you can find the example usage for com.google.common.collect Maps immutableEntry.

Prototype

@GwtCompatible(serializable = true)
public static <K, V> Entry<K, V> immutableEntry(@Nullable K key, @Nullable V value) 

Source Link

Document

Returns an immutable map entry with the specified key and value.

Usage

From source file:org.calrissian.accumulorecipes.commons.iterators.FirstNEntriesInRowIterator.java

private void prepKeys() throws IOException {
    if (lastRowFound == null) {
        topKey = null;//w  ww  . j  a v  a 2 s  . c  o  m
        topValue = null;
        return;
    }

    keysValues.clear();

    while (getSource().hasTop() && keysValues.size() < n
            && getSource().getTopKey().getRow().equals(lastRowFound)) {
        keysValues.add(
                Maps.immutableEntry(new Key(getSource().getTopKey()), new Value(getSource().getTopValue())));
        getSource().next();
    }

    topKey = new Key(lastRowFound, keysValues.iterator().next().getKey().getColumnFamily());
    topValue = encodeRow(keysValues);
}

From source file:org.opendaylight.controller.config.yang.store.impl.MbeParser.java

public YangStoreSnapshotImpl parseYangFiles(Collection<? extends InputStream> allInput)
        throws YangStoreException {
    YangParserImpl parser = new YangParserImpl();

    List<InputStream> bufferedInputStreams = new ArrayList<>();
    for (InputStream is : allInput) {
        String content;/*from w w w .  ja v  a 2 s . c o m*/
        try {
            content = IOUtils.toString(is);
        } catch (IOException e) {
            throw new YangStoreException("Can not get yang as String from " + is, e);
        }
        InputStream buf = new ByteArrayInputStream(content.getBytes());
        bufferedInputStreams.add(buf);
    }

    Map<InputStream, Module> allYangModules = parser.parseYangModelsFromStreamsMapped(bufferedInputStreams);

    SchemaContext resolveSchemaContext = parser.resolveSchemaContext(Sets.newHashSet(allYangModules.values()));

    // JMX generator

    Map<String, String> namespaceToPackageMapping = Maps.newHashMap();
    PackageTranslator packageTranslator = new PackageTranslator(namespaceToPackageMapping);

    Map<QName, ServiceInterfaceEntry> qNamesToSIEs = new HashMap<>();

    // create SIE structure qNamesToSIEs
    for (Module module : resolveSchemaContext.getModules()) {
        String packageName = packageTranslator.getPackageName(module);
        Map<QName, ServiceInterfaceEntry> namesToSIEntries = ServiceInterfaceEntry.create(module, packageName);

        for (Entry<QName, ServiceInterfaceEntry> sieEntry : namesToSIEntries.entrySet()) {

            // merge value into qNamesToSIEs
            if (qNamesToSIEs.containsKey(sieEntry.getKey()) == false) {
                qNamesToSIEs.put(sieEntry.getKey(), sieEntry.getValue());
            } else {
                throw new IllegalStateException("Cannot add two SIE with same qname " + sieEntry.getValue());
            }
        }
    }

    Map<String, Map<String, ModuleMXBeanEntry>> retVal = Maps.newHashMap();
    Map<String, Entry<Module, String>> modulesMap = new HashMap<>();

    for (Entry<InputStream, Module> moduleEntry : allYangModules.entrySet()) {
        String packageName = packageTranslator.getPackageName(moduleEntry.getValue());
        TypeProviderWrapper typeProviderWrapper = new TypeProviderWrapper(
                new TypeProviderImpl(resolveSchemaContext));
        String yangAsString;
        try {
            moduleEntry.getKey().reset();
            yangAsString = IOUtils.toString(moduleEntry.getKey());
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
        modulesMap.put(moduleEntry.getValue().getName(),
                Maps.immutableEntry(moduleEntry.getValue(), yangAsString));
        Map<String /* MB identity local name */, ModuleMXBeanEntry> namesToMBEs = ModuleMXBeanEntry.create(
                moduleEntry.getValue(), qNamesToSIEs, resolveSchemaContext, typeProviderWrapper, packageName);
        retVal.put(moduleEntry.getValue().getNamespace().toString(), namesToMBEs);
    }

    return new YangStoreSnapshotImpl(retVal, modulesMap);
}

From source file:org.onosproject.store.primitives.impl.CatalystSerializers.java

public static Serializer getSerializer() {
    Serializer serializer = new Serializer();
    TypeSerializerFactory factory = new DefaultCatalystTypeSerializerFactory(
            org.onosproject.store.service.Serializer.using(Arrays.asList((KryoNamespaces.API)),
                    MapEntryUpdateResult.class, MapEntryUpdateResult.Status.class, Transaction.State.class,
                    PrepareResult.class, CommitResult.class, DocumentPath.class, DocumentTreeUpdateResult.class,
                    DocumentTreeUpdateResult.Status.class, DocumentTreeEvent.class,
                    DocumentTreeEvent.Type.class, RollbackResult.class));
    // ONOS classes
    serializer.register(Change.class, factory);
    serializer.register(Leader.class, factory);
    serializer.register(Leadership.class, factory);
    serializer.register(NodeId.class, factory);
    serializer.register(Match.class, factory);
    serializer.register(MapEntryUpdateResult.class, factory);
    serializer.register(MapEntryUpdateResult.Status.class, factory);
    serializer.register(Transaction.State.class, factory);
    serializer.register(PrepareResult.class, factory);
    serializer.register(CommitResult.class, factory);
    serializer.register(RollbackResult.class, factory);
    serializer.register(TransactionId.class, factory);
    serializer.register(MapUpdate.class, factory);
    serializer.register(MapUpdate.Type.class, factory);
    serializer.register(MapTransaction.class, factory);
    serializer.register(Versioned.class, factory);
    serializer.register(MapEvent.class, factory);
    serializer.register(Task.class, factory);
    serializer.register(WorkQueueStats.class, factory);
    serializer.register(DocumentPath.class, factory);
    serializer.register(DocumentTreeUpdateResult.class, factory);
    serializer.register(DocumentTreeUpdateResult.Status.class, factory);
    serializer.register(DocumentTreeEvent.class, factory);
    serializer.register(Maps.immutableEntry("a", "b").getClass(), factory);
    serializer.register(ImmutableList.of().getClass(), factory);
    serializer.register(ImmutableList.of("a").getClass(), factory);
    serializer.register(Arrays.asList().getClass(), factory);
    serializer.register(Optional.class, factory);

    serializer.resolve(new LongCommands.TypeResolver());
    serializer.resolve(new AtomixConsistentMapCommands.TypeResolver());
    serializer.resolve(new AtomixLeaderElectorCommands.TypeResolver());
    serializer.resolve(new AtomixWorkQueueCommands.TypeResolver());
    serializer.resolve(new AtomixDocumentTreeCommands.TypeResolver());
    serializer.resolve(new ResourceManagerTypeResolver());
    serializer.resolve(new AtomixConsistentTreeMapCommands.TypeResolver());
    serializer.resolve(new AtomixConsistentMultimapCommands.TypeResolver());

    serializer.registerClassLoader(AtomixConsistentMapFactory.class)
            .registerClassLoader(AtomixLeaderElectorFactory.class)
            .registerClassLoader(AtomixWorkQueueFactory.class)
            .registerClassLoader(AtomixDocumentTreeFactory.class)
            .registerClassLoader(AtomixConsistentTreeMapFactory.class)
            .registerClassLoader(AtomixConsistentSetMultimapFactory.class);

    return serializer;
}

From source file:com.infinities.nova.policy.Rules.java

private static List<Entry<String, BaseCheck>> parseTokenize(String orig) {
    String[] tokens = orig.split("\\s+");

    List<Entry<String, BaseCheck>> entrys = Lists.newArrayList();

    for (String token : tokens) {
        token = token.trim();/*from   w  ww. j a  va2 s  . c  om*/
        if (Strings.isNullOrEmpty(token)) {
            continue;
        }
        String clean = lstrip(token, "(");
        int range = token.length() - clean.length();
        // logger.debug("lstrip: {}, range:{}", new Object[] { clean, range
        // });
        for (int i = 0; i < range; i++) {
            BaseCheck check = new StringCheck("(");
            entrys.add(Maps.immutableEntry("(", check));
        }

        if (Strings.isNullOrEmpty(clean)) {
            continue;
        } else {
            token = clean;
        }

        clean = rstrip(token, ")");
        int trail = token.length() - clean.length();
        // logger.debug("rstrip: {}, trail:{}", new Object[] { clean, trail
        // });
        String lowered = clean.toLowerCase();
        if (logicOperators.contains(lowered)) {
            BaseCheck check = new StringCheck(clean);
            entrys.add(Maps.immutableEntry(lowered, check));
        } else if (!Strings.isNullOrEmpty(clean)) {
            if (token.length() >= 2 && ((token.charAt(0) == '\"' && token.charAt(token.length()) == '\"')
                    || (token.charAt(0) == '\'' && token.charAt(token.length()) == '\''))) {
                BaseCheck check = new StringCheck(token.substring(1, token.length() - 1));
                entrys.add(Maps.immutableEntry("string", check));
            } else {
                entrys.add(Maps.immutableEntry("check", parseCheck(clean)));
            }
        }

        for (int i = 0; i < trail; i++) {
            BaseCheck check = new StringCheck(")");
            entrys.add(Maps.immutableEntry(")", check));
        }
    }

    return entrys;
}

From source file:me.lucko.luckperms.common.commands.impl.generic.meta.MetaInfo.java

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args,
        String label, CommandPermission permission) throws CommandException {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }//from  www . jav a2s.  co  m

    SortedSet<Map.Entry<Integer, LocalizedNode>> prefixes = new TreeSet<>(MetaComparator.INSTANCE.reversed());
    SortedSet<Map.Entry<Integer, LocalizedNode>> suffixes = new TreeSet<>(MetaComparator.INSTANCE.reversed());
    Set<LocalizedNode> meta = new HashSet<>();

    // Collect data
    for (LocalizedNode node : holder.resolveInheritances()) {
        if (!node.isSuffix() && !node.isPrefix() && !node.isMeta()) {
            continue;
        }

        if (node.isPrefix()) {
            prefixes.add(Maps.immutableEntry(node.getPrefix().getKey(), node));
        } else if (node.isSuffix()) {
            suffixes.add(Maps.immutableEntry(node.getSuffix().getKey(), node));
        } else if (node.isMeta()) {
            meta.add(node);
        }
    }

    if (prefixes.isEmpty()) {
        Message.CHAT_META_PREFIX_NONE.send(sender, holder.getFriendlyName());
    } else {
        Message.CHAT_META_PREFIX_HEADER.send(sender, holder.getFriendlyName());
        sendChatMetaMessage(ChatMetaType.PREFIX, prefixes, sender, holder, label);
    }

    if (suffixes.isEmpty()) {
        Message.CHAT_META_SUFFIX_NONE.send(sender, holder.getFriendlyName());
    } else {
        Message.CHAT_META_SUFFIX_HEADER.send(sender, holder.getFriendlyName());
        sendChatMetaMessage(ChatMetaType.SUFFIX, suffixes, sender, holder, label);
    }

    if (meta.isEmpty()) {
        Message.META_NONE.send(sender, holder.getFriendlyName());
    } else {
        Message.META_HEADER.send(sender, holder.getFriendlyName());
        sendMetaMessage(meta, sender, holder, label);
    }

    return CommandResult.SUCCESS;
}

From source file:com.infinities.keystone4j.policy.Rules.java

private static List<Entry<String, BaseCheck>> parseTokenize(String rule) {
    String[] tokens = rule.split("\\s+");

    List<Entry<String, BaseCheck>> entrys = Lists.newArrayList();

    for (String token : tokens) {
        token = token.trim();//from  w  ww .j av  a2s  .c  o m
        if (Strings.isNullOrEmpty(token)) {
            continue;
        }
        String clean = StringUtils.removeStart(token, "(");
        int range = token.length() - clean.length();
        // logger.debug("lstrip: {}, range:{}", new Object[] { clean, range
        // });
        for (int i = 0; i < range; i++) {
            BaseCheck check = new StringCheck("(");
            entrys.add(Maps.immutableEntry("(", check));
        }

        if (Strings.isNullOrEmpty(clean)) {
            continue;
        } else {
            token = clean;
        }

        clean = StringUtils.removeEnd(token, ")");
        int trail = token.length() - clean.length();
        // logger.debug("rstrip: {}, trail:{}", new Object[] { clean, trail
        // });
        String lowered = clean.toLowerCase();
        if (logicOperators.contains(lowered)) {
            BaseCheck check = new StringCheck(clean);
            entrys.add(Maps.immutableEntry(lowered, check));
        } else if (!Strings.isNullOrEmpty(clean)) {
            if (token.length() >= 2 && ((token.charAt(0) == '\"' && token.charAt(token.length()) == '\"')
                    || (token.charAt(0) == '\'' && token.charAt(token.length()) == '\''))) {
                BaseCheck check = new StringCheck(token.substring(1, token.length() - 1));
                entrys.add(Maps.immutableEntry("string", check));
            } else {
                entrys.add(Maps.immutableEntry("check", parseCheck(clean)));
            }
        }

        for (int i = 0; i < trail; i++) {
            BaseCheck check = new StringCheck(")");
            entrys.add(Maps.immutableEntry(")", check));
        }
    }

    return entrys;
}

From source file:google.registry.tools.CreateTldCommand.java

@Override
Optional<Map.Entry<DateTime, TldState>> getTldStateTransitionToAdd() {
    return initialTldState != null ? Optional.of(Maps.immutableEntry(START_OF_TIME, initialTldState))
            : Optional.<Map.Entry<DateTime, TldState>>absent();
}

From source file:com.nesscomputing.cache.JvmCacheProvider.java

private Entry<String, String> makeKey(String namespace, String key) {
    return Maps.immutableEntry(namespace, key);
}

From source file:org.jooby.internal.spec.RouteCollector.java

@Override
public void visit(final MethodCallExpr n, final Context ctx) {
    if (script) {
        Type mvcClass = useMvc(n, ctx);
        if (mvcClass != null) {
            mvcRoutes(n, mvcClass, ctx);
        } else {/*from www  .  j  a v a  2  s.  co  m*/
            Type appType = importApp(n, ctx);
            if (appType != null) {
                importRoutes(appType, ctx);
            } else {
                List<MethodCallExpr> routes = routes(n, ctx);
                for (MethodCallExpr route : routes) {
                    Optional<LambdaExpr> lambda = route.getArgs().stream().map(it -> handler(it, ctx))
                            .filter(it -> it != null).findFirst();
                    this.nodes.add(Maps.immutableEntry(route, lambda.get()));
                }
            }
        }
    }
}

From source file:org.onosproject.store.primitives.impl.TranscodingAsyncConsistentTreeMap.java

@Override
public CompletableFuture<Map.Entry<String, Versioned<V1>>> lastEntry() {
    return backingMap.lastEntry().thenApply(
            entry -> Maps.immutableEntry(entry.getKey(), versionedValueTransform.apply(entry.getValue())));
}