List of usage examples for com.google.common.collect Iterables isEmpty
public static boolean isEmpty(Iterable<?> iterable)
From source file:org.sonar.plugins.checkstyle.CheckstyleSensor.java
@Override public boolean shouldExecuteOnProject(Project project) { FilePredicates predicates = fs.predicates(); Iterable<File> mainFiles = fs.files(predicates.and(predicates.hasLanguage(CheckstyleConstants.JAVA_KEY), predicates.hasType(Type.MAIN))); return !Iterables.isEmpty(mainFiles) && !profile.getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY).isEmpty(); }
From source file:com.palantir.atlasdb.keyvalue.impl.Cells.java
public static SortedSet<byte[]> getRows(Iterable<Cell> cells) { if (Iterables.isEmpty(cells)) { return ImmutableSortedSet.orderedBy(UnsignedBytes.lexicographicalComparator()).build(); }//ww w .j a va 2s .c o m return FluentIterable.from(cells).transform(getRowFunction()) .toSortedSet(UnsignedBytes.lexicographicalComparator()); }
From source file:org.workhorse.graph.builder.BaseBuilder.java
/** * Common validation method for all builders * that checks required fields to ensure that * they are populated.// ww w. j av a2s. c o m * @return An iterable of validation errors, if any */ protected Iterable<String> validate() { Collection<String> validationErrors = new ArrayList<>(); Arrays.stream(this.getClass().getFields()).filter(field -> field.isAnnotationPresent(Required.class)) .forEach(field -> { try { if (field.get(this) == null) { validationErrors.add(String.format("Required field %s on builder %s cannot be null", field.getName(), this.getClass().getName())); } else if (Collection.class.isAssignableFrom(field.getType())) { if (Iterables.isEmpty((Iterable) field.get(this))) { validationErrors .add(String.format("Required Iterable %s on builder %s cannot be empty", field.getName(), this.getClass().getName())); } } else if (Map.class.isAssignableFrom(field.getType())) { if (((Map) field.get(this)).isEmpty()) { validationErrors.add(String.format("Required Map %s on builder %s cannot be empty", field.getName(), this.getClass().getName())); } } } catch (IllegalAccessException e) { throw new RuntimeException(String.format("Unable to access field %s", field.getName())); } }); return validationErrors; }
From source file:org.summer.ss.core.scoping.StaticallyImportedFeaturesProvider.java
@Override protected Map<JvmTypeReference, Collection<String>> getVisibleTypesContainingStaticMethods( Iterable<JvmTypeReference> hierarchy) { boolean extension = isExtensionProvider(); if (hierarchy == null || Iterables.isEmpty(hierarchy)) { extension = false;// ww w . ja v a2 s .com } List<XImportDeclaration1> imports = getImports(); Collection<String> result = Lists.newArrayList(); for (XImportDeclaration1 imported : imports) { // if (imported.isStatic() && (!extension || imported.isExtension()) && imported.isWildcard()) { // String typeName = imported.getImportedTypeName(); // if (!Strings.isEmpty(typeName)) // result.add(typeName); // } } if (result.isEmpty()) return Collections.emptyMap(); if (!extension || hierarchy == null /* to trick jdt 3.6 npe analysis */ ) { return Collections.singletonMap(null, result); } Map<JvmTypeReference, Collection<String>> map = Maps.newHashMap(); for (JvmTypeReference reference : hierarchy) { map.put(reference, result); } return map; }
From source file:com.google.devtools.build.lib.util.FileTypeSet.java
/** * Returns a set that matches only the provided {@code fileTypes}. * * <p>If {@code fileTypes} is empty, the returned predicate will match no files. *//*from w w w . ja v a 2 s . c o m*/ public static FileTypeSet of(Iterable<FileType> fileTypes) { if (Iterables.isEmpty(fileTypes)) { return FileTypeSet.NO_FILE; } else { return new FileTypeSet(fileTypes); } }
From source file:com.spectralogic.ds3cli.util.RecoveryFileManager.java
public static String printFileList(final Iterable<Path> files) { if (Iterables.isEmpty(files)) { return "No matching recovery files found."; }//from w w w.j a v a2 s . c o m final StringBuffer fileList = new StringBuffer(); try { for (final Path file : files) { final RecoveryJob job = getRecoveryJobByName(file.getFileName().toString()); fileList.append(job.toString()); fileList.append("\n"); } return fileList.toString(); } catch (final IOException e) { return e.getMessage(); } }
From source file:org.sonar.java.checks.xml.web.ValidationFiltersCheck.java
@Override public void scanWebXml(XmlCheckContext context) { Iterable<Node> filtersDefinedInFilters = context.evaluateOnDocument(filterNamesFromFilterExpression); Iterable<Node> filtersUsedInMapping = context.evaluateOnDocument(filterNamesFromFilterMappingExpression); if (Iterables.isEmpty(filtersDefinedInFilters) || Iterables.isEmpty(filtersUsedInMapping)) { reportIssueOnFile("Add a validation filter to this \"web.xml\"."); } else {/*from ww w . j a v a2 s . c o m*/ Set<String> filterNamesFromFilters = getFilterNames(filtersDefinedInFilters); for (Node node : filtersUsedInMapping) { String filterName = getStringValue(node); if (!filterNamesFromFilters.contains(filterName)) { reportIssue(node, "\"" + filterName + "\" is not defined in this file."); } } } }
From source file:com.spectralogic.ds3cli.views.csv.DetailedObjectsView.java
@Override public String render(final GetDetailedObjectsResult obj) { final Iterable<DetailedS3Object> detailedS3Objects = obj.getResult(); if (detailedS3Objects == null || Iterables.isEmpty(detailedS3Objects)) { return "No objects returned"; }/*from w w w. j av a2 s. co m*/ final ImmutableList<String> headers = ImmutableList.of("Name", "Bucket", "Owner", "Size", "Type", "Creation Date", "Tapes", "Pools"); return new CsvOutput<>(headers, detailedS3Objects, new CsvOutput.ContentFormatter<DetailedS3Object>() { @Override public Iterable<String> format(final DetailedS3Object content) { final ImmutableList.Builder<String> builder = ImmutableList.builder(); builder.add(nullGuard(content.getName())); builder.add(nullGuardToString(content.getBucketId())); builder.add(nullGuardToString(content.getOwner())); builder.add(nullGuardToString(content.getSize())); builder.add(nullGuardToString(content.getType())); builder.add(nullGuardFromDate(content.getCreationDate(), DATE_FORMAT)); builder.add(concatenateTapes(content.getBlobs())); builder.add(concatenatePools(content.getBlobs())); return builder.build(); } }).toString(); }
From source file:com.facebook.buck.parcelable.ParcelableClass.java
public ParcelableClass(String packageName, Iterable<String> imports, String className, String creatorClassName, String defaultFieldVisibility, Iterable<ParcelableField> fields, String superClassName, String rawSuperParams) {//from w w w. j a v a 2 s . c o m Preconditions.checkArgument(!Iterables.isEmpty(fields), "There must be fields, or else there is nothing to parcel."); boolean hasJsonAnnotations = false; for (ParcelableField field : fields) { if (field.getJsonProperty() != null) { hasJsonAnnotations = true; break; } } this.packageName = Preconditions.checkNotNull(packageName); ImmutableSortedSet.Builder<String> importsBuilder = ImmutableSortedSet.<String>naturalOrder() .addAll(imports).add("import android.os.Parcel;").add("import android.os.Parcelable;") // Lists is used to facilitate creating an array to pass to Parcel.readTypedList(). .add("import com.google.common.collect.Lists;"); if (hasJsonAnnotations) { importsBuilder.add("import com.fasterxml.jackson.annotation.JsonProperty;"); } this.imports = importsBuilder.build(); this.className = Preconditions.checkNotNull(className); this.creatorClassName = Preconditions.checkNotNull(creatorClassName); this.defaultFieldVisibility = Preconditions.checkNotNull(defaultFieldVisibility); this.fields = fields; this.superClassName = superClassName; this.rawSuperParams = rawSuperParams; }
From source file:org.apache.brooklyn.core.config.ConfigConstraints.java
/** * Checks all constraints of all config keys available to an entity adjunct. * <p>//ww w .j av a2 s . c o m * If a constraint is a {@link BrooklynObjectPredicate} then * {@link BrooklynObjectPredicate#apply(Object, BrooklynObject)} will be used. */ public static void assertValid(EntityAdjunct adjunct) { Iterable<ConfigKey<?>> violations = new EntityAdjunctConstraints(adjunct).getViolations(); if (!Iterables.isEmpty(violations)) { throw new ConstraintViolationException(errorMessage(adjunct, violations)); } }