Example usage for com.google.common.collect ImmutableMap isEmpty

List of usage examples for com.google.common.collect ImmutableMap isEmpty

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMap isEmpty.

Prototype

@Override
    public boolean isEmpty() 

Source Link

Usage

From source file:com.google.devtools.build.java.bazel.JavaBuilderConfigGenerator.java

public static void main(String[] args) {
    try {/* w w  w.j a  v a  2s.  co  m*/
        InputStream stream = System.in;
        if (args.length > 0) {
            stream = new FileInputStream(args[0]);
        }
        ImmutableMap<String, JavaToolchainData> data = JavaToolchainDataParser.parse(stream);
        if (data.size() != 1) {
            die(data.isEmpty() ? "No java_toolchain found!" : "Multiple java_toolchain found!");
        }
        JavaToolchainData first = data.values().asList().get(0);
        String optsString = Joiner.on("\", \"").join(first.getJavacOptions());
        System.out.println("package com.google.devtools.build.java.bazel;");
        System.out.println("public class JavaBuilderJavacOpts {");
        System.out.println("public static final String[] DEFAULT_JAVACOPTS = {\"" + optsString + "\"};");
        System.out.println("}");
    } catch (IOException e) {
        die("Cannot load input file: " + e.getMessage());
    }
}

From source file:ai.grakn.graql.internal.gremlin.spanningtree.Arborescence.java

public static <T> Arborescence<T> of(ImmutableMap<T, T> parents) {
    if (parents != null && !parents.isEmpty()) {
        HashSet<T> allParents = Sets.newHashSet(parents.values());
        allParents.removeAll(parents.keySet());
        if (allParents.size() == 1) {
            return new Arborescence<>(parents, allParents.iterator().next());
        }/*from   w  w w  . j  a v  a2s.  c om*/
    }
    return new Arborescence<>(parents, null);
}

From source file:eu.eubrazilcc.lvl.storage.mongodb.MongoDBHelper.java

public static BasicDBObject toProjection(final @Nullable ImmutableMap<String, Boolean> projection) {
    BasicDBObject obj = null;/*from w  w  w . ja  v  a2 s.  com*/
    if (projection != null && !projection.isEmpty()) {
        obj = new BasicDBObject();
        final ImmutableSet<Entry<String, Boolean>> entrySet = projection.entrySet();
        final boolean action = entrySet.iterator().next().getValue();
        for (final Entry<String, Boolean> entry : entrySet) {
            String field = null;
            checkState(action == entry.getValue(),
                    "A projection cannot contain both include and exclude specifications");
            checkState(isNotBlank(field = trimToNull(entry.getKey())), "Uninitialized field");
            obj.append(field, action ? 1 : 0);
        }
    }
    return obj;
}

From source file:com.google.devtools.build.lib.skyframe.CollectPackagesUnderDirectoryValue.java

public static CollectPackagesUnderDirectoryValue of(boolean isDirectoryPackage,
        ImmutableMap<RootedPath, Boolean> subdirectoryTransitivelyContainsPackages) {
    if (!isDirectoryPackage && subdirectoryTransitivelyContainsPackages.isEmpty()) {
        return EMPTY;
    }//  ww w  .j av a 2s. c o  m
    return new CollectPackagesUnderDirectoryValue(isDirectoryPackage, subdirectoryTransitivelyContainsPackages);
}

From source file:com.google.devtools.build.lib.skylarkdebug.server.DebugEventHelper.java

private static ImmutableList<Scope> getScopes(DebugFrame frame) {
    ImmutableMap<String, Object> localVars = frame.lexicalFrameBindings();
    if (localVars.isEmpty()) {
        return ImmutableList.of(getScope("global", frame.globalBindings()));
    }//from  w  ww  .  j  av a2s .  c  o m
    Map<String, Object> globalVars = new LinkedHashMap<>(frame.globalBindings());
    // remove shadowed bindings
    localVars.keySet().forEach(globalVars::remove);

    return ImmutableList.of(getScope("local", localVars), getScope("global", globalVars));
}

From source file:net.sf.lucis.core.Highlight.java

