private <T> Dumper<T> findDumper(final T target, final ImmutableMap<Class<? extends T>, Dumper<T>> dumperClasses) { Optional<Class<? extends T>> dumpClass = from(dumperClasses.keySet()).firstMatch(isInstance(target)); if (dumpClass.isPresent()) { return dumperClasses.get(dumpClass.get()); } throw new IllegalArgumentException("Unknown target type:" + target.getClass()); }
public void testFirstMatch() { FluentIterable<String> iterable = FluentIterable.from(Lists.newArrayList("cool", "pants")); assertThat(iterable.firstMatch(Predicates.equalTo("cool"))).hasValue("cool"); assertThat(iterable.firstMatch(Predicates.equalTo("pants"))).hasValue("pants"); assertThat(iterable.firstMatch(Predicates.alwaysFalse())).isAbsent(); assertThat(iterable.firstMatch(Predicates.alwaysTrue())).hasValue("cool"); }
private Optional<Parameter> getBodyParameter(final List<Parameter> given) { final List<Parameter> allParams = new ArrayList<Parameter>(given); return FluentIterable.from(allParams).firstMatch(new Predicate<Parameter>() { @Override public boolean apply(final Parameter input) { return input.getParameterType() == ParameterType.BODY; } }); }
@Override public GResponse get() { return FluentIterable.from(method.responses()).firstMatch(findByCode("201")).orNull(); } });
private static MajorFragmentProfile findFragmentProfileWithId(QueryProfile profile, final int id) { return FluentIterable.from(profile.getFragmentProfileList()).firstMatch(new Predicate<MajorFragmentProfile>() { @Override public boolean apply(@Nullable MajorFragmentProfile input) { return input.getMajorFragmentId() == id; } }).get(); }
@Override public Optional<IProject> findProjectByName(final String name) { return FluentIterable.from(getAllProjects()).firstMatch(new Predicate<IProject>() { @Override public boolean apply(IProject project) { return project.getName().equals(name); } }); }
private static OperatorProfile findOperatorProfileWithId(MinorFragmentProfile minorFragmentProfile, final int id) { return FluentIterable.from(minorFragmentProfile.getOperatorProfileList()).firstMatch(new Predicate<OperatorProfile>() { @Override public boolean apply(OperatorProfile input) { return input.getOperatorId() == id; } }).get(); } private static long findMetric(OperatorProfile operatorProfile, final int id) {
private Optional<ExecutableElement> extractEventTypeMethodAccessor(List<? extends Element> members) { return FluentIterable.from(methodsIn(members)) .firstMatch(method -> method.getSimpleName().contentEquals("getType") && method.getParameters().isEmpty() && isGwtEventType(method, method.getReturnType())); }
public ResolvedType alternateFor(ResolvedType type) { Optional<AlternateTypeRule> matchingRule = FluentIterable.from(rules) .firstMatch(thatAppliesTo(type)); if (matchingRule.isPresent()) { return matchingRule.get().alternateFor(type); } return type; }
public ResolvedType alternateFor(ResolvedType type) { Optional<AlternateTypeRule> matchingRule = FluentIterable.from(rules) .firstMatch(thatAppliesTo(type)); if (matchingRule.isPresent()) { return matchingRule.get().alternateFor(type); } return type; }
private static long findMetric(OperatorProfile operatorProfile, final int id) { return FluentIterable.from(operatorProfile.getMetricList()).firstMatch(new Predicate<MetricValue>() { @Override public boolean apply(@Nullable MetricValue input) { return input.getMetricId() == id; } }).get().getLongValue(); }
public static Optional<BeanPropertyDefinition> jacksonPropertyWithSameInternalName(BeanDescription beanDescription, BeanPropertyDefinition propertyDefinition) { return FluentIterable.from(beanDescription.findProperties()) .firstMatch(withSameInternalName(propertyDefinition)); }
private Optional<org.jclouds.openstack.neutron.v2.domain.FloatingIP> tryFindExistingFloatingIp(org.jclouds.openstack.neutron.v2.features.FloatingIPApi neutronFloatingApi, final String availabilityZone) { Optional<org.jclouds.openstack.neutron.v2.domain.FloatingIP> floatingIPOptional = neutronFloatingApi.list().concat().firstMatch(new Predicate<org.jclouds.openstack.neutron.v2.domain.FloatingIP>() { @Override public boolean apply(@Nullable org.jclouds.openstack.neutron.v2.domain.FloatingIP input) { return input.getPortId() == null && input.getAvailabilityZone().equals(availabilityZone); } }); return floatingIPOptional; }
@Override public TypeDeclaration fetchType(Api api, final String name) throws GenerationException { return FluentIterable.from(Optional.fromNullable(foundInApi).or(FluentIterable.from(api.types()).append(Utils.goThroughLibraries(new ArrayList<TypeDeclaration>(), new HashSet<String>(), api.uses())))) .firstMatch(namedPredicate(name)).or(fail(name)); }
@Override public boolean apply(Changeset input) { Optional<Changeset> persistedChangeset = from(persistedChangesets).firstMatch(BY_ID(input.getId(), input.getAuthor())); return persistedChangeset.isPresent() && !input.getChecksum().equals(persistedChangeset.get().getChecksum()); } }
protected Optional<RoundRobinPool> getPoolById(final String poolId) { return api(zoneName).list().firstMatch(new Predicate<RoundRobinPool>() { public boolean apply(RoundRobinPool in) { return in.getId().equals(poolId); } }); }
protected Optional<DirectionalPool> getPoolById(final String cnamePoolId) { return api.getDirectionalPoolApiForZone(zoneName) .list() .firstMatch(new Predicate<DirectionalPool>() { public boolean apply(DirectionalPool in) { return in.getId().equals(cnamePoolId); } }); }
@Override public Hardware apply(ServerSpec spec) { Location location = FluentIterable.from(locations.get()).firstMatch(idEquals(spec.getDatacenter())).orNull(); assert location != null : String.format("no location matched ServerSpec %s", spec); return new HardwareBuilder().ids(spec.toString()).ram(spec.getMemorySizeMB()).processors( ImmutableList.of(new Processor(spec.getCpuCores(), 1.0))).volumes( ImmutableList.<Volume> of(new VolumeImpl((float) spec.getDiskSizeGB(), true, true))).hypervisor( spec.getPlatform()).location(location).supportsImage( ImagePredicates.idEquals(spec.getTemplateName())).build(); } }
protected Optional<Zone> getZoneByName(final String zoneName) { return api.getZoneApi().listByAccount(account.getId()).firstMatch(new Predicate<Zone>() { public boolean apply(Zone in) { return in.getName().equals(zoneName); } }); }
protected Optional<DirectionalPoolRecordDetail> getRecordByDNameAndId(String dname, String recordId) { return api.getDirectionalPoolApiForZone(zoneName) .listRecordsByDNameAndType(dname, IPV4.getCode()) .firstMatch(recordIdEqualTo(recordId)); }