/** @since 18.0 */ // @Override on JDK8 public <A extends Annotation> @Nullable A getDeclaredAnnotation(Class<A> annotationType) { checkNotNull(annotationType); return FluentIterable.from(annotations).filter(annotationType).first().orNull(); }
@Override public Optional<T> apply(List<T> input) { return FluentIterable.from(input).first(); } });
/** @since 18.0 */ // @Override on JDK8 @NullableDecl public <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationType) { checkNotNull(annotationType); return FluentIterable.from(annotations).filter(annotationType).first().orNull(); }
/** @since 18.0 */ // @Override on JDK8 @NullableDecl public <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationType) { checkNotNull(annotationType); return FluentIterable.from(annotations).filter(annotationType).first().orNull(); }
/** * Used by Governance */ @CheckForNull public ViewsSnapshotDto selectSnapshotBefore(String componentUuid, long date, DbSession dbSession) { return from(mapper(dbSession).selectSnapshotBefore(componentUuid, date)) .first() .orNull(); }
@SuppressWarnings("unused") // compilation test public void testSampleCodeError2() { FluentIterable<? extends Number> numbers = getSomeNumbers(); Optional<? extends Number> first = numbers.first(); // Number value = first.or(0.5); // error }
public void testFirst_list() { List<String> list = Lists.newArrayList("a", "b", "c"); assertThat(FluentIterable.from(list).first()).hasValue("a"); }
public void testFirst_emptyList() { List<String> list = Collections.emptyList(); assertThat(FluentIterable.from(list).first()).isAbsent(); }
public void testFirst_iterable() { Set<String> set = ImmutableSet.of("a", "b", "c"); assertThat(FluentIterable.from(set).first()).hasValue("a"); }
@SuppressWarnings("unused") // compilation test public void testSampleCodeFine2() { FluentIterable<? extends Number> numbers = getSomeNumbers(); // Sadly, the following is what users will have to do in some circumstances. @SuppressWarnings("unchecked") // safe covariant cast Optional<Number> first = (Optional) numbers.first(); Number value = first.or(0.5); // fine }
public void testFirst_null() { List<String> list = Lists.newArrayList(null, "a", "b"); try { FluentIterable.from(list).first(); fail(); } catch (NullPointerException expected) { } }
public void testFirst_emptyIterable() { Set<String> set = Sets.newHashSet(); assertThat(FluentIterable.from(set).first()).isAbsent(); }
private Measure getSomeMeasureByValueType(final Metric.MetricType metricType) { return from(MEASURES).filter(new Predicate<Measure>() { @Override public boolean apply(@Nullable Measure input) { return input.getValueType() == metricType.getValueType(); } }).first().get(); }
public void testFirst_emptySortedSet() { SortedSet<String> sortedSet = ImmutableSortedSet.of(); assertThat(FluentIterable.from(sortedSet).first()).isAbsent(); }
public void testFirst_sortedSet() { SortedSet<String> sortedSet = ImmutableSortedSet.of("b", "c", "a"); assertThat(FluentIterable.from(sortedSet).first()).hasValue("a"); }
/** * Applies to a node of type either DIRECTORY or FILE */ private static void setParentModuleProperties(ComponentDto componentDto, PathAwareVisitor.Path<ComponentDtoHolder> path) { componentDto.setProjectUuid(path.root().getDto().uuid()); ComponentDto parentModule = from(path.getCurrentPath()) .filter(ParentModulePathElement.INSTANCE) .first() .get() .getElement().getDto(); componentDto.setUuidPath(formatUuidPathFromParent(path.parent().getDto())); componentDto.setRootUuid(parentModule.uuid()); componentDto.setModuleUuid(parentModule.uuid()); componentDto.setModuleUuidPath(parentModule.moduleUuidPath()); }
root = FluentIterable.from(groups.values()).first().orNull();
ParameterizedBehaviorTestRunner(TestWithParameters test) throws InitializationError { super(test); FeatureSet features = FluentIterable .from(test.getParameters()) .filter(FeatureSet.class) .first() .orNull(); checkState(features != null, "No FeatureSet parameter found"); // JDK-8 bug: Cannot use `super::` if the superclass method is protected; see // https://bugs.openjdk.java.net/browse/JDK-8139836 testing = new SharedBehaviorTesting( notifier -> super.childrenInvoker(notifier), (method, notifier) -> super.runChild(method, notifier), super::createTest, super::getDescription, super::getTestClass, (cls, name) -> Description.createTestDescription(cls, name + test.getParameters()), features); }
private static String messageFor(final Throwable ex) { final List<Throwable> chain = Throwables.getCausalChain(ex); final Optional<RecoverableException> recoverableIfAny = FluentIterable.from(chain).filter(RecoverableException.class).first(); return (recoverableIfAny.isPresent() ? recoverableIfAny.get() : ex).getMessage(); }
private Optional<OperatingSystem> tryExtractOperatingSystemFrom(VirtualGuestBlockDeviceTemplateGroup image) { if (image.getGlobalIdentifier() == null) return Optional.absent(); return FluentIterable.from(image.getChildren()) .transformAndConcat(new BlockDeviceTemplateGroupToBlockDeviceTemplateIterable()) .filter(new IsBootableDevice()) .transformAndConcat(new BlockDeviceTemplateToDiskImageSoftware()) .transform(new DiskImageSoftwareToSoftwareDescription()) .filter(new IsOperatingSystem()) .transform(new SoftwareDescriptionToOperatingSystem(image.getGlobalIdentifier())) .first(); }