public static Highlight of(Map<String, Integer> fields) {
    final ImmutableMap<String, Integer> f = filter(fields);
    if (f.isEmpty()) {
        return no();
    }//from w  w  w  . j  a va 2s .c  om
    return new Some(Factory.get().standardAnalyzer(), new SimpleHTMLFormatter(), f);
}

From source file:net.sf.lucis.core.Highlight.java

public static Highlight of(Analyzer analyzer, Formatter formatter, Map<String, Integer> fields) {
    final ImmutableMap<String, Integer> f = filter(fields);
    if (f.isEmpty()) {
        return no();
    }/*from   w w w  .j a v  a 2s .c o  m*/
    checkNotNull(analyzer);
    checkNotNull(formatter);
    return new Some(analyzer, formatter, f);
}

From source file:net.conquiris.api.search.Highlight.java

public static Highlight of(Map<String, Integer> fields) {
    final ImmutableMap<String, Integer> f = filter(fields);
    if (f.isEmpty()) {
        return no();
    }/* www.j  a v a 2  s . co m*/
    return new Some(new StandardAnalyzer(Version.LUCENE_34), new SimpleHTMLFormatter(), f);
}

From source file:com.sourceclear.headlines.util.HeaderBuilder.java

public static String formatDirectives(ImmutableMap<String, ImmutableList<String>> directives) {

    // In the case of an empty map return the empty string:
    if (directives.isEmpty()) {
        return "";
    }//from   w w w  . j a  v a  2 s  . co m

    StringBuilder sb = new StringBuilder();

    // Outer loop - loop through each directive
    for (String directive : directives.keySet()) {

        // Don't add a directive if it has zero elements
        if (directives.get(directive).size() == 0) {
            continue;
        }

        StringBuilder elements = new StringBuilder();

        // Inner loop = for each directive build up the element String
        for (String element : directives.get(directive)) {
            elements.append(element).append(" ");
        }

        if (sb.length() > 0) {
            sb.append("; ");
        }

        sb.append(directive).append(" ").append(elements.append(" ").toString());
    }

    return sb.toString().trim();
}

From source file:org.grycap.gpf4med.Gpf4MedService.java

/**
 * Creates a Grizzly HTTP server exposing JAX-RS resources defined in this service.
 * @return Grizzly HTTP server.// w w w.j av  a2 s .c  o  m
 */
private static HttpServer createServer(final String baseUri) {
    HttpServer server = null;
    try {
        // scan for connectors
        final Set<Class<?>> classSet = newLinkedHashSet();
        final ImmutableMap<String, GraphConnector> connectors = GraphConnectorManager.INSTANCE.listConnectors();
        if (connectors != null && !connectors.isEmpty()) {
            classSet.addAll(transform(connectors.entrySet(),
                    new Function<Map.Entry<String, GraphConnector>, Class<?>>() {
                        @Override
                        public Class<?> apply(final Entry<String, GraphConnector> entry) {
                            return entry.getValue().restResourceImplementation();
                        }
                    }));
        }

        // create a resource configuration that scans for JAX-RS resources and providers
        final ResourceConfig resourceConfig = ResourceConfig.forApplication(new Application() {
            @Override
            public Set<Class<?>> getClasses() {
                final Set<Class<?>> classes = newHashSet();
                classes.add(Gpf4MedResourceImpl.class);
                return classes;
            }
        }).register(MoxyJsonFeature.class);
        if (!classSet.isEmpty()) {
            resourceConfig.registerClasses(classSet);
        }

        // create a non-started-yet HttpServer instance
        server = GrizzlyHttpServerFactory.createHttpServer(URI.create(baseUri), resourceConfig, false);

        // serve static HTTP resources from file-system
        final File htdocsDir = ConfigurationManager.INSTANCE.getHtdocsDir();
        if (htdocsDir != null && htdocsDir.isDirectory() && htdocsDir.canRead()) {
            final StaticHttpHandler staticHttpHandler = new StaticHttpHandler(htdocsDir.getCanonicalPath());
            server.getServerConfiguration().addHttpHandler(staticHttpHandler, "/");
        }

        // apply any optional configuration to the HttpServer instance and start the service
        final TCPNIOTransport transport = server.getListener("grizzly").getTransport();
        transport.setTcpNoDelay(true);
    } catch (Exception e) {
        server = null;
        LOGGER.error("Failed to create HTTP server", e);
    }
    return server;
}