List of usage examples for com.google.common.collect ImmutableMap isEmpty
@Override public boolean isEmpty()
From source file:com.google.errorprone.bugpatterns.InconsistentCapitalization.java
@Override public Description matchClass(ClassTree tree, VisitorState state) { ImmutableSet<Symbol> fields = FieldScanner.findFields(tree); if (fields.isEmpty()) { return Description.NO_MATCH; }/*from w ww.j ava2 s .c om*/ ImmutableMap<String, Symbol> fieldNamesMap = fields.stream() .collect(toImmutableMap(symbol -> Ascii.toLowerCase(symbol.toString()), x -> x, (x, y) -> x)); ImmutableMap<TreePath, Symbol> matchedParameters = MatchingParametersScanner .findMatchingParameters(fieldNamesMap, state.getPath()); if (matchedParameters.isEmpty()) { return Description.NO_MATCH; } for (Entry<TreePath, Symbol> entry : matchedParameters.entrySet()) { TreePath parameterPath = entry.getKey(); Symbol field = entry.getValue(); String fieldName = field.getSimpleName().toString(); VariableTree parameterTree = (VariableTree) parameterPath.getLeaf(); SuggestedFix.Builder fix = SuggestedFix.builder() .merge(SuggestedFixes.renameVariable(parameterTree, fieldName, state)); if (parameterPath.getParentPath() != null) { String qualifiedName = getExplicitQualification(parameterPath, tree, state) + field.getSimpleName(); // If the field was accessed in a non-qualified way, by renaming the parameter this may // cause clashes with it. Thus, it is required to qualify all uses of the field within the // parameter's scope just in case. parameterPath.getParentPath().getLeaf().accept(new TreeScanner<Void, Void>() { @Override public Void visitIdentifier(IdentifierTree tree, Void unused) { if (field.equals(ASTHelpers.getSymbol(tree))) { fix.replace(tree, qualifiedName); } return null; } }, null); } state.reportMatch( buildDescription(parameterPath.getLeaf()) .setMessage(String.format( "Found the field '%s' with the same name as the parameter '%s' but with " + "different capitalization.", fieldName, ((VariableTree) parameterPath.getLeaf()).getName())) .addFix(fix.build()).build()); } return Description.NO_MATCH; }
From source file:org.elasticsearch.action.admin.indices.mapping.get.TransportGetFieldMappingsIndexAction.java
@Override protected GetFieldMappingsResponse shardOperation(final GetFieldMappingsIndexRequest request, int shardId) throws ElasticsearchException { IndexService indexService = indicesService.indexServiceSafe(request.index()); Collection<String> typeIntersection; if (request.types().length == 0) { typeIntersection = indexService.mapperService().types(); } else {//w w w .ja va 2 s. co m typeIntersection = Collections2.filter(indexService.mapperService().types(), new Predicate<String>() { @Override public boolean apply(String type) { return Regex.simpleMatch(request.types(), type); } }); if (typeIntersection.isEmpty()) { throw new TypeMissingException(new Index(request.index()), request.types()); } } MapBuilder<String, ImmutableMap<String, FieldMappingMetaData>> typeMappings = new MapBuilder<>(); for (String type : typeIntersection) { DocumentMapper documentMapper = indexService.mapperService().documentMapper(type); ImmutableMap<String, FieldMappingMetaData> fieldMapping = findFieldMappingsByType(documentMapper, request); if (!fieldMapping.isEmpty()) { typeMappings.put(type, fieldMapping); } } return new GetFieldMappingsResponse(ImmutableMap.of(request.index(), typeMappings.immutableMap())); }
From source file:org.waveprotocol.box.server.frontend.FragmentsFetcher.java
@Timed void fetchOptionalFragments(final FragmentsBuffer buffer, Map<SegmentId, VersionRange> ranges, int minReplySize, int maxReplySize) throws WaveServerException { Preconditions.checkArgument(!ranges.isEmpty(), "Ranges are empty"); // First request try to make minimal reply. FragmentsRequest firstRequest = new FragmentsRequest.Builder().addRanges(ranges) .setMaxReplySize(minReplySize).build(); fetchFragmentsRequest(buffer, firstRequest); Set<SegmentId> receivedSegmentIds = buffer.getIntervals().keySet(); ImmutableMap.Builder<SegmentId, VersionRange> optionalRangesBuilder = ImmutableMap.builder(); for (SegmentId segmentId : ranges.keySet()) { if (!receivedSegmentIds.contains(segmentId)) { optionalRangesBuilder.put(segmentId, ranges.get(segmentId)); }// w w w . j a v a 2s . c o m } ImmutableMap<SegmentId, VersionRange> optionalRanges = optionalRangesBuilder.build(); if (!optionalRanges.isEmpty()) { // Second request try to build maximal reply from cache. FragmentsRequest secondRequest = new FragmentsRequest.Builder().addRanges(optionalRanges) .setOnlyFromCache(true).setMaxReplySize(maxReplySize).build(); fetchFragmentsRequest(buffer, secondRequest); } }
From source file:com.squareup.wire.schema.Options.java
/** Returns an object of the same type as {@code o}, or null if it is not retained. */ private Object retainAll(Schema schema, MarkSet markSet, ProtoType type, Object o) { if (!markSet.contains(type)) { return null; // Prune this type. } else if (o instanceof Map) { ImmutableMap.Builder<ProtoMember, Object> builder = ImmutableMap.builder(); for (Map.Entry<?, ?> entry : ((Map<?, ?>) o).entrySet()) { ProtoMember protoMember = (ProtoMember) entry.getKey(); if (!markSet.contains(protoMember)) continue; // Prune this field. Field field = schema.getField(protoMember); Object retainedValue = retainAll(schema, markSet, field.type(), entry.getValue()); if (retainedValue != null) { builder.put(protoMember, retainedValue); // This retained field is non-empty. }//w ww . j av a 2s .c o m } ImmutableMap<ProtoMember, Object> map = builder.build(); return !map.isEmpty() ? map : null; } else if (o instanceof List) { ImmutableList.Builder<Object> builder = ImmutableList.builder(); for (Object value : ((List) o)) { Object retainedValue = retainAll(schema, markSet, type, value); if (retainedValue != null) { builder.add(retainedValue); // This retained value is non-empty. } } ImmutableList<Object> list = builder.build(); return !list.isEmpty() ? list : null; } else { return o; } }
From source file:org.spongepowered.common.mixin.core.block.state.MixinIBlockState.java
@SuppressWarnings("unchecked") @Override//from w ww.j ava2 s. c om default String getId() { StringBuilder builder = new StringBuilder(); builder.append(((BlockType) getBlock()).getId()); final ImmutableMap<IProperty<?>, Comparable<?>> properties = (ImmutableMap<IProperty<?>, Comparable<?>>) (ImmutableMap<?, ?>) this .getProperties(); if (!properties.isEmpty()) { builder.append('['); Joiner joiner = Joiner.on(','); List<String> propertyValues = new ArrayList<>(); for (Map.Entry<IProperty<?>, Comparable<?>> entry : properties.entrySet()) { propertyValues.add(entry.getKey().getName() + "=" + entry.getValue()); } builder.append(joiner.join(propertyValues)); builder.append(']'); } return builder.toString(); }
From source file:org.openqa.selenium.remote.session.SafariFilter.java
@Override public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) { ImmutableMap<String, Object> caps = unmodifiedCaps.entrySet().parallelStream() .filter(entry -> ("browserName".equals(entry.getKey()) && "safari".equals(entry.getValue())) || "safari.options".equals(entry.getKey())) .distinct().filter(entry -> Objects.nonNull(entry.getValue())) .collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)); return caps.isEmpty() ? null : caps; }
From source file:com.google.devtools.build.android.desugar.Desugar.java
private void desugarOneInput(InputOutputPair inputOutputPair, IndexedInputs indexedClasspath, ClassLoader bootclassloader) throws Exception { Path inputPath = inputOutputPair.getInput(); Path outputPath = inputOutputPair.getOutput(); checkArgument(Files.isDirectory(inputPath) || !Files.isDirectory(outputPath), "Input jar file requires an output jar file"); try (OutputFileProvider outputFileProvider = toOutputFileProvider(outputPath); InputFileProvider inputFiles = toInputFileProvider(inputPath)) { IndexedInputs indexedInputFiles = new IndexedInputs(ImmutableList.of(inputFiles)); // Prepend classpath with input file itself so LambdaDesugaring can load classes with // lambdas. IndexedInputs indexedClasspathAndInputFiles = indexedClasspath.withParent(indexedInputFiles); // Note that input file and classpath need to be in the same classloader because // we typically get the header Jar for inputJar on the classpath and having the header // Jar in a parent loader means the header version is preferred over the real thing. ClassLoader loader = new HeaderClassLoader(indexedClasspathAndInputFiles, rewriter, bootclassloader); ClassReaderFactory readerFactory = new ClassReaderFactory( (options.copyBridgesFromClasspath && !allowDefaultMethods) ? indexedClasspathAndInputFiles : indexedInputFiles, rewriter);/* w w w .j a va2 s .c om*/ ImmutableSet.Builder<String> interfaceLambdaMethodCollector = ImmutableSet.builder(); desugarClassesInInput(inputFiles, outputFileProvider, loader, readerFactory, interfaceLambdaMethodCollector); desugarAndWriteDumpedLambdaClassesToOutput(outputFileProvider, loader, readerFactory, interfaceLambdaMethodCollector); } ImmutableMap<Path, LambdaInfo> leftBehind = lambdas.drain(); checkState(leftBehind.isEmpty(), "Didn't process %s", leftBehind); }
From source file:com.facebook.buck.core.config.BuckConfig.java
public Optional<ImmutableMap<String, String>> getSection(String sectionName) { ImmutableMap<String, String> values = config.get(sectionName); return values.isEmpty() ? Optional.empty() : Optional.of(values); }
From source file:com.google.devtools.build.lib.skylarkdebug.server.ThreadHandler.java
/** * Returns true if there's a breakpoint at the current location, with a satisfied condition if * relevant.// ww w . j a va 2 s .c o m */ private boolean hasBreakpointMatchedAtLocation(Environment env, Location location) throws ConditionalBreakpointException { // breakpoints is volatile, so taking a local copy ImmutableMap<SkylarkDebuggingProtos.Location, SkylarkDebuggingProtos.Breakpoint> breakpoints = this.breakpoints; if (breakpoints.isEmpty()) { return false; } SkylarkDebuggingProtos.Location locationProto = DebugEventHelper.getLocationProto(location); if (locationProto == null) { return false; } locationProto = locationProto.toBuilder().clearColumnNumber().build(); SkylarkDebuggingProtos.Breakpoint breakpoint = breakpoints.get(locationProto); if (breakpoint == null) { return false; } String condition = breakpoint.getExpression(); if (condition.isEmpty()) { return true; } try { return EvalUtils.toBoolean(doEvaluate(env, condition)); } catch (EvalException | InterruptedException e) { throw new ConditionalBreakpointException(e.getMessage()); } }
From source file:com.facebook.buck.rules.modern.builders.MultiThreadedBlobUploader.java
/** Uploads missing items to the CAS. */ public void addMissing(ImmutableMap<Protocol.Digest, ThrowingSupplier<InputStream, IOException>> data) throws IOException { try {/*from w ww . j a v a 2s . c o m*/ data = ImmutableMap.copyOf(Maps.filterKeys(data, k -> !containedHashes.contains(k.getHash()))); if (data.isEmpty()) { return; } enqueue(data).get(); } catch (InterruptedException | ExecutionException e) { throw new IOException(e); } }