List of usage examples for com.google.common.collect Iterables isEmpty
public static boolean isEmpty(Iterable<?> iterable)
From source file:nz.co.testamation.common.contract.Conditions.java
public static <T> T notEmpty(T obj) { if (obj instanceof CharSequence && StringUtils.isBlank((CharSequence) obj)) { throw new IllegalStateException("Expected char sequence to not be empty"); }/* w w w. j a v a 2 s. co m*/ if (obj instanceof Iterable && Iterables.isEmpty((Iterable<?>) obj)) { throw new IllegalStateException("Expected iterable to not be empty"); } return Conditions.notNull(obj); }
From source file:org.apache.aurora.common.args.constraints.NotEmptyIterableVerifier.java
@Override public void verify(Iterable<?> value, Annotation annotation) { checkArgument(!Iterables.isEmpty(value), "Value must not be empty."); }
From source file:org.apache.aurora.scheduler.filter.ConstraintMatcher.java
/** * Gets the veto (if any) for a scheduling constraint based on the {@link AttributeAggregate} this * filter was created with.// w ww .j a va 2 s . c o m * * @param constraint Scheduling filter to check. * @return A veto if the constraint is not satisfied based on the existing state of the job. */ static Optional<Veto> getVeto(AttributeAggregate cachedjobState, Iterable<IAttribute> hostAttributes, IConstraint constraint) { Iterable<IAttribute> sameNameAttributes = Iterables.filter(hostAttributes, new NameFilter(constraint.getName())); Optional<IAttribute> attribute; if (Iterables.isEmpty(sameNameAttributes)) { attribute = Optional.absent(); } else { Set<String> attributeValues = ImmutableSet .copyOf(Iterables.concat(Iterables.transform(sameNameAttributes, GET_VALUES))); attribute = Optional.of(IAttribute.build(new Attribute(constraint.getName(), attributeValues))); } ITaskConstraint taskConstraint = constraint.getConstraint(); switch (taskConstraint.getSetField()) { case VALUE: boolean matches = AttributeFilter.matches(attribute.transform(GET_VALUES).or(ImmutableSet.of()), taskConstraint.getValue()); return matches ? Optional.absent() : Optional.of(Veto.constraintMismatch(constraint.getName())); case LIMIT: if (!attribute.isPresent()) { return Optional.of(Veto.constraintMismatch(constraint.getName())); } boolean satisfied = AttributeFilter.matches(attribute.get(), taskConstraint.getLimit().getLimit(), cachedjobState); return satisfied ? Optional.absent() : Optional.of(Veto.unsatisfiedLimit(constraint.getName())); default: throw new SchedulerException( "Failed to recognize the constraint type: " + taskConstraint.getSetField()); } }
From source file:org.eclipse.sirius.diagram.ui.tools.internal.graphical.edit.part.DDiagramHelper.java
/** * Find the parent diagram./* w w w . j a va 2s .c om*/ * * @param element * Edit part. * @return The parent diagram or <code>null</code> if not found. */ public static IDDiagramEditPart findParentDiagram(final EditPart element) { IDDiagramEditPart result = null; if (element instanceof IDDiagramEditPart) { result = (IDDiagramEditPart) element; } else if (element instanceof DDiagramRootEditPart) { Iterable<IDDiagramEditPart> ddiagramChildren = Iterables.filter(element.getChildren(), IDDiagramEditPart.class); if (!Iterables.isEmpty(ddiagramChildren)) { result = ddiagramChildren.iterator().next(); } } else if (element != null) { result = DDiagramHelper.findParentDiagram(element.getParent()); } return result; }
From source file:org.eclipse.emf.eson.scoping.SimpleEPackageScope.java
@Override public Iterable<IEObjectDescription> getElements(EObject object) { Iterable<IEObjectDescription> result = super.getElements(object); if (Iterables.isEmpty(result) && (object instanceof EPackage)) { final EPackage ePackage = (EPackage) object; Iterable<IEObjectDescription> localElements = getLocalElementsByEClass(EcorePackage.Literals.EPACKAGE); result = Iterables.filter(localElements, new Predicate<IEObjectDescription>() { @Override// w w w . j av a2 s. c om public boolean apply(IEObjectDescription input) { return input.getQualifiedName().getFirstSegment().equals(ePackage.getNsURI()); } }); } return result; }
From source file:org.gradle.internal.fingerprint.impl.DefaultCurrentFileCollectionFingerprint.java
public static CurrentFileCollectionFingerprint from(Iterable<FileSystemSnapshot> roots, FingerprintingStrategy strategy) { if (Iterables.isEmpty(roots)) { return strategy.getIdentifier().getEmptyFingerprint(); }/*w ww. j av a 2 s . co m*/ Map<String, FileSystemLocationFingerprint> snapshots = strategy.collectFingerprints(roots); if (snapshots.isEmpty()) { return strategy.getIdentifier().getEmptyFingerprint(); } return new DefaultCurrentFileCollectionFingerprint(snapshots, strategy.getCompareStrategy(), strategy.getIdentifier(), roots); }
From source file:com.twitter.hbc.core.HttpHosts.java
/** * All httpHosts must start with the http scheme("http:// or https://") *//*from w w w .j a v a2s . c o m*/ public HttpHosts(Iterable<String> addresses) { Preconditions.checkNotNull(addresses); Preconditions.checkArgument(!Iterables.isEmpty(addresses)); for (String address : addresses) { if (!address.toLowerCase().startsWith(HttpConstants.HTTP_SCHEME + "://") && !address.toLowerCase().startsWith(HttpConstants.HTTPS_SCHEME + "://")) { throw new IllegalArgumentException("Address doesn't have an http scheme: " + address); } } List<String> copy = Lists.newArrayList(addresses); Collections.shuffle(copy); this.hosts = Iterators.cycle(copy); }
From source file:com.bigfatgun.fixjures.dao.FakeService.java
public void deleteObjectWithLowestBalance() { List<MyBusinessObject> businessObjectList = dao.findAllOrderedByAccountBalance(); if (!Iterables.isEmpty(businessObjectList)) { dao.delete(businessObjectList.iterator().next()); }//from w ww . j av a2 s . c o m }
From source file:org.tensorics.core.booleans.operations.And.java
@Override public Boolean apply(Iterable<Boolean> booleanList) { if (Iterables.isEmpty(booleanList)) { throw new NoSuchElementException("Cannot perform a logical AND with no elements"); }/*from ww w . ja v a 2s . co m*/ return stream(booleanList.spliterator(), false).allMatch(TRUE::equals); }
From source file:com.vilt.minium.impl.WaitPredicates.java
/** * Predicate to use with {@link WaitWebElements#wait(Predicate)} methods which ensures that * evaluation will only be successful when this instance is not empty (that is, evaluates * to one or more {@link WebElement} instances. * * @param <T> the generic type// w ww . j ava2s. com * @return predicate that returns true if it is empty */ public static <T extends WebElements> Predicate<T> whileEmpty() { return new Predicate<T>() { @Override public boolean apply(T input) { return !Iterables.isEmpty(input); } @Override public String toString() { return "whileEmpty()"; } }; }