List of usage examples for com.google.common.collect FluentIterable of
@Beta @CheckReturnValue @Deprecated public static <E> FluentIterable<E> of(E[] elements)
From source file:dagger.internal.codegen.ComponentRequirementFields.java
/** * Returns a new object representing the fields available from a child component of this one. *///from w w w .j av a2 s . com ComponentRequirementFields forChildComponent() { return new ComponentRequirementFields( FluentIterable.of(newComponentRequirementsMap()).append(componentRequirementFieldsMaps).toList()); }
From source file:com.gwtplatform.mvp.processors.proxy.ProxyPlaceDetails.java
private void extractGatekeeperParams() { GatekeeperParams annotation = element.getAnnotation(GatekeeperParams.class); gatekeeperParams = new ArrayList<>(); if (annotation != null && verifyIsGatekeeperWithParams()) { FluentIterable.of(annotation.value()) .transform(param -> param.replace("\\", "\\\\").replace("\"", "\\\"")) .copyInto(gatekeeperParams); }/* w w w .j a v a 2 s .c o m*/ }
From source file:com.google.api.codegen.csharp.CSharpDiscoveryContext.java
public Iterable<String> sortUsings(Iterable<String> usings) { Predicate<String> isAlias = new Predicate<String>() { @Override/*from w ww . j a v a 2 s . co m*/ public boolean apply(String using) { return using.contains("="); } }; FluentIterable<String> fluentUsings = FluentIterable.from(usings).transform(new Function<String, String>() { @Override public String apply(String using) { return "using " + using + ";"; } }); Iterable<String> aliases = fluentUsings.anyMatch(isAlias) ? FluentIterable.of(new String[] { "" }).append(fluentUsings.filter(isAlias)) : Collections.<String>emptyList(); return fluentUsings.filter(Predicates.<String>not(isAlias)).append(aliases); }
From source file:com.facebook.buck.go.GoDescriptors.java
@VisibleForTesting static ImmutableMap<Path, Path> getPackageImportMap(ImmutableList<Path> globalVendorPaths, Path basePackagePath, Iterable<Path> packageNameIter) { Map<Path, Path> importMapBuilder = Maps.newHashMap(); ImmutableSortedSet<Path> packageNames = ImmutableSortedSet.copyOf(packageNameIter); ImmutableList.Builder<Path> vendorPathsBuilder = ImmutableList.builder(); vendorPathsBuilder.addAll(globalVendorPaths); Path prefix = Paths.get(""); for (Path component : FluentIterable.of(new Path[] { Paths.get("") }).append(basePackagePath)) { prefix = prefix.resolve(component); vendorPathsBuilder.add(prefix.resolve("vendor")); }/*ww w .j a v a 2 s .c om*/ for (Path vendorPrefix : vendorPathsBuilder.build()) { for (Path vendoredPackage : packageNames.tailSet(vendorPrefix)) { if (!vendoredPackage.startsWith(vendorPrefix)) { break; } importMapBuilder.put(MorePaths.relativize(vendorPrefix, vendoredPackage), vendoredPackage); } } return ImmutableMap.copyOf(importMapBuilder); }
From source file:com.github.lukaszbudnik.gugis.GugisModule.java
private List<String> getMethodsMarkedWithPropagation(final Class<?> compositeClass, final Propagation propagation) { return FluentIterable.of(compositeClass.getMethods()).filter(new Predicate<Method>() { @Override//www . j a v a 2 s .com public boolean apply(Method input) { Propagate propagate = input.getAnnotation(Propagate.class); if (propagate == null) { return false; } return propagate.propagation() == propagation; } }).transform(new Function<Method, String>() { @Override public String apply(Method input) { return input.toString().replace(compositeClass.getCanonicalName() + ".", ""); } }).toList(); }
From source file:org.parceler.internal.ParcelableAnalysis.java
private ParcelableDescriptor innerAnalyze(ASTType astType, ASTAnnotation parcelASTAnnotation) { ASTType converter = getConverterType(parcelASTAnnotation); Parcel.Serialization serialization = parcelASTAnnotation != null ? parcelASTAnnotation.getProperty("value", Parcel.Serialization.class) : null;/* w w w .j ava 2 s . c o m*/ ASTType[] interfaces = parcelASTAnnotation != null ? parcelASTAnnotation.getProperty("implementations", ASTType[].class) : new ASTType[0]; ASTType[] analyze = parcelASTAnnotation != null ? parcelASTAnnotation.getProperty("analyze", ASTType[].class) : new ASTType[0]; ParcelableDescriptor parcelableDescriptor; if (converter != null) { parcelableDescriptor = new ParcelableDescriptor(interfaces, converter); } else { parcelableDescriptor = new ParcelableDescriptor(interfaces); Set<MethodSignature> definedMethods = new HashSet<MethodSignature>(); Map<String, ASTReference<ASTParameter>> writeParameters = new HashMap<String, ASTReference<ASTParameter>>(); Set<ASTConstructor> constructors = findConstructors(astType, true); Set<ASTMethod> factoryMethods = findFactoryMethods(astType); ConstructorReference constructorReference = null; if (!astType.isStatic() && astType.isInnerClass()) { validator.error("Inner Classes annotated with @Parcel must be static.").element(astType).build(); } if (!factoryMethods.isEmpty() && !findConstructors(astType, false).isEmpty()) { validator .error("Both @ParcelConstructor and @ParcelFactory may not be annotated on the same class.") .element(astType).build(); } else if (factoryMethods.size() == 1) { ASTMethod factoryMethod = factoryMethods.iterator().next(); if (!factoryMethod.isStatic()) { validator.error("@ParcelFactory method must be static").element(factoryMethod).build(); } else { writeParameters.putAll(findMethodParameters(factoryMethod)); constructorReference = new ConstructorReference(factoryMethods.iterator().next()); parcelableDescriptor.setConstructorPair(constructorReference); } } else if (factoryMethods.size() > 1) { validator.error("Too many @ParcelFactory annotated factory methods.").element(astType).build(); } else if (constructors.size() == 1) { writeParameters.putAll(findConstructorParameters(constructors.iterator().next())); constructorReference = new ConstructorReference(constructors.iterator().next()); parcelableDescriptor.setConstructorPair(constructorReference); } else if (constructors.size() == 0) { validator.error( "No @ParcelConstructor annotated constructor and no default empty bean constructor found.") .element(astType).build(); } else { validator.error("Too many @ParcelConstructor annotated constructors found.").element(astType) .build(); } ImmutableSet<ASTType> analyzeSet; if (analyze == null) { analyzeSet = ImmutableSet.of(); } else { analyzeSet = FluentIterable.of(analyze).toSet(); } Iterator<ASTType> typeIterator = new ASTTypeHierarchyIterator(astType, analyzeSet); while (typeIterator.hasNext()) { ASTType hierarchyLoop = typeIterator.next(); HashMultimap<String, ASTReference<ASTMethod>> defaultWriteMethods = HashMultimap.create(); HashMultimap<String, ASTReference<ASTMethod>> defaultReadMethods = HashMultimap.create(); HashMultimap<String, ASTReference<ASTField>> defaultFields = HashMultimap.create(); if (Parcel.Serialization.BEAN.equals(serialization)) { defaultWriteMethods.putAll(findJavaBeanWriteMethods(hierarchyLoop, definedMethods, false)); defaultReadMethods.putAll(findJavaBeanReadMethods(hierarchyLoop, definedMethods, false)); } else if (Parcel.Serialization.VALUE.equals(serialization)) { defaultWriteMethods.putAll(findValueWriteMethods(hierarchyLoop, definedMethods, false)); defaultReadMethods.putAll(findValueReadMethods(hierarchyLoop, definedMethods, false)); } else { defaultFields.putAll(findFields(hierarchyLoop, false)); } parcelableDescriptor.getWrapCallbacks() .addAll(findCallbacks(hierarchyLoop, definedMethods, OnWrap.class)); parcelableDescriptor.getUnwrapCallbacks() .addAll(findCallbacks(hierarchyLoop, definedMethods, OnUnwrap.class)); for (ASTMethod wrapCallbackMethod : parcelableDescriptor.getWrapCallbacks()) { if (!wrapCallbackMethod.getReturnType().equals(ASTVoidType.VOID)) { validator.error("@OnWrap annotated methods must return void.").element(wrapCallbackMethod) .build(); } if (!wrapCallbackMethod.getParameters().isEmpty()) { validator.error("@OnWrap annotated methods must have no method parameters.") .element(wrapCallbackMethod).build(); } } for (ASTMethod unwrapCallbackMethod : parcelableDescriptor.getUnwrapCallbacks()) { if (!unwrapCallbackMethod.getReturnType().equals(ASTVoidType.VOID)) { validator.error("@OnUnwrap annotated methods must return void.") .element(unwrapCallbackMethod).build(); } if (!unwrapCallbackMethod.getParameters().isEmpty()) { validator.error("@OnUnwrap annotated methods must have no method parameters.") .element(unwrapCallbackMethod).build(); } } HashMultimap<String, ASTReference<ASTMethod>> propertyWriteMethods = findJavaBeanWriteMethods( hierarchyLoop, definedMethods, true); HashMultimap<String, ASTReference<ASTMethod>> propertyReadMethods = findJavaBeanReadMethods( hierarchyLoop, definedMethods, true); HashMultimap<String, ASTReference<ASTField>> propertyFields = findFields(hierarchyLoop, true); //check for > 1 properties HashMultimap<String, ASTReference<ASTMethod>> writeCombination = combine(defaultWriteMethods, propertyWriteMethods); HashMultimap<String, ASTReference<ASTMethod>> readCombination = combine(defaultReadMethods, propertyReadMethods); HashMultimap<String, ASTReference<ASTField>> fieldCombination = combine(defaultFields, propertyFields); validateSingleProperty(writeCombination); validateSingleProperty(readCombination); validateSingleProperty(fieldCombination); validateConverters(combine(readCombination, writeCombination), fieldCombination, writeParameters); Map<String, AccessibleReference> readReferences = new HashMap<String, AccessibleReference>(); Map<String, FieldReference> fieldWriteReferences = new HashMap<String, FieldReference>(); Map<String, MethodReference> methodWriteReferences = new HashMap<String, MethodReference>(); Map<String, ASTType> converters = new HashMap<String, ASTType>(); for (String methodKey : defaultReadMethods.keys()) { ASTReference<ASTMethod> methodASTReference = defaultReadMethods.get(methodKey).iterator() .next(); readReferences.put(methodKey, new MethodReference(astType, hierarchyLoop, methodKey, methodASTReference.getReference().getReturnType(), methodASTReference.getReference())); if (methodASTReference.getConverter() != null) { converters.put(methodKey, methodASTReference.getConverter()); } } //overwrite with field accessor for (String fieldKey : defaultFields.keys()) { ASTReference<ASTField> fieldASTReference = defaultFields.get(fieldKey).iterator().next(); readReferences.put(fieldKey, new FieldReference(hierarchyLoop, fieldKey, fieldASTReference.getReference())); fieldWriteReferences.put(fieldKey, new FieldReference(hierarchyLoop, fieldKey, fieldASTReference.getReference())); if (fieldASTReference.getConverter() != null) { converters.put(fieldKey, fieldASTReference.getConverter()); } } //overwrite with property methods for (String methodKey : propertyReadMethods.keys()) { ASTReference<ASTMethod> methodASTReference = propertyReadMethods.get(methodKey).iterator() .next(); readReferences.put(methodKey, new MethodReference(astType, hierarchyLoop, methodKey, methodASTReference.getReference().getReturnType(), methodASTReference.getReference())); if (methodASTReference.getConverter() != null) { converters.put(methodKey, methodASTReference.getConverter()); } } //overwrite with property fields for (String fieldKey : propertyFields.keys()) { ASTReference<ASTField> fieldASTReference = propertyFields.get(fieldKey).iterator().next(); readReferences.put(fieldKey, new FieldReference(hierarchyLoop, fieldKey, fieldASTReference.getReference())); fieldWriteReferences.put(fieldKey, new FieldReference(hierarchyLoop, fieldKey, fieldASTReference.getReference())); if (fieldASTReference.getConverter() != null) { converters.put(fieldKey, fieldASTReference.getConverter()); } } //default write via methods for (String methodKey : defaultWriteMethods.keys()) { ASTReference<ASTMethod> methodASTReference = defaultWriteMethods.get(methodKey).iterator() .next(); methodWriteReferences.put(methodKey, new MethodReference( astType, hierarchyLoop, methodKey, methodASTReference.getReference() .getParameters().iterator().next().getASTType(), methodASTReference.getReference())); if (methodASTReference.getConverter() != null) { converters.put(methodKey, methodASTReference.getConverter()); } } //overwrite with property methods for (String methodKey : propertyWriteMethods.keys()) { ASTReference<ASTMethod> methodASTReference = propertyWriteMethods.get(methodKey).iterator() .next(); methodWriteReferences.put(methodKey, new MethodReference( astType, hierarchyLoop, methodKey, methodASTReference.getReference() .getParameters().iterator().next().getASTType(), methodASTReference.getReference())); if (methodASTReference.getConverter() != null) { converters.put(methodKey, methodASTReference.getConverter()); } } //constructor if (constructorReference != null) { for (Map.Entry<String, ASTReference<ASTParameter>> parameterEntry : writeParameters .entrySet()) { if (readReferences.containsKey(parameterEntry.getKey())) { if (constructorReference.getWriteReferences() .containsKey(parameterEntry.getValue().getReference())) { validator.error( "More than one property found in inheritance hierarchy to match constructor parameter " + parameterEntry.getKey() + ". Consider renaming or using a manual ParcelConverter.") .element(parameterEntry.getValue().getReference()).build(); } else { validateReadReference(readReferences, parameterEntry.getValue().getReference(), parameterEntry.getKey()); constructorReference.putReference(parameterEntry.getValue().getReference(), readReferences.get(parameterEntry.getKey())); if (parameterEntry.getValue().getConverter() != null) { constructorReference.putConverter(parameterEntry.getValue().getReference(), parameterEntry.getValue().getConverter()); } else { validateType(parameterEntry.getValue().getReference().getASTType(), parameterEntry.getValue().getReference(), parameterEntry.getValue().getReference().toString()); } } } } } //methods for (String propertyName : methodWriteReferences.keySet()) { MethodReference methodReference = methodWriteReferences.get(propertyName); if (!writeParameters.containsKey(propertyName) && readReferences.containsKey(propertyName)) { validateReadReference(readReferences, methodReference.getMethod(), propertyName); ASTType propertyConverter = converters.containsKey(propertyName) ? converters.get(propertyName) : null; if (propertyConverter == null) { validateType(methodReference.getType(), methodReference.getMethod(), methodReference.getOwner().getName() + "#" + methodReference.getName()); } parcelableDescriptor.getMethodPairs().add(new ReferencePair<MethodReference>(propertyName, methodReference, readReferences.get(propertyName), propertyConverter)); } } //fields for (String propertyName : fieldWriteReferences.keySet()) { FieldReference fieldReference = fieldWriteReferences.get(propertyName); if (!writeParameters.containsKey(propertyName) && !methodWriteReferences.containsKey(propertyName) && readReferences.containsKey(propertyName)) { validateReadReference(readReferences, fieldReference.getField(), propertyName); ASTType propertyConverter = converters.containsKey(propertyName) ? converters.get(propertyName) : null; if (propertyConverter == null) { validateType(fieldReference.getType(), fieldReference.getField(), fieldReference.getOwner().getName() + "." + fieldReference.getName()); } parcelableDescriptor.getFieldPairs().add(new ReferencePair<FieldReference>(propertyName, fieldReference, readReferences.get(propertyName), propertyConverter)); } } //Add all public methods for the ability to determine if they have been overridden in a lower subclass for (ASTMethod astMethod : astType.getMethods()) { if (astMethod.getAccessModifier().equals(ASTAccessModifier.PUBLIC)) { definedMethods.add(new MethodSignature(astMethod)); } } } //validate all constructor / factory parameters have a matching read property if (constructorReference != null) { if (constructorReference.getConstructor() != null) { for (ASTParameter parameter : constructorReference.getConstructor().getParameters()) { if (!constructorReference.containsWriteReference(parameter)) { validator.error("No corresponding property found for constructor parameter " + parameter.getName()).element(parameter).build(); } } } else if (constructorReference.getFactoryMethod() != null) { for (ASTParameter parameter : constructorReference.getFactoryMethod().getParameters()) { if (!constructorReference.containsWriteReference(parameter)) { validator.error("No corresponding property found for factory method parameter " + parameter.getName()).element(parameter).build(); } } } } } if (validator.isInError()) { return null; } return parcelableDescriptor; }
From source file:com.bendb.thrifty.schema.Program.java
/** * Get all named elements declared in this Program. *///from w w w . j ava 2 s . c o m public Iterable<Named> names() { // Some type-resolution subtlety eludes me. I'd have thought that // Iterable<EnumType> is castable to Iterable<Named> (inheritance), // but the IDE claims otherwise. So, instead of FluentIterable.<Named>from(enums), // we work around by making one from an empty Named array and appending. FluentIterable<Named> iter = FluentIterable.of(new Named[0]); return iter.append(enums).append(structs).append(unions).append(exceptions).append(services) .append(typedefs); }
From source file:org.graylog2.plugin.inputs.Extractor.java
public void runExtractor(Message msg) { // We can only work on Strings. if (!(msg.getField(sourceField) instanceof String)) { return;/* www .j av a2 s . c o m*/ } final String field = (String) msg.getField(sourceField); // Decide if to extract at all. if (conditionType.equals(ConditionType.STRING)) { if (!field.contains(conditionValue)) { return; } } else if (conditionType.equals(ConditionType.REGEX)) { if (!regexConditionPattern.matcher(field).find()) { return; } } final Timer.Context timerContext = metricRegistry.timer(getTotalTimerName()).time(); final Result[] results = run(field); if (results == null || results.length == 0 || FluentIterable.of(results).anyMatch(VALUE_NULL_PREDICATE)) { timerContext.close(); return; } else if (results.length == 1 && results[0].target == null) { // results[0].target is null if this extractor cannot produce multiple fields use targetField in that case msg.addField(targetField, results[0].getValue()); } else { for (final Result result : results) { msg.addField(result.getTarget(), result.getValue()); } } // Remove original from message? if (cursorStrategy.equals(CursorStrategy.CUT) && !targetField.equals(sourceField) && !Message.RESERVED_FIELDS.contains(sourceField) && results[0].beginIndex != -1) { final StringBuilder sb = new StringBuilder(field); final ImmutableList<Result> reverseList = FluentIterable.from(Arrays.asList(results)) .toSortedList(new Comparator<Result>() { @Override public int compare(Result left, Result right) { // reversed! return -1 * ComparisonChain.start().compare(left.endIndex, right.endIndex).result(); } }); // remove all from reverse so that the indices still match for (final Result result : reverseList) { sb.delete(result.getBeginIndex(), result.getEndIndex()); } String finalResult = sb.toString(); // also ignore pure whitespace if (finalResult.trim().isEmpty()) { finalResult = "fullyCutByExtractor"; } msg.removeField(sourceField); // TODO don't add an empty field back, or rather don't add fullyCutByExtractor msg.addField(sourceField, finalResult); } runConverters(msg); timerContext.stop(); }
From source file:org.apache.james.mailet.DefaultDescriptorsExtractor.java
private boolean isExperimental(JavaClass javaClass) { return FluentIterable.of(javaClass.getAnnotations()).anyMatch(new Predicate<Annotation>() { @Override/*from w ww . j a va 2 s . co m*/ public boolean apply(Annotation annotation) { return annotation.getType().getValue().equals(Experimental.class.getName()); } }); }
From source file:org.everit.json.schema.ObjectSchema.java
private FluentIterable<String> getAdditionalProperties(final JSONObject subject) { String[] names = JSONObject.getNames(subject); if (names == null) { return FluentIterable.from(Lists.<String>newArrayList()); } else {/*from ww w. jav a 2 s . c o m*/ return FluentIterable.of(names).filter(new Predicate<String>() { @Override public boolean apply(String key) { return !propertySchemas.containsKey(key) && !matchesAnyPattern(key); } }); } }