List of usage examples for com.google.common.collect ImmutableMap isEmpty
@Override public boolean isEmpty()
From source file:com.proofpoint.jmx.MBeanRepresentation.java
private static Map<String, Object> toMap(Descriptor descriptor) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); for (String fieldName : descriptor.getFieldNames()) { Object fieldValue = descriptor.getFieldValue(fieldName); if (fieldName != null) { builder.put(fieldName, fieldValue); }// w ww . jav a 2 s . com } ImmutableMap<String, Object> map = builder.build(); if (!map.isEmpty()) { return map; } else { return null; } }
From source file:io.airlift.jmx.MBeanRepresentation.java
private static Map<String, Object> toMap(Descriptor descriptor) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); for (String fieldName : descriptor.getFieldNames()) { Object fieldValue = descriptor.getFieldValue(fieldName); if (fieldValue != null) { if (fieldValue instanceof Descriptor) { fieldValue = toMap((Descriptor) fieldValue); }/*from ww w . j ava 2s . co m*/ builder.put(fieldName, fieldValue); } } ImmutableMap<String, Object> map = builder.build(); if (!map.isEmpty()) { return map; } else { return null; } }
From source file:com.palantir.common.concurrent.ExecutorInheritableThreadLocal.java
/** * @return the old map installed on that thread *///from w ww . j a va2s . c om static ConcurrentMap<ExecutorInheritableThreadLocal<?>, Object> installMapOnThread( ImmutableMap<ExecutorInheritableThreadLocal<?>, Object> map) { ConcurrentMap<ExecutorInheritableThreadLocal<?>, Object> oldMap = mapForThisThread.get(); if (map.isEmpty()) { mapForThisThread.remove(); } else { ConcurrentMap<ExecutorInheritableThreadLocal<?>, Object> newMap = makeNewMap(); newMap.putAll(map); // Install the map in case callInstallOnChildThread makes use // of existing thread locals (UserSessionClientInfo does this). mapForThisThread.set(newMap); for (ExecutorInheritableThreadLocal<?> e : map.keySet()) { @SuppressWarnings("unchecked") ExecutorInheritableThreadLocal<Object> eitl = (ExecutorInheritableThreadLocal<Object>) e; eitl.set(eitl.callInstallOnChildThread(eitl.get())); } } return oldMap; }
From source file:eu.eidas.auth.commons.EIDASUtil.java
/** * Returns the identifier of some configuration given a set of configurations and the corresponding configuration * key.// w w w . ja va2 s. c o m * * @param configKey The key that IDs some configuration. * @return The configuration String value. */ @Nullable public static String getConfig(@Nullable String configKey) { Preconditions.checkNotNull(configKey, "configKey"); ImmutableMap<String, String> properties = INSTANCE.getProperties(); final String propertyValue; if (properties.isEmpty()) { LOG.warn("BUSINESS EXCEPTION : Configs not loaded - property-Key value is null or empty {} ", configKey); propertyValue = configKey; } else { propertyValue = properties.get(configKey); if (StringUtils.isEmpty(propertyValue)) { LOG.warn("BUSINESS EXCEPTION : Invalid property-Key value is null or empty {}", configKey); } } return propertyValue; }
From source file:org.apache.james.jmap.model.Message.java
protected static boolean areAttachedMessagesKeysInAttachments(ImmutableList<Attachment> attachments, ImmutableMap<BlobId, SubMessage> attachedMessages) { return attachedMessages.isEmpty() || attachedMessages.keySet().stream().anyMatch(inAttachments(attachments)); }
From source file:com.facebook.buck.artifact_cache.ArtifactCaches.java
private static ArtifactCache createHttpArtifactCache(HttpCacheEntry cacheDescription, final String hostToReportToRemote, final BuckEventBus buckEventBus, ProjectFilesystem projectFilesystem, ListeningExecutorService httpWriteExecutorService, ArtifactCacheBuckConfig config, NetworkCacheFactory factory, boolean distributedBuildModeEnabled) { // Setup the default client to use. OkHttpClient.Builder storeClientBuilder = new OkHttpClient.Builder(); storeClientBuilder.networkInterceptors() .add(chain -> chain.proceed(chain.request().newBuilder() .addHeader("X-BuckCache-User", System.getProperty("user.name", "<unknown>")) .addHeader("X-BuckCache-Host", hostToReportToRemote).build())); int timeoutSeconds = cacheDescription.getTimeoutSeconds(); setTimeouts(storeClientBuilder, timeoutSeconds); storeClientBuilder.connectionPool(new ConnectionPool( /* maxIdleConnections */ (int) config.getThreadPoolSize(), /* keepAliveDurationMs */ config.getThreadPoolKeepAliveDurationMillis(), TimeUnit.MILLISECONDS)); final ImmutableMap<String, String> readHeaders = cacheDescription.getReadHeaders(); final ImmutableMap<String, String> writeHeaders = cacheDescription.getWriteHeaders(); // If write headers are specified, add them to every default client request. if (!writeHeaders.isEmpty()) { storeClientBuilder.networkInterceptors().add(chain -> chain .proceed(addHeadersToBuilder(chain.request().newBuilder(), writeHeaders).build())); }// w w w. j a v a 2 s. c o m OkHttpClient storeClient = storeClientBuilder.build(); // For fetches, use a client with a read timeout. OkHttpClient.Builder fetchClientBuilder = storeClient.newBuilder(); setTimeouts(fetchClientBuilder, timeoutSeconds); // If read headers are specified, add them to every read client request. if (!readHeaders.isEmpty()) { fetchClientBuilder.networkInterceptors().add( chain -> chain.proceed(addHeadersToBuilder(chain.request().newBuilder(), readHeaders).build())); } fetchClientBuilder.networkInterceptors().add((chain -> { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder() .body(new ProgressResponseBody(originalResponse.body(), buckEventBus)).build(); })); OkHttpClient fetchClient = fetchClientBuilder.build(); HttpService fetchService; HttpService storeService; switch (config.getLoadBalancingType()) { case CLIENT_SLB: HttpLoadBalancer clientSideSlb = config.getSlbConfig().createClientSideSlb(new DefaultClock(), buckEventBus, new CommandThreadFactory("ArtifactCaches.HttpLoadBalancer", SLB_THREAD_PRIORITY)); fetchService = new RetryingHttpService(buckEventBus, new LoadBalancedService(clientSideSlb, fetchClient, buckEventBus), config.getMaxFetchRetries()); storeService = new LoadBalancedService(clientSideSlb, storeClient, buckEventBus); break; case SINGLE_SERVER: URI url = cacheDescription.getUrl(); fetchService = new SingleUriService(url, fetchClient); storeService = new SingleUriService(url, storeClient); break; default: throw new IllegalArgumentException("Unknown HttpLoadBalancer type: " + config.getLoadBalancingType()); } String cacheName = cacheDescription.getName().map(input -> "http-" + input).orElse("http"); boolean doStore = cacheDescription.getCacheReadMode().isDoStore(); return factory .newInstance(NetworkCacheArgs.builder().setThriftEndpointPath(config.getHybridThriftEndpoint()) .setCacheName(cacheName).setRepository(config.getRepository()) .setScheduleType(config.getScheduleType()).setFetchClient(fetchService) .setStoreClient(storeService).setDoStore(doStore).setProjectFilesystem(projectFilesystem) .setBuckEventBus(buckEventBus).setHttpWriteExecutorService(httpWriteExecutorService) .setErrorTextTemplate(cacheDescription.getErrorMessageFormat()) .setDistributedBuildModeEnabled(distributedBuildModeEnabled).build()); }
From source file:de.metas.ui.web.process.adprocess.WebuiProcessClassInfo.java
private static WebuiProcessClassInfo createWebuiProcessClassInfo(final Class<?> processClass) throws Exception { final ProcessClassInfo processClassInfo = ProcessClassInfo.of(processClass); final WebuiProcess webuiProcessAnn = processClass.getAnnotation(WebuiProcess.class); @SuppressWarnings("unchecked") final Set<Method> lookupValuesProviderMethods = ReflectionUtils.getAllMethods(processClass, ReflectionUtils.withAnnotation(ProcessParamLookupValuesProvider.class)); final ImmutableMap<String, LookupDescriptorProvider> paramLookupValuesProviders = lookupValuesProviderMethods .stream().map(method -> createParamLookupValuesProvider(method)) .collect(GuavaCollectors.toImmutableMap()); ////w w w . java 2 s . com // Check is there were no settings at all so we could return our NULL instance if (ProcessClassInfo.isNull(processClassInfo) && paramLookupValuesProviders.isEmpty()) { return NULL; } return new WebuiProcessClassInfo(processClassInfo, webuiProcessAnn, paramLookupValuesProviders); }
From source file:com.vmware.photon.controller.common.dcp.QueryTaskUtils.java
/** * Builds a QueryTask.QuerySpecification which will query for documents of type T. * Any other filter clauses are optional. * This allows for a query that returns all documents of type T. * This also expands the content of the resulting documents. * * @param documentType/*from w w w .j a v a 2 s. c om*/ * @param terms * @return */ public static QueryTask.QuerySpecification buildQuerySpec(Class documentType, ImmutableMap<String, String> terms) { checkNotNull(documentType, "Cannot build query spec for unspecified documentType"); QueryTask.QuerySpecification spec = new QueryTask.QuerySpecification(); QueryTask.Query documentKindClause = new QueryTask.Query() .setTermPropertyName(ServiceDocument.FIELD_NAME_KIND) .setTermMatchValue(Utils.buildKind(documentType)); if (terms == null || terms.isEmpty()) { // since there are no other clauses // skip adding boolean clauses // to workaround the DCP requirement to have at least 2 // boolean clauses for a valid query spec.query = documentKindClause; } else { spec.query.addBooleanClause(documentKindClause); for (String key : terms.keySet()) { QueryTask.Query clause = new QueryTask.Query().setTermPropertyName(key) .setTermMatchValue(terms.get(key)); spec.query.addBooleanClause(clause); } } return spec; }
From source file:com.vmware.photon.controller.common.xenon.QueryTaskUtils.java
/** * Builds a QueryTask.QuerySpecification which will query for documents of type T. * Any other filter clauses are optional. * This allows for a query that returns all documents of type T. * This also expands the content of the resulting documents. * * @param documentType//from w ww . j a v a 2 s . c om * @param terms * @return */ public static QueryTask.QuerySpecification buildQuerySpec(Class documentType, ImmutableMap<String, String> terms) { checkNotNull(documentType, "Cannot build query spec for unspecified documentType"); QueryTask.QuerySpecification spec = new QueryTask.QuerySpecification(); QueryTask.Query documentKindClause = new QueryTask.Query() .setTermPropertyName(ServiceDocument.FIELD_NAME_KIND) .setTermMatchValue(Utils.buildKind(documentType)); if (terms == null || terms.isEmpty()) { // since there are no other clauses // skip adding boolean clauses // to workaround the Xenon requirement to have at least 2 // boolean clauses for a valid query spec.query = documentKindClause; } else { spec.query.addBooleanClause(documentKindClause); for (String key : terms.keySet()) { QueryTask.Query clause = new QueryTask.Query().setTermPropertyName(key) .setTermMatchValue(terms.get(key)); spec.query.addBooleanClause(clause); } } return spec; }
From source file:org.glowroot.agent.weaving.AdviceCache.java
private static ImmutableList<Advice> createReweavableAdvisors(List<InstrumentationConfig> reweavableConfigs, @Nullable Instrumentation instrumentation, File tmpDir, boolean cleanTmpDir) throws Exception { ImmutableMap<Advice, LazyDefinedClass> advisors = AdviceGenerator.createAdvisors(reweavableConfigs, null, false, true);//from ww w. ja v a 2 s . c om if (instrumentation == null) { // instrumentation is null when debugging with LocalContainer ClassLoader isolatedWeavingClassLoader = Thread.currentThread().getContextClassLoader(); checkNotNull(isolatedWeavingClassLoader); ClassLoaders.defineClasses(advisors.values(), isolatedWeavingClassLoader); } else { if (cleanTmpDir) { ClassLoaders.createDirectoryOrCleanPreviousContentsWithPrefix(tmpDir, "config-pointcuts"); } if (!advisors.isEmpty()) { String suffix = ""; int count = jarFileCounter.incrementAndGet(); if (count > 1) { suffix = "-" + count; } File jarFile = new File(tmpDir, "config-pointcuts" + suffix + ".jar"); ClassLoaders.defineClassesInBootstrapClassLoader(advisors.values(), instrumentation, jarFile); } } return advisors.keySet().asList(); }