/** * Returns the first element of the given collection * * @param <T> * @param collection * @return <code>null</code> if the first element is <code>null</code> or * the collection is <code>null</code> or empty */ public static <T> T firstElementOf(final Collection<? extends T> collection) { if (isEmpty(collection)) { return null; } return collection.iterator().next(); }
/** * Constructor * * @param customData * @param declaredByMetadataId * @param modifier * @param annotations can be <code>null</code> for none */ protected AbstractIdentifiableAnnotatedJavaStructureProvider(final CustomData customData, final String declaredByMetadataId, final int modifier, final Collection<AnnotationMetadata> annotations) { super(customData, declaredByMetadataId, modifier); CollectionUtils.populate(this.annotations, annotations); }
public MethodMetadata getMostConcreteMethodWithTag(final Object tagKey) { return CollectionUtils.firstElementOf(getMethodsWithTag(tagKey)); }
final List<?> excludeFieldsList = CollectionUtils.arrayToList(excludeFields); final FieldMetadata versionField = getPersistenceMemberLocator().getVersionField(javaType);
final List<?> excludeFieldsList = CollectionUtils.arrayToList(excludeFields); final FieldMetadata versionField = getPersistenceMemberLocator().getVersionField(javaType);
public String asPlainText() { StringBuilder sb = new StringBuilder(); if (!CollectionUtils.isEmpty(beginComments)) { sb.append(StringUtils.join(beginComments, "\n")); } if (!CollectionUtils.isEmpty(internalComments)) { if (sb.length() > 0) { sb.append("/n"); } sb.append(StringUtils.join(internalComments, "\n")); } if (!CollectionUtils.isEmpty(endComments)) { if (sb.length() > 0) { sb.append("/n"); } sb.append(StringUtils.join(endComments, "\n")); } return sb.toString(); }
/** * Constructor * * @param customData * @param declaredByMetadataId * @param modifier * @param annotations * @param parameterTypes * @param parameterNames * @param throwsTypes * @param body */ protected AbstractInvocableMemberMetadata(final CustomData customData, final String declaredByMetadataId, final int modifier, final List<AnnotationMetadata> annotations, final List<AnnotatedJavaType> parameterTypes, final List<JavaSymbolName> parameterNames, final List<JavaType> throwsTypes, final String body) { super(customData, declaredByMetadataId, modifier, annotations); this.body = body; CollectionUtils.populate(this.parameterNames, parameterNames); CollectionUtils.populate(this.parameterTypes, parameterTypes); CollectionUtils.populate(this.throwsTypes, throwsTypes); }
public MethodMetadata getMostConcreteMethodWithTag(final Object tagKey) { return CollectionUtils.firstElementOf(getMethodsWithTag(tagKey)); }
private boolean isEmpty(List<AbstractComment> comments) { if (CollectionUtils.isEmpty(comments)) { return true; } for (AbstractComment comment : comments) { if (StringUtils.isNotBlank(comment.getComment())) { return false; } } return true; } }
/** * Set the aspects to use on {@code declare precedence} * AspectJ declaration. * * @param aspects */ public void setDeclarePrecedence(JavaType... aspects) { if (aspects != null && aspects.length > 0) { Validate.isTrue(aspects.length >= 1, "precedence must contain, at least, 1 aspect"); } CollectionUtils.populate(declarePrecedence, Arrays.asList(aspects)); }
private String collectionToDelimitedString(final Collection<?> coll, final String delim, final String prefix, final String suffix) { if (CollectionUtils.isEmpty(coll)) { return ""; } final StringBuilder sb = new StringBuilder(); final Iterator<?> it = coll.iterator(); while (it.hasNext()) { sb.append(prefix).append(it.next()).append(suffix); if (it.hasNext() && delim != null) { sb.append(delim); } } return sb.toString(); }
this.registeredImports.putAll(registeredImports); CollectionUtils.populate(this.declaredConstructors, declaredConstructors); CollectionUtils.populate(this.declaredFields, declaredFields); CollectionUtils.populate(this.declaredMethods, declaredMethods); CollectionUtils.populate(this.extendsTypes, extendsTypes); CollectionUtils.populate(this.fieldAnnotations, fieldAnnotations); CollectionUtils.populate(this.implementsTypes, implementsTypes); CollectionUtils.populate(this.innerTypes, innerTypes); CollectionUtils.populate(this.methodAnnotations, methodAnnotations); CollectionUtils.populate(this.declarePrecedence, declarePrecedence);
/** * Returns the {@link Identifier} for the entity identified by the given * metadata ID. * * @param metadataIdentificationString * @return <code>null</code> if there isn't one */ private Identifier getIdentifier(final String metadataIdentificationString) { final JavaType entity = getType(metadataIdentificationString); final List<Identifier> identifiers = getIdentifiersForType(entity); if (CollectionUtils.isEmpty(identifiers)) { return null; } // We have potential identifier information from an IdentifierService. // We only use this identifier information if the user did NOT provide // ANY identifier-related attributes on @RooJpaEntity.... Validate .isTrue( identifiers.size() == 1, "Identifier service indicates %d fields illegally for the entity '%s' (should only be one identifier field given this is an entity, not an Identifier class)", identifiers.size(), entity.getSimpleTypeName()); return identifiers.iterator().next(); }
private void cachePhysicalPaths(final Collection<Path> paths) { final Collection<Path> pathsToCache = CollectionUtils.populate(new HashSet<Path>(), paths); if (!pathsToCache.contains(ROOT)) { pathsToCache.add(ROOT); } for (final Path path : pathsToCache) { pathLocations.put(path, path.getModulePath(this)); } }
public MemberTypeAdditions getMemberTypeAdditions(final String callerMID, final String methodIdentifier, final JavaType targetEntity, final JavaType idType, boolean autowire, final MethodParameter... callerParameters) { Validate.isTrue(StringUtils.isNotBlank(callerMID), "Caller's metadata ID required"); Validate.notBlank(methodIdentifier, "Method identifier required"); Validate.notNull(targetEntity, "Target enitity type required"); Validate.notNull(idType, "Enitity Id type required"); // Look for a repository layer method with this ID and parameter types final List<JavaType> parameterTypes = new PairList<JavaType, JavaSymbolName>(callerParameters).getKeys(); final RepositoryJpaLayerMethod method = RepositoryJpaLayerMethod.valueOf(methodIdentifier, parameterTypes, targetEntity, idType); if (method == null) { return null; } // Look for repositories that support this domain type final Collection<ClassOrInterfaceTypeDetails> repositories = repositoryLocator.getRepositories(targetEntity); if (CollectionUtils.isEmpty(repositories)) { return null; } // Use the first such repository (could refine this later) final ClassOrInterfaceTypeDetails repository = repositories.iterator().next(); // Return the additions the caller needs to make return getMethodAdditions(callerMID, method, repository.getName(), Arrays.asList(callerParameters)); }
/** * Constructs a new instance. * * @param details the member holders that should be stored in this instance * (can be <code>null</code>) */ public MemberDetailsImpl(final Collection<? extends MemberHoldingTypeDetails> details) { Validate.notEmpty(details, "Member holding details required"); CollectionUtils.populate(this.details, details); }
public boolean executeCommand(final String line) { if (tailor == null) { return executeCommandImpl(line); } /* * If getTailor() is not null, then try to transform input command and * execute all outputs sequentially */ List<String> commands = null; commands = tailor.sew(line); if (CollectionUtils.isEmpty(commands)) { return executeCommandImpl(line); } for (final String command : commands) { logger.info("roo-tailor> " + command); if (!executeCommandImpl(command)) { return false; } } return true; }
/** * Constructor that takes a pre-built method call. * * @param builder stores any changes the caller should make in order to make * the given method call, e.g. the field that is the method * target; can be <code>null</code> if the caller requires no * changes other than the given method call * @param methodName the bare name of the method being invoked (required) * @param methodCall a valid Java snippet that calls the method, including * any required target and parameters, for example "foo.bar(baz)" * (required) * @param isStatic whether the invoked method is static * @param methodParameters the parameters taken by the invoked method (can * be <code>null</code>) */ public MemberTypeAdditions(final ClassOrInterfaceTypeDetailsBuilder builder, final String methodName, final String methodCall, final boolean isStatic, final List<MethodParameter> methodParameters) { Validate.notBlank(methodName, "Invalid method name '%s'", methodName); Validate.notBlank(methodCall, "Invalid method signature '%s'", methodCall); classOrInterfaceDetailsBuilder = builder; this.methodCall = methodCall; this.methodName = methodName; this.methodParameters = new ArrayList<MethodParameter>(); CollectionUtils.populate(this.methodParameters, methodParameters); this.isStatic = isStatic; }
Validate.isTrue(isProjectAvailable(moduleName), "Plugin modification prohibited at this time"); Validate.notNull(newPlugins, "Plugins required"); if (CollectionUtils.isEmpty(newPlugins)) { return;
/** * Constructor that allows all fields to be set. * * @param groupId the group ID (required) * @param artifactId the artifact ID (required) * @param version the version (required) * @param configuration the configuration for this plugin (optional) * @param dependencies the dependencies for this plugin (can be * <code>null</code>) * @param executions the executions for this plugin (can be * <code>null</code>) */ public Plugin(final String groupId, final String artifactId, final String version, final Configuration configuration, final Collection<? extends Dependency> dependencies, final Collection<? extends Execution> executions) { Validate.notNull(groupId, "Group ID required"); Validate.notNull(artifactId, "Artifact ID required"); //Validate.notNull(version, "Version required"); if (version == null || version == "") { gav = new GAV(groupId, artifactId, "-"); } else { gav = new GAV(groupId, artifactId, version); } this.configuration = configuration; // Defensively copy the given nullable collections CollectionUtils.populate(this.dependencies, dependencies); CollectionUtils.populate(this.executions, executions); }