List of usage examples for com.google.common.collect ImmutableList isEmpty
boolean isEmpty();
From source file:google.registry.flows.domain.DomainDeleteFlow.java
@Nullable private ImmutableList<FeeTransformResponseExtension> getResponseExtensions(DomainResource existingDomain, DateTime now) {/*from w w w .ja v a 2 s . c om*/ FeeTransformResponseExtension.Builder feeResponseBuilder = getDeleteResponseBuilder(); if (feeResponseBuilder == null) { return ImmutableList.of(); } ImmutableList.Builder<Credit> creditsBuilder = new ImmutableList.Builder<>(); for (GracePeriod gracePeriod : existingDomain.getGracePeriods()) { if (gracePeriod.hasBillingEvent()) { Money cost = getGracePeriodCost(gracePeriod, now); creditsBuilder.add(Credit.create(cost.negated().getAmount(), FeeType.CREDIT, gracePeriod.getType().getXmlName())); feeResponseBuilder.setCurrency(checkNotNull(cost.getCurrencyUnit())); } } ImmutableList<Credit> credits = creditsBuilder.build(); if (credits.isEmpty()) { return ImmutableList.of(); } return ImmutableList.of(feeResponseBuilder.setCredits(credits).build()); }
From source file:com.wandoulabs.jodis.RoundRobinJedisPool.java
@Override public Jedis getResource() { ImmutableList<PooledObject> pools = this.pools; if (pools.isEmpty()) { throw new JedisException("Proxy list empty"); }/*from w w w.j a v a2s .c om*/ for (;;) { int current = nextIdx.get(); int next = current >= pools.size() - 1 ? 0 : current + 1; if (nextIdx.compareAndSet(current, next)) { return pools.get(next).pool.getResource(); } } }
From source file:com.facebook.buck.rules.Manifest.java
private boolean hashesMatch(FileHashCache fileHashCache, SourcePathResolver resolver, ImmutableListMultimap<String, SourcePath> universe, int[] hashIndices) throws IOException { for (int hashIndex : hashIndices) { Pair<Integer, HashCode> hashEntry = hashes.get(hashIndex); String header = headers.get(hashEntry.getFirst()); ImmutableList<SourcePath> candidates = universe.get(header); if (candidates.isEmpty()) { return false; }/*from ww w. j av a 2s. c o m*/ HashCode onDiskHeaderHash; try { onDiskHeaderHash = hashSourcePathGroup(fileHashCache, resolver, candidates); } catch (NoSuchFileException e) { return false; } HashCode headerHash = hashEntry.getSecond(); if (!headerHash.equals(onDiskHeaderHash)) { return false; } } return true; }
From source file:org.zanata.events.TextFlowTargetStateEvent.java
public TextFlowTargetStateEvent(DocumentLocaleKey key, Long projectIterationId, Long actorId, ImmutableList<TextFlowTargetStateChange> states) { this.key = key; this.projectIterationId = projectIterationId; this.actorId = actorId; this.states = states; Preconditions.checkArgument(!states.isEmpty(), "states is empty"); }
From source file:com.google.errorprone.bugpatterns.WildcardImport.java
@Override public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState state) { ImmutableList<ImportTree> wildcardImports = getWildcardImports(tree.getImports()); if (wildcardImports.isEmpty()) { return NO_MATCH; }/* ww w . j av a 2s .co m*/ // Find all of the types that need to be imported. Set<TypeToImport> typesToImport = ImportCollector.collect((JCCompilationUnit) tree); // Group the imported types by the on-demand import they replace. Multimap<ImportTree, TypeToImport> toFix = groupImports(wildcardImports, typesToImport); Fix fix = createFix(wildcardImports, toFix, state); if (fix.isEmpty()) { return NO_MATCH; } return describeMatch(wildcardImports.get(0), fix); }
From source file:com.iteblog.ElasticSearchOutputFormat.java
public void configure(Configuration configuration) { List<TransportAddress> transportNodes = new ArrayList<TransportAddress>(transportAddresses.size()); for (InetSocketAddress address : transportAddresses) { transportNodes.add(new InetSocketTransportAddress(address)); }/* w w w . j a v a2s. co m*/ Settings settings = Settings.settingsBuilder().put(userConfig).build(); TransportClient transportClient = TransportClient.builder().settings(settings).build(); for (TransportAddress transport : transportNodes) { transportClient.addTransportAddress(transport); } // verify that we actually are connected to a cluster ImmutableList<DiscoveryNode> nodes = ImmutableList.copyOf(transportClient.connectedNodes()); if (nodes.isEmpty()) { throw new RuntimeException("Client is not connected to any Elasticsearch nodes!"); } client = transportClient; if (LOG.isInfoEnabled()) { LOG.info("Created Elasticsearch TransportClient {}", client); } BulkProcessor.Builder bulkProcessorBuilder = BulkProcessor.builder(client, new BulkProcessor.Listener() { public void beforeBulk(long executionId, BulkRequest request) { } public void afterBulk(long executionId, BulkRequest request, BulkResponse response) { if (response.hasFailures()) { for (BulkItemResponse itemResp : response.getItems()) { if (itemResp.isFailed()) { LOG.error("Failed to index document in Elasticsearch: " + itemResp.getFailureMessage()); failureThrowable.compareAndSet(null, new RuntimeException(itemResp.getFailureMessage())); } } hasFailure.set(true); } } public void afterBulk(long executionId, BulkRequest request, Throwable failure) { LOG.error(failure.getMessage()); failureThrowable.compareAndSet(null, failure); hasFailure.set(true); } }); // This makes flush() blocking bulkProcessorBuilder.setConcurrentRequests(0); if (userConfig.containsKey(CONFIG_KEY_BULK_FLUSH_MAX_ACTIONS)) { bulkProcessorBuilder.setBulkActions(stringToInt(userConfig.get(CONFIG_KEY_BULK_FLUSH_MAX_ACTIONS))); } if (userConfig.containsKey(CONFIG_KEY_BULK_FLUSH_MAX_SIZE_MB)) { bulkProcessorBuilder.setBulkSize( new ByteSizeValue(stringToInt(CONFIG_KEY_BULK_FLUSH_MAX_SIZE_MB), ByteSizeUnit.MB)); } if (userConfig.containsKey(CONFIG_KEY_BULK_FLUSH_INTERVAL_MS)) { bulkProcessorBuilder .setFlushInterval(TimeValue.timeValueMillis(stringToInt(CONFIG_KEY_BULK_FLUSH_INTERVAL_MS))); } bulkProcessor = bulkProcessorBuilder.build(); requestIndexer = new BulkProcessorIndexer(bulkProcessor); }
From source file:google.registry.flows.async.RefreshDnsOnHostRenameAction.java
@Override public void run() { LeaseOptions options = LeaseOptions.Builder.withCountLimit(maxLeaseCount()).leasePeriod(LEASE_MINUTES, MINUTES);/*from ww w . j a va 2 s . c o m*/ List<TaskHandle> tasks = pullQueue.leaseTasks(options); if (tasks.isEmpty()) { response.setPayload("No DNS refresh on host rename tasks to process in pull queue."); return; } ImmutableList.Builder<DnsRefreshRequest> requestsBuilder = new ImmutableList.Builder<>(); ImmutableList.Builder<Key<HostResource>> hostKeys = new ImmutableList.Builder<>(); final List<TaskHandle> tasksToDelete = new ArrayList<>(); for (TaskHandle task : tasks) { try { Optional<DnsRefreshRequest> request = DnsRefreshRequest.createFromTask(task, clock.nowUtc()); if (request.isPresent()) { requestsBuilder.add(request.get()); hostKeys.add(request.get().hostKey()); } else { // Skip hosts that are deleted. tasksToDelete.add(task); } } catch (Exception e) { logger.severefmt(e, "Could not parse DNS refresh for host request, delaying task for a day: %s", task); // Grab the lease for a whole day, so it won't continue throwing errors every five minutes. pullQueue.modifyTaskLease(task, 1L, DAYS); } } deleteTasksWithRetry(tasksToDelete, pullQueue, retrier); ImmutableList<DnsRefreshRequest> refreshRequests = requestsBuilder.build(); if (refreshRequests.isEmpty()) { logger.info("No asynchronous DNS refreshes to process because all renamed hosts are deleted."); response.setPayload("All requested DNS refreshes are on hosts that were since deleted."); } else { logger.infofmt("Processing asynchronous DNS refresh for renamed hosts: %s", hostKeys.build()); runMapreduce(refreshRequests, tasks); } }
From source file:com.facebook.buck.cli.VerifyCachesCommand.java
private boolean verifyRuleKeyCache(CellProvider cellProvider, PrintStream stdOut, RuleKeyConfiguration ruleKeyConfiguration, FileHashCache fileHashCache, RuleKeyCacheRecycler<RuleKey> recycler) { ImmutableList<Map.Entry<BuildRule, RuleKey>> contents = recycler.getCachedBuildRules(); RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(ruleKeyConfiguration); ActionGraphBuilder graphBuilder = new SingleThreadedActionGraphBuilder(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer(), cellProvider); contents.forEach(e -> graphBuilder.addToIndex(e.getKey())); SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(graphBuilder); SourcePathResolver pathResolver = DefaultSourcePathResolver.from(ruleFinder); DefaultRuleKeyFactory defaultRuleKeyFactory = new DefaultRuleKeyFactory(fieldLoader, fileHashCache, pathResolver, ruleFinder);//from w w w .j a va2s . c o m stdOut.println(String.format("Examining %d build rule keys.", contents.size())); ImmutableList<BuildRule> mismatches = RichStream.from(contents) .filter(entry -> !defaultRuleKeyFactory.build(entry.getKey()).equals(entry.getValue())) .map(Map.Entry::getKey).toImmutableList(); if (mismatches.isEmpty()) { stdOut.println("No rule key cache errors found."); } else { stdOut.println("Found rule key cache errors:"); for (BuildRule rule : mismatches) { stdOut.println(String.format(" %s", rule)); } } return true; }
From source file:de.metas.ui.web.window.datatypes.LookupValuesList.java
/** * @param id/*from w w w . ja v a 2s . c o m*/ * @return first lookup value found for <code>id</code> or null */ public LookupValue getById(final Object id) { final ImmutableList<LookupValue> values = valuesById.get(id); return values.isEmpty() ? null : values.get(0); }
From source file:com.android.common.ide.common.blame.Message.java
public Message(@NonNull Kind kind, @NonNull String text, @NonNull String rawMessage, @NonNull Optional<String> toolName, @NonNull ImmutableList<SourceFilePosition> positions) { mKind = kind;//from ww w .j av a2 s .c om mText = text; mRawMessage = rawMessage; mToolName = toolName; if (positions.isEmpty()) { mSourceFilePositions = ImmutableList.of(SourceFilePosition.UNKNOWN); } else { mSourceFilePositions = positions; } }