/** * 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(); }
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(); }
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; } }
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(); }
/** * 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(); }
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)); }
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; }
Validate.isTrue(isProjectAvailable(moduleName), "Plugin modification prohibited at this time"); Validate.notNull(newPlugins, "Plugins required"); if (CollectionUtils.isEmpty(newPlugins)) { return;
Validate.notNull(repositories, "Repositories required"); if (CollectionUtils.isEmpty(repositories)) { return;
"Dependency modification prohibited at this time"); Validate.notNull(dependenciesToRemove, "Dependencies required"); if (CollectionUtils.isEmpty(dependenciesToRemove)) { return;
Validate.isTrue(isProjectAvailable(moduleName), "Plugin modification prohibited at this time"); Validate.notNull(plugins, "Plugins required"); if (CollectionUtils.isEmpty(plugins)) { return;
if (!hasJavaBeanAnnotation && !CollectionUtils.isEmpty(equalityFields)) { ensureGovernorHasMethod(new MethodMetadataBuilder(getEqualsMethod())); ensureGovernorHasMethod(new MethodMetadataBuilder(getHashCodeMethod()));
public void addEqualsAndHashCodeMethods(final JavaType javaType, final boolean appendSuper, final Set<String> excludeFields) { // Add @RooEquals annotation to class if not yet present final ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(javaType); if (cid == null || cid.getTypeAnnotation(ROO_EQUALS) != null) { return; } final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(ROO_EQUALS); if (appendSuper) { annotationBuilder.addBooleanAttribute("appendSuper", appendSuper); } if (!CollectionUtils.isEmpty(excludeFields)) { final List<StringAttributeValue> attributes = new ArrayList<StringAttributeValue>(); for (final String excludeField : excludeFields) { attributes.add(new StringAttributeValue(new JavaSymbolName("value"), excludeField)); } annotationBuilder.addAttribute(new ArrayAttributeValue<StringAttributeValue>( new JavaSymbolName("excludeFields"), attributes)); } final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(cid); cidBuilder.addAnnotation(annotationBuilder.build()); typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build()); } }
final String transportGuarantee, final Document document, final String comment) { Validate.notNull(document, "Web XML document required"); Validate.isTrue(!CollectionUtils.isEmpty(webResourceCollections), "A security-constraint element must contain at least one web-resource-collection");
private Properties getProps(final Map<String, String> map) { Validate.isTrue(!CollectionUtils.isEmpty(map), "Connection properties map must not be null or empty"); final Properties props = new Properties(); props.putAll(map); return props; } }
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(); }
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(); }
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; } }
/** * 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(); }
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; }