List of usage examples for com.google.common.collect ImmutableMap isEmpty
@Override public boolean isEmpty()
From source file:org.jclouds.rackspace.autoscale.v1.binders.BindWebhookToJson.java
@SuppressWarnings("unchecked") @Override/* w w w. ja v a 2 s. co m*/ public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { ImmutableMap.Builder<String, Object> webhook = ImmutableMap.builder(); webhook.put("name", postParams.get("name")); ImmutableMap<String, Object> metadata = postParams.get("metadata") != null ? ImmutableMap.copyOf((Map<String, Object>) postParams.get("metadata")) : ImmutableMap.<String, Object>of(); if (!metadata.isEmpty()) { webhook.put("metadata", postParams.get("metadata")); } return jsonBinder.bindToRequest(request, ImmutableList.of(webhook.build())); }
From source file:google.registry.model.ofy.CommitLoggedWork.java
/** Check that the timestamp of each BackupGroupRoot is in the past. */ private void checkBackupGroupRootTimestamps(DateTime transactionTime, Set<Entry<Key<BackupGroupRoot>, BackupGroupRoot>> bgrEntries) { ImmutableMap.Builder<Key<BackupGroupRoot>, DateTime> builder = new ImmutableMap.Builder<>(); for (Entry<Key<BackupGroupRoot>, BackupGroupRoot> entry : bgrEntries) { DateTime updateTime = entry.getValue().getUpdateAutoTimestamp().getTimestamp(); if (!updateTime.isBefore(transactionTime)) { builder.put(entry.getKey(), updateTime); }//from ww w . j ava 2 s . c o m } ImmutableMap<Key<BackupGroupRoot>, DateTime> problematicRoots = builder.build(); if (!problematicRoots.isEmpty()) { throw new TimestampInversionException(transactionTime, problematicRoots); } }
From source file:org.apache.rya.shell.util.RyaDetailsFormatter.java
/** * Pretty formats an instance of {@link RyaDetails}. * * @param details - The object to format. (not null) * @return A pretty render of the object. *///from www .ja v a 2s.co m public String format(final RyaDetails details) { requireNonNull(details); final StringBuilder report = new StringBuilder(); report.append("General Metadata:\n"); report.append(" Instance Name: ").append(details.getRyaInstanceName()).append("\n"); report.append(" RYA Version: ").append(details.getRyaVersion()).append("\n"); report.append(" Users: ").append(Joiner.on(", ").join(details.getUsers())).append("\n"); report.append("Secondary Indicies:\n"); report.append(" Entity Centric Index:\n"); report.append(" Enabled: ").append(details.getEntityCentricIndexDetails().isEnabled()).append("\n"); //RYA-215 report.append(" Geospatial Index:\n"); //RYA-215 report.append(" Enabled: ").append( details.getGeoIndexDetails().isEnabled() ).append("\n"); report.append(" Free Text Index:\n"); report.append(" Enabled: ").append(details.getFreeTextIndexDetails().isEnabled()).append("\n"); report.append(" Temporal Index:\n"); report.append(" Enabled: ").append(details.getTemporalIndexDetails().isEnabled()).append("\n"); report.append(" PCJ Index:\n"); final PCJIndexDetails pcjDetails = details.getPCJIndexDetails(); report.append(" Enabled: ").append(pcjDetails.isEnabled()).append("\n"); if (pcjDetails.isEnabled()) { if (pcjDetails.getFluoDetails().isPresent()) { final String fluoAppName = pcjDetails.getFluoDetails().get().getUpdateAppName(); report.append(" Fluo App Name: ").append(fluoAppName).append("\n"); } final ImmutableMap<String, PCJDetails> pcjs = pcjDetails.getPCJDetails(); report.append(" PCJs:\n"); if (pcjs.isEmpty()) { report.append(" No PCJs have been added yet.\n"); } else { for (final PCJDetails pcj : pcjs.values()) { report.append(" ID: ").append(pcj.getId()).append("\n"); final String updateStrategy = format(pcj.getUpdateStrategy(), "None"); report.append(" Update Strategy: ").append(updateStrategy).append("\n"); final String lastUpdateTime = format(pcj.getLastUpdateTime(), "unavailable"); report.append(" Last Update Time: ").append(lastUpdateTime).append("\n"); } } } report.append("Statistics:\n"); report.append(" Prospector:\n"); final String prospectorLastUpdateTime = format(details.getProspectorDetails().getLastUpdated(), "unavailable"); report.append(" Last Update Time: ").append(prospectorLastUpdateTime).append("\n"); report.append(" Join Selectivity:\n"); final String jsLastUpdateTime = format(details.getJoinSelectivityDetails().getLastUpdated(), "unavailable"); report.append(" Last Updated Time: ").append(jsLastUpdateTime).append("\n"); return report.toString(); }
From source file:org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider.java
@Inject public FilterAllocationDecider(Settings settings, NodeSettingsService nodeSettingsService) { super(settings); ImmutableMap<String, String> requireMap = settings.getByPrefix(CLUSTER_ROUTING_REQUIRE_GROUP).getAsMap(); if (requireMap.isEmpty()) { clusterRequireFilters = null;//from www . j a v a 2s . c o m } else { clusterRequireFilters = DiscoveryNodeFilters.buildFromKeyValue(AND, requireMap); } ImmutableMap<String, String> includeMap = settings.getByPrefix(CLUSTER_ROUTING_INCLUDE_GROUP).getAsMap(); if (includeMap.isEmpty()) { clusterIncludeFilters = null; } else { clusterIncludeFilters = DiscoveryNodeFilters.buildFromKeyValue(OR, includeMap); } ImmutableMap<String, String> excludeMap = settings.getByPrefix(CLUSTER_ROUTING_EXCLUDE_GROUP).getAsMap(); if (excludeMap.isEmpty()) { clusterExcludeFilters = null; } else { clusterExcludeFilters = DiscoveryNodeFilters.buildFromKeyValue(OR, excludeMap); } nodeSettingsService.addListener(new ApplySettings()); }
From source file:com.google.caliper.runner.config.CaliperConfig.java
/** * Returns the default set of instruments to use if the user doesn't specify which instruments to * use on the command line.//from w w w . j av a2s . c o m */ public ImmutableSet<String> getDefaultInstruments() { // TODO(cgdecker): could/should this "defaults" be generalized? // e.g. if there's a command line option "--foo", "defaults.foo" is the default value of "foo" // if the user doesn't pass that option. This is already the case here since "--instrument" is // the long-form commmand line option, but I'm not trying to generalize now since there's no // apparent need to. ImmutableMap<String, String> defaults = subgroupMap(properties, "defaults"); if (!defaults.isEmpty()) { String instruments = defaults.get("instrument"); if (instruments != null) { return ImmutableSet.copyOf(Splitter.on(',').split(instruments)); } } throw new InvalidConfigurationException( "Could not find default set of instruments to use (defaults.instrument in config file)"); }
From source file:com.facebook.buck.remoteexecution.util.MultiThreadedBlobUploader.java
/** Uploads missing items to the CAS. */ public ListenableFuture<Void> addMissing(ImmutableMap<Digest, UploadDataSupplier> data) { data = ImmutableMap.copyOf(Maps.filterKeys(data, k -> !containedHashes.contains(k.getHash()))); if (data.isEmpty()) { return Futures.immediateFuture(null); }/*from w w w. ja va 2 s .c o m*/ return enqueue(data); }
From source file:com.zulily.omicron.conf.Configuration.java
/** * Extract a new instance based off of this one but with some of the config values being updated * * @param overrideMap ConfigKey values to override * @return An instance with the updated config values */// w w w . ja va 2 s.c o m public Configuration withOverrides(final ImmutableMap<ConfigKey, String> overrideMap) { if (overrideMap == null || overrideMap.isEmpty()) { return this; } HashMap<ConfigKey, String> result = Maps.newHashMap(this.rawConfigMap); result.putAll(overrideMap); return new Configuration(ImmutableMap.copyOf(result), this.getConfigurationTimestamp(), this.configFilePath); }
From source file:com.facebook.buck.doctor.DoctorReportHelper.java
public DoctorEndpointResponse uploadRequest(DoctorEndpointRequest request) { if (!doctorConfig.getEndpointUrl().isPresent()) { String errorMsg = String.format( "Doctor endpoint URL is not set. Please set [%s] %s on your .buckconfig", DoctorConfig.DOCTOR_SECTION, DoctorConfig.URL_FIELD); return createErrorDoctorEndpointResponse(errorMsg); }/*from w w w .j av a2 s . c om*/ byte[] requestJson; try { requestJson = objectMapper.writeValueAsBytes(request); } catch (JsonProcessingException e) { return createErrorDoctorEndpointResponse( "Failed to encode request to JSON. " + "Reason: " + e.getMessage()); } OkHttpClient httpClient = new OkHttpClient.Builder() .connectTimeout(doctorConfig.getHttpTimeoutMs(), TimeUnit.MILLISECONDS) .readTimeout(doctorConfig.getHttpTimeoutMs(), TimeUnit.MILLISECONDS) .writeTimeout(doctorConfig.getHttpTimeoutMs(), TimeUnit.MILLISECONDS).build(); Response httpResponse; try { RequestBody requestBody; ImmutableMap<String, String> extraArgs = doctorConfig.getExtraRequestArgs(); if (extraArgs.isEmpty()) { requestBody = RequestBody.create(JSON, requestJson); } else { FormBody.Builder formBody = new FormBody.Builder(); formBody.add("data", new String(requestJson)); for (Map.Entry<String, String> entry : extraArgs.entrySet()) { formBody.add(entry.getKey(), entry.getValue()); } requestBody = formBody.build(); } Request httpRequest = new Request.Builder().url(doctorConfig.getEndpointUrl().get()).post(requestBody) .build(); httpResponse = httpClient.newCall(httpRequest).execute(); } catch (IOException e) { return createErrorDoctorEndpointResponse("Failed to perform the request to " + doctorConfig.getEndpointUrl().get() + ". Reason: " + e.getMessage()); } try { if (httpResponse.isSuccessful()) { String body = new String(httpResponse.body().bytes(), Charsets.UTF_8); return objectMapper.readValue(body, DoctorEndpointResponse.class); } return createErrorDoctorEndpointResponse("Request was not successful."); } catch (JsonProcessingException e) { return createErrorDoctorEndpointResponse(String.format(DECODE_FAIL_TEMPLATE, e.getMessage())); } catch (IOException e) { return createErrorDoctorEndpointResponse(String.format(DECODE_FAIL_TEMPLATE, e.getMessage())); } }
From source file:at.molindo.esi4j.mapping.impl.GenericTypeMapping.java
@Override public final MappingSource getMappingSource() { try {/*from ww w.j a va2s . c o m*/ if (_mapping == null || isDynamicMapping()) { Builder mapperBuilder = new RootObjectMapper.Builder(getTypeAlias()); buildMapping(mapperBuilder); XContentBuilder contentBuilder = JsonXContent.contentBuilder(); contentBuilder.startObject(); mapperBuilder.build(new BuilderContext(ImmutableSettings.EMPTY, new ContentPath())) .toXContent(contentBuilder, EMPTY_PARAMS, new ToXContent() { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { ImmutableMap<String, Object> meta = meta(); if (meta != null && !meta.isEmpty()) { builder.field("_meta", meta); } return builder; } }); contentBuilder.endObject(); // cache mapping as string for easy debugging _mapping = contentBuilder.string(); } return MappingSource.Builder.string(_mapping); } catch (IOException e) { throw new RuntimeException(); } }
From source file:org.openqa.selenium.remote.session.EdgeFilter.java
@Override public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) { ImmutableMap<String, Object> caps = unmodifiedCaps.entrySet().parallelStream() .filter(entry -> ("browserName".equals(entry.getKey()) && "edge".equals(entry.getValue()))) .distinct().filter(entry -> Objects.nonNull(entry.getValue())) .collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)); return caps.isEmpty() ? null : caps; }