List of usage examples for com.google.common.collect ImmutableSet isEmpty
boolean isEmpty();
From source file:org.elasticsearch.search.facet.terms.strings.FieldsTermsStringFacetExecutor.java
public FieldsTermsStringFacetExecutor(FieldMapper[] fieldMappers, int size, int shardSize, InternalStringTermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context, ImmutableSet<BytesRef> excluded, Pattern pattern, SearchScript script) { this.size = size; this.shardSize = shardSize; this.comparatorType = comparatorType; this.script = script; this.indexFieldDatas = new IndexFieldData[fieldMappers.length]; for (int i = 0; i < fieldMappers.length; i++) { FieldMapper mapper = fieldMappers[i]; indexFieldDatas[i] = context.fieldData().getForField(mapper); }/*from ww w. ja v a 2 s.c o m*/ if (excluded.isEmpty() && pattern == null && script == null) { aggregator = new HashedAggregator(); } else { aggregator = new HashedScriptAggregator(excluded, pattern, script); } if (allTerms) { for (int i = 0; i < fieldMappers.length; i++) { TermsStringFacetExecutor.loadAllTerms(context, indexFieldDatas[i], aggregator); } } }
From source file:org.spongepowered.common.data.property.store.item.HarvestingPropertyStore.java
@SuppressWarnings("unchecked") @Override/*www. j a v a 2 s . c o m*/ protected Optional<HarvestingProperty> getFor(ItemStack itemStack) { final Item item = itemStack.getItem(); if (item instanceof ItemTool) { final ImmutableSet<BlockType> blocks = ImmutableSet.copyOf((Set) ((ItemTool) item).effectiveBlocks); return Optional.of(new HarvestingProperty(blocks)); } else { final Collection<BlockType> blockTypes = SpongeImpl.getRegistry().getAllOf(BlockType.class); final ImmutableSet.Builder<BlockType> builder = ImmutableSet.builder(); blockTypes.stream().filter(blockType -> item.canHarvestBlock((Block) blockType)).forEach(builder::add); final ImmutableSet<BlockType> blocks = builder.build(); if (blocks.isEmpty()) { return Optional.empty(); } else { return Optional.of(new HarvestingProperty(blocks)); } } }
From source file:org.elasticsearch.search.facet.terms.strings.TermsStringOrdinalsFacetExecutor.java
public TermsStringOrdinalsFacetExecutor(IndexFieldData.WithOrdinals indexFieldData, int size, int shardSize, TermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context, ImmutableSet<BytesRef> excluded, Pattern pattern, int ordinalsCacheAbove) { this.indexFieldData = indexFieldData; this.size = size; this.shardSize = shardSize; this.comparatorType = comparatorType; this.ordinalsCacheAbove = ordinalsCacheAbove; if (excluded == null || excluded.isEmpty()) { this.excluded = null; } else {//from w ww. ja v a2 s . c o m this.excluded = excluded; } this.matcher = pattern != null ? pattern.matcher("") : null; // minCount is offset by -1 if (allTerms) { minCount = -1; } else { minCount = 0; } this.cacheRecycler = context.cacheRecycler(); this.bigArrays = context.bigArrays(); this.aggregators = new ArrayList<>(context.searcher().getIndexReader().leaves().size()); }
From source file:de.metas.ui.web.attachments.DocumentAttachments.java
/** * If the document contains some attachment related tabs, it will send an "stale" notification to frontend. * In this way, frontend will be aware of this and will have to refresh the tab. */// w ww.j ava 2 s . c o m private void notifyRelatedDocumentTabsChanged() { final ImmutableSet<DetailId> attachmentRelatedTabIds = entityDescriptor.getIncludedEntities().stream() .filter(includedEntityDescriptor -> Objects.equals(includedEntityDescriptor.getTableNameOrNull(), I_AD_AttachmentEntry.Table_Name)) .map(includedEntityDescriptor -> includedEntityDescriptor.getDetailId()) .collect(ImmutableSet.toImmutableSet()); if (attachmentRelatedTabIds.isEmpty()) { return; } websocketPublisher.staleTabs(documentPath.getWindowId(), documentPath.getDocumentId(), attachmentRelatedTabIds); }
From source file:org.apache.thrift.maven.AbstractThriftMojo.java
/** * Executes the mojo.//from w w w. j a va 2s . c o m */ public void execute() throws MojoExecutionException, MojoFailureException { checkParameters(); final File thriftSourceRoot = getThriftSourceRoot(); if (thriftSourceRoot.exists()) { try { ImmutableSet<File> thriftFiles = findThriftFilesInDirectory(thriftSourceRoot); final File outputDirectory = getOutputDirectory(); ImmutableSet<File> outputFiles = findGeneratedFilesInDirectory(getOutputDirectory()); if (thriftFiles.isEmpty()) { getLog().info("No thrift files to compile."); } else if (checkStaleness && ((lastModified(thriftFiles) + staleMillis) < lastModified(outputFiles))) { getLog().info("Skipping compilation because target directory newer than sources."); attachFiles(); } else { ImmutableSet<File> derivedThriftPathElements = makeThriftPathFromJars( temporaryThriftFileDirectory, getDependencyArtifactFiles()); outputDirectory.mkdirs(); // Quick fix to fix issues with two mvn installs in a row (ie no clean) // cleanDirectory(outputDirectory); Thrift thrift = new Thrift.Builder(thriftExecutable, outputDirectory).setGenerator(generator) .addThriftPathElement(thriftSourceRoot).addThriftPathElements(derivedThriftPathElements) .addThriftPathElements(asList(additionalThriftPathElements)).addThriftFiles(thriftFiles) .build(); final int exitStatus = thrift.compile(); if (exitStatus != 0) { getLog().error("thrift failed output: " + thrift.getOutput()); getLog().error("thrift failed error: " + thrift.getError()); throw new MojoFailureException( "thrift did not exit cleanly. Review output for more information."); } attachFiles(); } } catch (IOException e) { throw new MojoExecutionException("An IO error occurred", e); } catch (IllegalArgumentException e) { throw new MojoFailureException("thrift failed to execute because: " + e.getMessage(), e); } catch (CommandLineException e) { throw new MojoExecutionException("An error occurred while invoking thrift.", e); } } else { getLog().info(format("%s does not exist. Review the configuration or consider disabling the plugin.", thriftSourceRoot)); } }
From source file:net.caseif.flint.common.arena.CommonArena.java
@Override public Round createRound() throws IllegalStateException, OrphanedComponentException { checkState();//from w ww. j a v a2s . c om Preconditions.checkState(!getRound().isPresent(), "Cannot create a round in an arena already hosting one"); ImmutableSet<LifecycleStage> stages = getMinigame().getConfigValue(ConfigNode.DEFAULT_LIFECYCLE_STAGES); Preconditions.checkState(stages != null && !stages.isEmpty(), "Illegal call to nullary createRound method: default lifecycle stages are not set"); return createRound(getMinigame().getConfigValue(ConfigNode.DEFAULT_LIFECYCLE_STAGES)); }
From source file:com.google.devtools.build.lib.remote.GrpcActionCache.java
/** Upload all results of a locally executed action to the cache. */ @Override/*from w w w.j a v a 2 s . c om*/ public void uploadAllResults(Path execRoot, Collection<Path> files, ActionResult.Builder result) throws IOException, InterruptedException { ArrayList<ContentDigest> digests = new ArrayList<>(); for (Path file : files) { digests.add(ContentDigests.computeDigest(file)); } ImmutableSet<ContentDigest> missing = getMissingDigests(digests); if (!missing.isEmpty()) { uploadChunks(missing.size(), new BlobChunkFileIterator(missing, files.iterator())); } int index = 0; for (Path file : files) { if (file.isDirectory()) { // TODO(olaola): to implement this for a directory, will need to create or pass a // TreeNodeRepository to call uploadTree. throw new UnsupportedOperationException("Storing a directory is not yet supported."); } // Add to protobuf. result.addOutputBuilder().setPath(file.relativeTo(execRoot).getPathString()).getFileMetadataBuilder() .setDigest(digests.get(index++)).setExecutable(file.isExecutable()); } }
From source file:com.google.devtools.build.lib.remote.GrpcActionCache.java
/** * Put the file contents cache if it is not already in it. No-op if the file is already stored in * cache. The given path must be a full absolute path. Note: this is horribly inefficient, need to * patch through an overload that uses an ActionInputFile cache to compute the digests! * * @return The key for fetching the file contents blob from cache. *//*from w ww. ja va 2s . c o m*/ @Override public ContentDigest uploadFileContents(Path file) throws IOException, InterruptedException { ContentDigest digest = ContentDigests.computeDigest(file); ImmutableSet<ContentDigest> missing = getMissingDigests(ImmutableList.of(digest)); if (!missing.isEmpty()) { uploadChunks(1, new BlobChunkFileIterator(file)); } return digest; }
From source file:grakn.core.graql.reasoner.query.ReasonerQueryImpl.java
@Override public Type getUnambiguousType(Variable var, boolean inferTypes) { ImmutableSet<Type> types = getVarTypeMap(inferTypes).get(var); Type type = null;/* w w w .ja va 2 s . co m*/ if (types.isEmpty()) return type; try { type = Iterables.getOnlyElement(types); } catch (IllegalArgumentException e) { throw GraqlQueryException.ambiguousType(var, types); } return type; }
From source file:com.google.devtools.build.lib.remote.GrpcActionCache.java
@Override public ImmutableList<ContentDigest> uploadBlobs(Iterable<byte[]> blobs) throws InterruptedException { ArrayList<ContentDigest> digests = new ArrayList<>(); for (byte[] blob : blobs) { digests.add(ContentDigests.computeDigest(blob)); }// www . j a v a 2s .c o m ImmutableSet<ContentDigest> missing = getMissingDigests(digests); try { if (!missing.isEmpty()) { uploadChunks(missing.size(), new BlobChunkInlineIterator(missing, blobs.iterator())); } return ImmutableList.copyOf(digests); } catch (IOException e) { // This will never happen. throw new RuntimeException(e); } }