List of usage examples for com.google.common.collect Iterables any
public static <T> boolean any(Iterable<T> iterable, Predicate<? super T> predicate)
From source file:com.palantir.ptoss.cinch.core.BindingContext.java
private Map<String, ObjectFieldMethod> indexBindableMethods() throws IllegalArgumentException { // Get all fields marked @Bindable List<Field> bindables = getAnnotatedFields(Bindable.class); if (Iterables.any(bindables, Predicates.not(Reflections.IS_FIELD_FINAL))) { throw new BindingException("all @Bindables have to be final"); }// w w w . j ava 2s . c o m // Add all BindableModels bindables.addAll(getBindableModelFields()); // Index those methods. List<ObjectFieldMethod> methods = getParameterlessMethodsOnFieldTypes(object, bindables); // Add methods for classes marked @Bindable if (Reflections.isClassAnnotatedForClassHierarchy(object, Bindable.class)) { methods.addAll(Reflections.getParameterlessMethodsForClassHierarchy(object)); } return indexMethods(methods); }
From source file:zotmc.collect.recipe.BasicRecipeView.java
private static IRecipe explicitShaped(boolean mirrored, int w, int h, Collection<RecipeElement> inputs, ItemStack result) {//from w w w.j a va 2 s.c om if (!mirrored || Iterables.any(inputs, RecipeElement.IS_ORE)) { ShapedOreRecipe r = new ShapedOreRecipe(result, mirrored, ' ', Items.apple); WIDTH.set(r, w); HEIGHT.set(r, h); INPUT.set(r, Collections2.transform(inputs, TO_ORE_RECIPE_INPUT).toArray(new Object[w * h])); return r; } return new ShapedRecipes(w, h, Collections2.transform(inputs, TO_ITEM_STACK).toArray(new ItemStack[w * h]), result); }
From source file:zotmc.collect.recipe.BasicRecipeView.java
private static IRecipe explicitShapeless(Collection<RecipeElement> inputs, ItemStack result) { if (Iterables.any(inputs, RecipeElement.IS_ORE)) { ShapelessOreRecipe r = new ShapelessOreRecipe(result); castRaw(r.getInput()).addAll(Collections2.transform(inputs, TO_ORE_RECIPE_INPUT)); return r; }/* w ww . j av a 2 s .c om*/ return new ShapelessRecipes(result, ImmutableList.copyOf(Collections2.transform(inputs, TO_ITEM_STACK))); }
From source file:org.eclipse.sirius.diagram.ui.tools.internal.actions.repair.AbstractDiagramElementState.java
/** * Restore {@link GraphicalFilter}.//from w ww.j ava 2 s .c om * * @param element * the {@link DDiagramElement} on which restore the specified * {@link GraphicalFilter} * @param filter * the specified {@link GraphicalFilter} to restore */ protected void addFilterType(DDiagramElement element, GraphicalFilter filter) { if (!Iterables.any(element.getGraphicalFilters(), Predicates.instanceOf(filter.getClass()))) { element.getGraphicalFilters().add(filter); } }
From source file:gov.nih.nci.firebird.data.AbstractProtocolRegistration.java
/** * @return whether or not this registration is a reactivation of an approved registration *//*from w ww . ja v a2 s .co m*/ @Transient public boolean isApprovedRegistrationReactivation() { if (getInvitation().getInvitationStatus() != InvitationStatus.REACTIVATED) { return false; } return Iterables.any(getParentRegistrations(), new Predicate<AbstractProtocolRegistration>() { public boolean apply(AbstractProtocolRegistration registration) { return registration.getApprovalDate() != null && registration.getStatus() == RegistrationStatus.INACTIVE; } }); }
From source file:com.facebook.swift.codec.metadata.AbstractThriftMetadataBuilder.java
protected final void addMethod(Type type, Method method, boolean allowReaders, boolean allowWriters) { checkArgument(method.isAnnotationPresent(ThriftField.class)); ThriftField annotation = method.getAnnotation(ThriftField.class); Class<?> clazz = TypeToken.of(type).getRawType(); // verify parameters if (isValidateGetter(method)) { if (allowReaders) { MethodExtractor methodExtractor = new MethodExtractor(type, method, annotation, THRIFT_FIELD); fields.add(methodExtractor); extractors.add(methodExtractor); } else {//w ww. j av a 2s . c o m metadataErrors.addError("Reader method %s.%s is not allowed on a builder class", clazz.getName(), method.getName()); } } else if (isValidateSetter(method)) { if (allowWriters) { List<ParameterInjection> parameters; if (method.getParameterTypes().length > 1 || Iterables.any( asList(method.getParameterAnnotations()[0]), Predicates.instanceOf(ThriftField.class))) { parameters = getParameterInjections(type, method.getParameterAnnotations(), resolveFieldTypes(type, method.getGenericParameterTypes()), extractParameterNames(method)); if (annotation.value() != Short.MIN_VALUE) { metadataErrors.addError( "A method with annotated parameters can not have a field id specified: %s.%s ", clazz.getName(), method.getName()); } if (!annotation.name().isEmpty()) { metadataErrors.addError( "A method with annotated parameters can not have a field name specified: %s.%s ", clazz.getName(), method.getName()); } if (annotation.requiredness() == Requiredness.REQUIRED) { metadataErrors.addError( "A method with annotated parameters can not be marked as required: %s.%s ", clazz.getName(), method.getName()); } } else { Type parameterType = resolveFieldTypes(type, method.getGenericParameterTypes())[0]; parameters = ImmutableList.of(new ParameterInjection(type, 0, annotation, ReflectionHelper.extractFieldName(method), parameterType)); } fields.addAll(parameters); methodInjections.add(new MethodInjection(method, parameters)); } else { metadataErrors.addError( "Inject method %s.%s is not allowed on struct class, since struct has a builder", clazz.getName(), method.getName()); } } else { metadataErrors.addError("Method %s.%s is not a supported getter or setter", clazz.getName(), method.getName()); } }
From source file:org.inferred.freebuilder.processor.CodeGenerator.java
/** Write the source code for a generated builder. */ void writeBuilderSource(SourceBuilder code, Metadata metadata) { if (!metadata.hasBuilder()) { writeStubSource(code, metadata); return;/* w w w. ja v a 2s . com*/ } boolean hasRequiredProperties = any(metadata.getProperties(), IS_REQUIRED); code.addLine("/**").addLine(" * Auto-generated superclass of {@link %s},", metadata.getBuilder()) .addLine(" * derived from the API of {@link %s}.", metadata.getType()).addLine(" */") .addLine("@%s(\"%s\")", Generated.class, this.getClass().getName()); if (metadata.isGwtCompatible()) { code.addLine("@%s", GwtCompatible.class); } code.add("abstract class %s", metadata.getGeneratedBuilder().getSimpleName()); if (metadata.isBuilderSerializable()) { code.add(" implements %s", Serializable.class); } code.addLine(" {"); // Static fields if (metadata.getProperties().size() > 1) { code.addLine("").addLine(" private static final %1$s COMMA_JOINER = %1$s.on(\", \").skipNulls();", Joiner.class); } // Property enum if (hasRequiredProperties) { addPropertyEnum(metadata, code); } // Property fields code.addLine(""); for (Property property : metadata.getProperties()) { PropertyCodeGenerator codeGenerator = property.getCodeGenerator(); codeGenerator.addBuilderFieldDeclaration(code); } // Unset properties if (hasRequiredProperties) { code.addLine(" private final %s<%s> _unsetProperties =", EnumSet.class, metadata.getPropertyEnum()) .addLine(" %s.allOf(%s.class);", EnumSet.class, metadata.getPropertyEnum()); } // Setters and getters for (Property property : metadata.getProperties()) { property.getCodeGenerator().addBuilderFieldAccessors(code, metadata); } // Value type String inheritsFrom = getInheritanceKeyword(metadata.getType()); code.addLine(""); if (metadata.isGwtSerializable()) { // Due to a bug in GWT's handling of nested types, we have to declare Value as package scoped // so Value_CustomFieldSerializer can access it. code.addLine(" @%s(serializable = true)", GwtCompatible.class).addLine( " static final class %s %s %s {", metadata.getValueType().getSimpleName(), inheritsFrom, metadata.getType()); } else { code.addLine(" private static final class %s %s %s {", metadata.getValueType().getSimpleName(), inheritsFrom, metadata.getType()); } // Fields for (Property property : metadata.getProperties()) { property.getCodeGenerator().addValueFieldDeclaration(code, property.getName()); } // Constructor code.addLine("").addLine(" private %s(%s builder) {", metadata.getValueType().getSimpleName(), metadata.getGeneratedBuilder()); for (Property property : metadata.getProperties()) { property.getCodeGenerator().addFinalFieldAssignment(code, "this." + property.getName(), "builder"); } code.addLine(" }"); // Getters for (Property property : metadata.getProperties()) { code.addLine("").addLine(" @%s", Override.class); for (TypeElement nullableAnnotation : property.getNullableAnnotations()) { code.addLine(" @%s", nullableAnnotation); } code.addLine(" public %s %s() {", property.getType(), property.getGetterName()); code.add(" return "); property.getCodeGenerator().addReadValueFragment(code, property.getName()); code.add(";\n"); code.addLine(" }"); } // Equals switch (metadata.standardMethodUnderride(StandardMethod.EQUALS)) { case ABSENT: // Default implementation if no user implementation exists. code.addLine("").addLine(" @%s", Override.class).addLine(" public boolean equals(Object obj) {") .addLine(" if (!(obj instanceof %s)) {", metadata.getValueType()) .addLine(" return false;").addLine(" }") .addLine(" %1$s other = (%1$s) obj;", metadata.getValueType()); if (metadata.getProperties().isEmpty()) { code.addLine(" return true;"); } else if (code.getSourceLevel().javaUtilObjects().isPresent()) { String prefix = " return "; for (Property property : metadata.getProperties()) { code.add(prefix); code.add("%1$s.equals(%2$s, other.%2$s)", code.getSourceLevel().javaUtilObjects().get(), property.getName()); prefix = "\n && "; } code.add(";\n"); } else { for (Property property : metadata.getProperties()) { switch (property.getType().getKind()) { case FLOAT: case DOUBLE: code.addLine(" if (%s.doubleToLongBits(%s)", Double.class, property.getName()).addLine( " != %s.doubleToLongBits(other.%s)) {", Double.class, property.getName()); break; default: if (property.getType().getKind().isPrimitive()) { code.addLine(" if (%1$s != other.%1$s) {", property.getName()); } else if (property.getCodeGenerator().getType() == Type.OPTIONAL) { code.addLine(" if (%1$s != other.%1$s", property.getName()).addLine( " && (%1$s == null || !%1$s.equals(other.%1$s))) {", property.getName()); } else { code.addLine(" if (!%1$s.equals(other.%1$s)) {", property.getName()); } } code.addLine(" return false;").addLine(" }"); } code.addLine(" return true;"); } code.addLine(" }"); break; case OVERRIDEABLE: // Partial-respecting override if a non-final user implementation exists. code.addLine("").addLine(" @%s", Override.class).addLine(" public boolean equals(Object obj) {") .addLine(" return (!(obj instanceof %s) && super.equals(obj));", metadata.getPartialType()) .addLine(" }"); break; case FINAL: // Cannot override if a final user implementation exists. break; } // Hash code if (metadata.standardMethodUnderride(StandardMethod.HASH_CODE) == ABSENT) { String properties = Joiner.on(", ").join(getNames(metadata.getProperties())); code.addLine("").addLine(" @%s", Override.class).addLine(" public int hashCode() {"); if (code.getSourceLevel().javaUtilObjects().isPresent()) { code.addLine(" return %s.hash(%s);", code.getSourceLevel().javaUtilObjects().get(), properties); } else { code.addLine(" return %s.hashCode(new Object[] { %s });", Arrays.class, properties); } code.addLine(" }"); } // toString if (metadata.standardMethodUnderride(StandardMethod.TO_STRING) == ABSENT) { code.addLine("").addLine(" @%s", Override.class).addLine(" public %s toString() {", String.class) .add(" return \"%s{", metadata.getType().getSimpleName()); switch (metadata.getProperties().size()) { case 0: { code.add("}\";\n"); break; } case 1: { Property property = getOnlyElement(metadata.getProperties()); if (property.getCodeGenerator().getType() == Type.OPTIONAL) { code.add("\" + (%1$s != null ? \"%1$s=\" + %1$s : \"\") + \"}\";\n", property.getName()); } else { code.add("%1$s=\" + %1$s + \"}\";\n", property.getName()); } break; } default: { // If one or more of the properties are optional, use COMMA_JOINER for readability. // Otherwise, use string concatenation for performance. if (any(metadata.getProperties(), IS_OPTIONAL)) { code.add("\"\n").add(" + COMMA_JOINER.join(\n"); Property lastProperty = getLast(metadata.getProperties()); for (Property property : metadata.getProperties()) { code.add(" "); if (property.getCodeGenerator().getType() == Type.OPTIONAL) { code.add("(%s != null ? ", property.getName()); } code.add("\"%1$s=\" + %1$s", property.getName()); if (property.getCodeGenerator().getType() == Type.OPTIONAL) { code.add(" : null)"); } if (property != lastProperty) { code.add(",\n"); } else { code.add(")\n"); } } code.addLine(" + \"}\";"); } else { code.add("\"\n"); Property lastProperty = getLast(metadata.getProperties()); for (Property property : metadata.getProperties()) { code.add(" + \"%1$s=\" + %1$s", property.getName()); if (property != lastProperty) { code.add(" + \", \"\n"); } else { code.add(" + \"}\";\n"); } } } break; } } code.addLine(" }"); } code.addLine(" }"); if (metadata.isGwtSerializable()) { addCustomValueSerializer(metadata, code); } // build() code.addLine("").addLine(" /**").addLine( " * Returns a newly-created {@link %s} based on the contents of the {@code %s}.", metadata.getType(), metadata.getBuilder().getSimpleName()); if (hasRequiredProperties) { code.addLine(" *").addLine(" * @throws IllegalStateException if any field has not been set"); } code.addLine(" */").addLine(" public %s build() {", metadata.getType()); if (hasRequiredProperties) { code.addLine(" %s.checkState(_unsetProperties.isEmpty(), \"Not set: %%s\", _unsetProperties);", Preconditions.class); } code.addLine(" return new %s(this);", metadata.getValueType()).addLine(" }"); // mergeFrom(Value) code.addLine("").addLine(" /**") .addLine(" * Sets all property values using the given {@code %s} as a template.", metadata.getType()) .addLine(" */") .addLine(" public %s mergeFrom(%s value) {", metadata.getBuilder(), metadata.getType()); for (Property property : metadata.getProperties()) { property.getCodeGenerator().addMergeFromValue(code, "value"); } code.addLine(" return (%s) this;", metadata.getBuilder()); code.addLine(" }"); // mergeFrom(Builder) code.addLine("").addLine(" /**").addLine(" * Copies values from the given {@code %s}.", metadata.getBuilder().getSimpleName()); if (hasRequiredProperties) { code.addLine(" * Does not affect any properties not set on the input."); } code.addLine(" */").addLine(" public %1$s mergeFrom(%1$s template) {", metadata.getBuilder()); if (hasRequiredProperties) { code.addLine(" // Upcast to access the private _unsetProperties field.") .addLine(" // Otherwise, oddly, we get an access violation.") .addLine(" %s<%s> _templateUnset = ((%s) template)._unsetProperties;", EnumSet.class, metadata.getPropertyEnum(), metadata.getGeneratedBuilder()); } for (Property property : metadata.getProperties()) { if (property.getCodeGenerator().getType() == Type.REQUIRED) { code.addLine(" if (!_templateUnset.contains(%s.%s)) {", metadata.getPropertyEnum(), property.getAllCapsName()); property.getCodeGenerator().addMergeFromBuilder(withIndent(code, 2), metadata, "template"); code.addLine(" }"); } else { property.getCodeGenerator().addMergeFromBuilder(code, metadata, "template"); } } code.addLine(" return (%s) this;", metadata.getBuilder()); code.addLine(" }"); // clear() if (metadata.getBuilderFactory().isPresent()) { code.addLine("").addLine(" /**").addLine(" * Resets the state of this builder.").addLine(" */") .addLine(" public %s clear() {", metadata.getBuilder()); List<PropertyCodeGenerator> codeGenerators = Lists.transform(metadata.getProperties(), GET_CODE_GENERATOR); if (Iterables.any(codeGenerators, IS_TEMPLATE_REQUIRED_IN_CLEAR)) { code.add(" %s _template = ", metadata.getGeneratedBuilder()); metadata.getBuilderFactory().get().addNewBuilder(code, metadata.getBuilder()); code.add(";\n"); } for (PropertyCodeGenerator codeGenerator : codeGenerators) { if (codeGenerator.isTemplateRequiredInClear()) { codeGenerator.addClear(code, "_template"); } else { codeGenerator.addClear(code, null); } } if (hasRequiredProperties) { code.addLine(" _unsetProperties.clear();").addLine( " _unsetProperties.addAll(_template._unsetProperties);", metadata.getGeneratedBuilder()); } code.addLine(" return (%s) this;", metadata.getBuilder()).addLine(" }"); } else { code.addLine("").addLine(" /**") .addLine(" * Ensures a subsequent mergeFrom call will make a clone of its input.") .addLine(" *") .addLine(" * <p>The exact implementation of this method is not guaranteed to remain") .addLine(" * stable; it should always be followed directly by a mergeFrom call.") .addLine(" */").addLine(" public %s clear() {", metadata.getBuilder()); for (Property property : metadata.getProperties()) { property.getCodeGenerator().addPartialClear(code); } code.addLine(" return (%s) this;", metadata.getBuilder()).addLine(" }"); } // GWT whitelist type if (metadata.isGwtSerializable()) { code.addLine("") .addLine(" /** This class exists solely to ensure GWT whitelists all required types. */") .addLine(" @%s(serializable = true)", GwtCompatible.class) .addLine(" static final class GwtWhitelist %s %s {", inheritsFrom, metadata.getType()) .addLine(""); for (Property property : metadata.getProperties()) { code.addLine(" %s %s;", property.getType(), property.getName()); } code.addLine("").addLine(" private GwtWhitelist() {") .addLine(" throw new %s();", UnsupportedOperationException.class).addLine(" }"); for (Property property : metadata.getProperties()) { code.addLine("").addLine(" @%s", Override.class).addLine(" public %s %s() {", property.getType(), property.getGetterName()); code.addLine(" throw new %s();", UnsupportedOperationException.class).addLine(" }"); } code.addLine(" }"); } // Partial value type code.addLine("").addLine(" private static final class %s %s %s {", metadata.getPartialType().getSimpleName(), inheritsFrom, metadata.getType()); // Fields for (Property property : metadata.getProperties()) { property.getCodeGenerator().addValueFieldDeclaration(code, property.getName()); } if (hasRequiredProperties) { code.addLine(" private final %s<%s> _unsetProperties;", EnumSet.class, metadata.getPropertyEnum()); } // Constructor code.addLine("").addLine(" %s(%s builder) {", metadata.getPartialType().getSimpleName(), metadata.getGeneratedBuilder()); for (Property property : metadata.getProperties()) { property.getCodeGenerator().addPartialFieldAssignment(code, "this." + property.getName(), "builder"); } if (hasRequiredProperties) { code.addLine(" this._unsetProperties = builder._unsetProperties.clone();"); } code.addLine(" }"); // Getters for (Property property : metadata.getProperties()) { code.addLine("").addLine(" @%s", Override.class); for (TypeElement nullableAnnotation : property.getNullableAnnotations()) { code.addLine(" @%s", nullableAnnotation); } code.addLine(" public %s %s() {", property.getType(), property.getGetterName()); if (property.getCodeGenerator().getType() == Type.REQUIRED) { code.addLine(" if (_unsetProperties.contains(%s.%s)) {", metadata.getPropertyEnum(), property.getAllCapsName()) .addLine(" throw new %s(\"%s not set\");", UnsupportedOperationException.class, property.getName()) .addLine(" }"); } code.add(" return "); property.getCodeGenerator().addReadValueFragment(code, property.getName()); code.add(";\n"); code.addLine(" }"); } // Equals if (metadata.standardMethodUnderride(StandardMethod.EQUALS) != FINAL) { code.addLine("").addLine(" @%s", Override.class).addLine(" public boolean equals(Object obj) {") .addLine(" if (!(obj instanceof %s)) {", metadata.getPartialType()) .addLine(" return false;").addLine(" }") .addLine(" %1$s other = (%1$s) obj;", metadata.getPartialType()); if (metadata.getProperties().isEmpty()) { code.addLine(" return true;"); } else if (code.getSourceLevel().javaUtilObjects().isPresent()) { String prefix = " return "; for (Property property : metadata.getProperties()) { code.add(prefix); code.add("%1$s.equals(%2$s, other.%2$s)", code.getSourceLevel().javaUtilObjects().get(), property.getName()); prefix = "\n && "; } if (hasRequiredProperties) { code.add(prefix); code.add("%1$s.equals(_unsetProperties, other._unsetProperties)", code.getSourceLevel().javaUtilObjects().get()); } code.add(";\n"); } else { for (Property property : metadata.getProperties()) { switch (property.getType().getKind()) { case FLOAT: case DOUBLE: code.addLine(" if (%s.doubleToLongBits(%s)", Double.class, property.getName()).addLine( " != %s.doubleToLongBits(other.%s)) {", Double.class, property.getName()); break; default: if (property.getType().getKind().isPrimitive()) { code.addLine(" if (%1$s != other.%1$s) {", property.getName()); } else if (property.getCodeGenerator().getType() == Type.HAS_DEFAULT) { code.addLine(" if (!%1$s.equals(other.%1$s)) {", property.getName()); } else { code.addLine(" if (%1$s != other.%1$s", property.getName()).addLine( " && (%1$s == null || !%1$s.equals(other.%1$s))) {", property.getName()); } } code.addLine(" return false;").addLine(" }"); } if (hasRequiredProperties) { code.addLine(" return _unsetProperties.equals(other._unsetProperties);"); } else { code.addLine(" return true;"); } } code.addLine(" }"); } // Hash code if (metadata.standardMethodUnderride(StandardMethod.HASH_CODE) != FINAL) { code.addLine("").addLine(" @%s", Override.class).addLine(" public int hashCode() {"); List<String> namesList = getNames(metadata.getProperties()); if (hasRequiredProperties) { namesList = ImmutableList.<String>builder().addAll(namesList).add("_unsetProperties").build(); } String properties = Joiner.on(", ").join(namesList); if (code.getSourceLevel().javaUtilObjects().isPresent()) { code.addLine(" return %s.hash(%s);", code.getSourceLevel().javaUtilObjects().get(), properties); } else { code.addLine(" return %s.hashCode(new Object[] { %s });", Arrays.class, properties); } code.addLine(" }"); } // toString if (metadata.standardMethodUnderride(StandardMethod.TO_STRING) != FINAL) { code.addLine("").addLine(" @%s", Override.class).addLine(" public %s toString() {", String.class); code.add(" return \"partial %s{", metadata.getType().getSimpleName()); switch (metadata.getProperties().size()) { case 0: { code.add("}\";\n"); break; } case 1: { Property property = getOnlyElement(metadata.getProperties()); switch (property.getCodeGenerator().getType()) { case HAS_DEFAULT: code.add("%1$s=\" + %1$s + \"}\";\n", property.getName()); break; case OPTIONAL: code.add("\"\n") .addLine(" + (%1$s != null ? \"%1$s=\" + %1$s : \"\")", property.getName()) .addLine(" + \"}\";"); break; case REQUIRED: code.add("\"\n") .addLine(" + (!_unsetProperties.contains(%s.%s)", metadata.getPropertyEnum(), property.getAllCapsName()) .addLine(" ? \"%1$s=\" + %1$s : \"\")", property.getName()) .addLine(" + \"}\";"); break; } break; } default: { code.add("\"\n").add(" + COMMA_JOINER.join(\n"); Property lastProperty = getLast(metadata.getProperties()); for (Property property : metadata.getProperties()) { code.add(" "); switch (property.getCodeGenerator().getType()) { case HAS_DEFAULT: code.add("\"%1$s=\" + %1$s", property.getName()); break; case OPTIONAL: code.add("(%1$s != null ? \"%1$s=\" + %1$s : null)", property.getName()); break; case REQUIRED: code.add("(!_unsetProperties.contains(%s.%s)\n", metadata.getPropertyEnum(), property.getAllCapsName()) .add(" ? \"%1$s=\" + %1$s : null)", property.getName()); break; } if (property != lastProperty) { code.add(",\n"); } else { code.add(")\n"); } } code.addLine(" + \"}\";"); break; } } code.addLine(" }"); } code.addLine(" }"); // buildPartial() code.addLine("").addLine(" /**") .addLine(" * Returns a newly-created partial {@link %s}", metadata.getType()) .addLine(" * based on the contents of the {@code %s}.", metadata.getBuilder().getSimpleName()) .addLine(" * State checking will not be performed."); if (hasRequiredProperties) { code.addLine(" * Unset properties will throw an {@link %s}", UnsupportedOperationException.class) .addLine(" * when accessed via the partial object."); } code.addLine(" *").addLine(" * <p>Partials should only ever be used in tests.").addLine(" */") .addLine(" @%s()", VisibleForTesting.class) .addLine(" public %s buildPartial() {", metadata.getType()) .addLine(" return new %s(this);", metadata.getPartialType()).addLine(" }").addLine("}"); }
From source file:gov.nih.nci.caarray.domain.project.Project.java
/** * Check whether this is a experiment that was previously imported but not parsed, * but now can be imported and parsed (due to a parsing FileHandler being * implemented for it). This will be the case if all of the imported data files * associated with the experiment meet this condition. * @return true if the experiment has repasable data files. *//*from w ww . j av a 2 s . c o m*/ @Transient public boolean isUnparsedAndReimportable() { return Iterables.any(getImportedFileSet(), new Predicate<CaArrayFile>() { public boolean apply(CaArrayFile file) { return file.isUnparsedAndReimportable(); } }); }
From source file:org.jfrog.hudson.ArtifactoryRedeployPublisher.java
private boolean isBuildFromM2ReleasePlugin(AbstractBuild<?, ?> build) { List<Cause> causes = build.getCauses(); return !causes.isEmpty() && Iterables.any(causes, new Predicate<Cause>() { public boolean apply(Cause input) { return "org.jvnet.hudson.plugins.m2release.ReleaseCause".equals(input.getClass().getName()); }//from w w w . j a v a 2s. c o m }); }
From source file:forge.ai.AiController.java
public CardCollection getLandsToPlay() { final CardCollection hand = new CardCollection(player.getCardsIn(ZoneType.Hand)); hand.addAll(player.getCardsIn(ZoneType.Exile)); CardCollection landList = CardLists.filter(hand, Presets.LANDS); CardCollection nonLandList = CardLists.filter(hand, Predicates.not(CardPredicates.Presets.LANDS)); //filter out cards that can't be played landList = CardLists.filter(landList, new Predicate<Card>() { @Override/*from w w w .j a v a 2s .c o m*/ public boolean apply(final Card c) { if (!c.getSVar("NeedsToPlay").isEmpty()) { final String needsToPlay = c.getSVar("NeedsToPlay"); CardCollection list = CardLists.getValidCards(game.getCardsIn(ZoneType.Battlefield), needsToPlay.split(","), c.getController(), c); if (list.isEmpty()) { return false; } } return player.canPlayLand(c); } }); final CardCollection landsNotInHand = new CardCollection(player.getCardsIn(ZoneType.Graveyard)); landsNotInHand.addAll(game.getCardsIn(ZoneType.Exile)); if (!player.getCardsIn(ZoneType.Library).isEmpty()) { landsNotInHand.add(player.getCardsIn(ZoneType.Library).get(0)); } for (final Card crd : landsNotInHand) { if (!(crd.isLand() || (crd.isFaceDown() && crd.getState(CardStateName.Original).getType().isLand()))) { continue; } if (crd.hasKeyword("May be played") || crd.mayPlay(player) != null) { landList.add(crd); } } if (landList.isEmpty()) { return null; } if (landList.size() == 1 && nonLandList.size() < 3) { CardCollectionView cardsInPlay = player.getCardsIn(ZoneType.Battlefield); CardCollection landsInPlay = CardLists.filter(cardsInPlay, Presets.LANDS); CardCollection allCards = new CardCollection(player.getCardsIn(ZoneType.Graveyard)); allCards.addAll(player.getCardsIn(ZoneType.Command)); allCards.addAll(cardsInPlay); int maxCmcInHand = Aggregates.max(hand, CardPredicates.Accessors.fnGetCmc); int max = Math.max(maxCmcInHand, 6); // consider not playing lands if there are enough already and an ability with a discard cost is present if (landsInPlay.size() + landList.size() > max) { for (Card c : allCards) { for (SpellAbility sa : c.getSpellAbilities()) { if (sa.getPayCosts() != null) { for (CostPart part : sa.getPayCosts().getCostParts()) { if (part instanceof CostDiscard) { return null; } } } } } } } landList = CardLists.filter(landList, new Predicate<Card>() { @Override public boolean apply(final Card c) { canPlaySpellBasic(c); if (c.getType().isLegendary() && !c.getName().equals("Flagstones of Trokair")) { final CardCollectionView list = player.getCardsIn(ZoneType.Battlefield); if (Iterables.any(list, CardPredicates.nameEquals(c.getName()))) { return false; } } // don't play the land if it has cycling and enough lands are available final FCollectionView<SpellAbility> spellAbilities = c.getSpellAbilities(); final CardCollectionView hand = player.getCardsIn(ZoneType.Hand); CardCollection lands = new CardCollection(player.getCardsIn(ZoneType.Battlefield)); lands.addAll(hand); lands = CardLists.filter(lands, CardPredicates.Presets.LANDS); int maxCmcInHand = Aggregates.max(hand, CardPredicates.Accessors.fnGetCmc); for (final SpellAbility sa : spellAbilities) { if (sa.isCycling()) { if (lands.size() >= Math.max(maxCmcInHand, 6)) { return false; } } } return true; } }); return landList; }