/** * Transforms list of Eithers into two lists, which contains left and right values. */ public static <L, R> Pair<List<L>, List<R>> splitEithers(final Iterable<Either<L, R>> eithers) { return Pair.<List<L>, List<R>>pair( ImmutableList.copyOf(Eithers.filterLeft(eithers)), ImmutableList.copyOf(Eithers.filterRight(eithers)) ); } }
@Override public Either<ErrorCollection, Collection<PermissionGrantInput>> fromBean(final List<PermissionGrantBean> permissions) { return sequenceRight(transform(firstNonNull(permissions, Collections.<PermissionGrantBean>emptyList()), new Function<PermissionGrantBean, Either<ErrorCollection, PermissionGrantInput>>() { @Override public Either<ErrorCollection, PermissionGrantInput> apply(final PermissionGrantBean grantBean) { return fromBean(grantBean); } })).map(new Function<Iterable<PermissionGrantInput>, Collection<PermissionGrantInput>>() { @Override public Collection<PermissionGrantInput> apply(final Iterable<PermissionGrantInput> grants) { return ImmutableList.copyOf(grants); } }); }
private <T> T raiseExceptionOnError(final Either<AttachmentError, T> result) throws AttachmentException { return Eithers.getOrThrow(result.left().map(new Function<AttachmentError, AttachmentException>() { @Override public AttachmentException apply(final AttachmentError attachmentError) { return new AttachmentException(String.format("Got error while saving attachment %s: %s", attachmentError.getFilename(), attachmentError.getLogMessage()), attachmentError.getException().getOrNull()); } })); }
public static AvailableProjectsBean create(final JiraProxyFactory proxyFactory, final String issueId, Iterable<Either<NegativeResponseStatus, Projects>> projects) { Preconditions.checkNotNull(proxyFactory); Preconditions.checkNotNull(issueId); Preconditions.checkNotNull(projects); return new AvailableProjectsBean(Iterables.transform(Eithers.filterRight(projects), new ProjectsToProjectGroupBean()), RemoteFailuresBean.create(proxyFactory, issueId, Eithers.filterLeft(projects))); }
final List<String> nonValidKeysMessages = ImmutableList.copyOf(Iterables.transform(Eithers.filterLeft (applicationKeys), new Function<String, String>() createUserRequest = createUserRequest.withApplicationAccess(ImmutableSet.copyOf(Eithers.filterRight(applicationKeys)));