public void testSkip_simple() { Collection<String> set = ImmutableSet.of("a", "b", "c", "d", "e"); assertEquals( Lists.newArrayList("c", "d", "e"), Lists.newArrayList(FluentIterable.from(set).skip(2))); assertEquals("[c, d, e]", FluentIterable.from(set).skip(2).toString()); }
private void createAppMasterRole(String appId, String operator) { Set<Permission> appPermissions = FluentIterable.from(Lists.newArrayList( PermissionType.CREATE_CLUSTER, PermissionType.CREATE_NAMESPACE, PermissionType.ASSIGN_ROLE)) .transform(permissionType -> createPermission(appId, permissionType, operator)).toSet(); Set<Permission> createdAppPermissions = rolePermissionService.createPermissions(appPermissions); Set<Long> appPermissionIds = createdAppPermissions.stream().map(BaseEntity::getId).collect(Collectors.toSet()); //create app master role Role appMasterRole = createRole(RoleUtils.buildAppMasterRoleName(appId), operator); rolePermissionService.createRoleWithPermissions(appMasterRole, appPermissionIds); }
@Override protected Optional<String[]> doExtract(final HttpRequest request) { String[] extractedValues = from(request.getHeaders().entrySet()) .filter(isForHeaderName(name)) .transform(toValue()) .transformAndConcat(arrayAsIterable()) .toArray(String.class); if (extractedValues.length > 0) { return of(extractedValues); } return absent(); }
/** * Applies {@code function} to each element of this fluent iterable and returns a fluent iterable * with the concatenated combination of results. {@code function} returns an Iterable of results. * * <p>The returned fluent iterable's iterator supports {@code remove()} if this function-returned * iterables' iterator does. After a successful {@code remove()} call, the returned fluent * iterable no longer contains the corresponding element. * * <p><b>{@code Stream} equivalent:</b> {@link Stream#flatMap} (using a function that produces * streams, not iterables). * * @since 13.0 (required {@code Function<E, Iterable<T>>} until 14.0) */ public <T> FluentIterable<T> transformAndConcat( Function<? super E, ? extends Iterable<? extends T>> function) { return FluentIterable.concat(transform(function)); }
public void testFilterWhenResponseIs404() throws Exception { HttpResponse filterResponse = HttpResponse.builder().statusCode(404).build(); EC2Api apiWhenDontExist = requestSendsResponse(filter, filterResponse); assertEquals(apiWhenDontExist.getTagApi().get().filter(ImmutableMultimap.<String, String> builder() .put("resource-type", "instance") .put("key", "stack") .build()).toSet(), ImmutableSet.of()); }
public void testTransformWith_nullFriendlyTransform() { List<Integer> input = asList(1, 2, null, 3); Iterable<String> result = FluentIterable.from(input).transform(new StringValueOfFunction()); assertEquals(asList("1", "2", "null", "3"), Lists.newArrayList(result)); }
@Value.Lazy List<TypeElement> includedTypes() { Optional<IncludeMirror> includes = include(); ImmutableList<TypeMirror> typeMirrors = includes.isPresent() ? ImmutableList.copyOf(includes.get().valueMirror()) : ImmutableList.<TypeMirror>of(); FluentIterable<TypeElement> typeElements = FluentIterable.from(typeMirrors) .filter(DeclaredType.class) .transform(DeclatedTypeToElement.FUNCTION); ImmutableSet<String> uniqueTypeNames = typeElements .filter(IsPublic.PREDICATE) .transform(ElementToName.FUNCTION) .toSet(); if (uniqueTypeNames.size() != typeMirrors.size()) { report().annotationNamed(IncludeMirror.simpleName()) .warning(About.INCOMPAT, "Some types were ignored, non-supported for inclusion: duplicates," + " non declared reference types, non-public"); } return typeElements.toList(); }
public void testFilter() { FluentIterable<String> filtered = FluentIterable.from(asList("foo", "bar")).filter(Predicates.equalTo("foo")); List<String> expected = Collections.singletonList("foo"); List<String> actual = Lists.newArrayList(filtered); assertEquals(expected, actual); assertCanIterateAgain(filtered); assertEquals("[foo]", filtered.toString()); }
public void testTransformAndConcat() { List<Integer> input = asList(1, 2, 3); Iterable<String> result = FluentIterable.from(input).transformAndConcat(new RepeatedStringValueOfFunction()); assertEquals(asList("1", "1", "2", "2", "3", "3"), Lists.newArrayList(result)); }
public void testSkip_nonStructurallyModifiedList() throws Exception { List<String> list = Lists.newArrayList("a", "b", "c"); FluentIterable<String> tail = FluentIterable.from(list).skip(1); Iterator<String> tailIterator = tail.iterator(); list.set(2, "c2"); assertEquals("b", tailIterator.next()); assertEquals("c2", tailIterator.next()); assertFalse(tailIterator.hasNext()); }
public void testLimit() { Iterable<String> iterable = Lists.newArrayList("foo", "bar", "baz"); FluentIterable<String> limited = FluentIterable.from(iterable).limit(2); assertEquals(ImmutableList.of("foo", "bar"), Lists.newArrayList(limited)); assertCanIterateAgain(limited); assertEquals("[foo, bar]", limited.toString()); }
public void testSkip_structurallyModifiedSkipSome() throws Exception { Collection<String> set = Sets.newLinkedHashSet(); Collections.addAll(set, "a", "b", "c"); FluentIterable<String> tail = FluentIterable.from(set).skip(1); set.remove("b"); set.addAll(Lists.newArrayList("X", "Y", "Z")); assertThat(tail).containsExactly("c", "X", "Y", "Z").inOrder(); }
public void testFromArray() { assertEquals( ImmutableList.of("1", "2", "3", "4"), Lists.newArrayList(FluentIterable.from(new Object[] {"1", "2", "3", "4"}))); }
public void testToList() { assertEquals(Lists.newArrayList(1, 2, 3, 4), fluent(1, 2, 3, 4).toList()); }
@Value.Derived @Value.Auxiliary public Set<EncodingInfo> encodings() { if (qualifiedName().endsWith("Enabled") || CustomImmutableAnnotations.annotations().contains(qualifiedName()) || style().isPresent()) { // See if it is encoding enabled itself Optional<EncodingInfo> encoding = EncMetadataMirror.find(element()).transform(ENCODING_INFLATER); if (encoding.isPresent()) { return encoding.asSet(); } // trying to find it as meta-meta annotation List<EncodingInfo> result = new ArrayList<>(); for (AnnotationMirror m : element().getAnnotationMirrors()) { MetaAnnotated metaAnnotated = MetaAnnotated.from(m, environment()); result.addAll(metaAnnotated.encodings()); } if (!result.isEmpty()) { return FluentIterable.from(result).toSet(); } } return ImmutableSet.of(); }
@Test public void test() { InputStream is = getClass().getResourceAsStream("/records_by_name_and_type.xml"); FluentIterable<ResourceRecordDetail> expected = expected(); ResourceRecordListHandler handler = injector.getInstance(ResourceRecordListHandler.class); FluentIterable<ResourceRecordDetail> result = factory.create(handler).parse(is); assertEquals(result.toList().toString(), expected.toList().toString()); }
Assert.assertEquals(pPartitions.size(), 4); Assert.assertEquals(rPartitions.size(), 4); Optional.of(PathUtils.combinePaths(RetentionIntegrationTest.TEST_PACKAGE_RESOURCE_NAME, "testHiveTimeBasedRetention", "jobProps.properties")), testTempPath); if (isReplacementTest) { Assert.assertEquals(pPartitions.size(), 4); expectedRetainedPartitions = new String[] { getQlPartition(purgedTbl, pRetained1).getName(), assertThat(FluentIterable.from(pPartitions).transform(new Function<Partition, String>() { @Override public String apply(Partition input) { return getQlPartition(purgedTbl, input).getName(); }).toList(), containsInAnyOrder(expectedRetainedPartitions));
private Optional<ResponseHandler> getGetHandler(final HttpRequest httpRequest) { Optional<ResponseHandler> matchedSetting = getSingleOrAllHandler(httpRequest, getSingleSettings, getAllSettings, name); if (matchedSetting.isPresent()) { return matchedSetting; } if (allMatcher.match(httpRequest)) { FluentIterable<RestSingleSetting> settings = FluentIterable.from(getSingleSettings.getSettings()); if (!settings.isEmpty() && settings.allMatch(isJsonHandlers())) { ImmutableList<Object> objects = settings .transform(toJsonHandler()) .transform(toPojo()).toList(); return of(with(Moco.json(objects))); } } return of(NOT_FOUND_HANDLER); }