public static <T> Iterable<T> $in(Optional<T> optional) { return optional.asSet(); }
public void testAsSet_presentIsImmutable() { Set<String> presentAsSet = Optional.of("a").asSet(); try { presentAsSet.add("b"); fail(); } catch (UnsupportedOperationException expected) { } }
public void testAsSet_absentIsImmutable() { Set<Object> absentAsSet = Optional.absent().asSet(); try { absentAsSet.add("foo"); fail(); } catch (UnsupportedOperationException expected) { } }
public void testAsSet_present() { Set<String> expected = Collections.singleton("a"); assertEquals(expected, Optional.of("a").asSet()); }
public void testAsSet_absent() { assertTrue("Returned set should be empty", Optional.absent().asSet().isEmpty()); }
@Memoized @Override Iterable<? extends RecursableDiffEntity> childEntities() { return breakdown().asSet(); }
@Memoized @Override Iterable<? extends RecursableDiffEntity> childEntities() { // Assemble the diffs in field number order so it most closely matches the schema. ImmutableList.Builder<RecursableDiffEntity> builder = ImmutableList.builderWithExpectedSize( singularFields().size() + repeatedFields().size() + unknownFields().asSet().size()); Set<Integer> fieldNumbers = Sets.union(singularFields().keySet(), repeatedFields().keySet()); for (int fieldNumber : Ordering.natural().sortedCopy(fieldNumbers)) { builder.addAll(singularFields().get(fieldNumber)); builder.addAll(repeatedFields().get(fieldNumber)); } builder.addAll(unknownFields().asSet()); return builder.build(); }
@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(); }
public void checkForAuthorization(SingularityRequest request, SingularityUser user, SingularityAuthorizationScope scope) { if (!authEnabled) { return; } checkForbidden(user.isAuthenticated(), "Not authenticated!"); final Set<String> readWriteGroups = Sets.union(request.getGroup().asSet(), request.getReadWriteGroups().or(Collections.emptySet())); final Set<String> readOnlyGroups = request.getReadOnlyGroups().or(defaultReadOnlyGroups); checkForAuthorization(user, readWriteGroups, readOnlyGroups, scope, Optional.of(request.getId())); }
/** * persist empty Optional of Date */ @Test public void nullDate() { final Jackson expected = ImmutableJackson.builder() .id(ObjectId.get()) .prop1("prop11") .prop2("prop22") .build(); repository.insert(expected).getUnchecked(); final Jackson actual = repository.findAll() .fetchAll().getUnchecked().get(0); check(expected.date().asSet()).isEmpty(); check(expected).is(actual); final BsonDocument doc = collection.find().first(); check(doc.keySet()).hasContentInAnyOrder("_id", "prop1", "prop2", "date", "uuid"); check(doc.get("date")).is(BsonNull.VALUE); }
authorizationHelper.checkForAuthorization( user, Sets.union(updateGroupsRequest.getGroup().asSet(), updateGroupsRequest.getReadWriteGroups()), updateGroupsRequest.getReadOnlyGroups(), SingularityAuthorizationScope.WRITE,
public boolean isAuthorizedForRequest(SingularityRequest request, SingularityUser user, SingularityAuthorizationScope scope) { if (!authEnabled) { return true; // no auth == no rules! } if (!user.isAuthenticated()) { return false; } final Set<String> userGroups = user.getGroups(); final Set<String> readWriteGroups = Sets.union(request.getGroup().asSet(), request.getReadWriteGroups().or(Collections.<String>emptySet())); final Set<String> readOnlyGroups = request.getReadOnlyGroups().or(defaultReadOnlyGroups); final boolean userIsAdmin = !adminGroups.isEmpty() && groupsIntersect(userGroups, adminGroups); final boolean userIsJITA = !jitaGroups.isEmpty() && groupsIntersect(userGroups, jitaGroups); final boolean userIsReadWriteUser = readWriteGroups.isEmpty() || groupsIntersect(userGroups, readWriteGroups); final boolean userIsReadOnlyUser = groupsIntersect(userGroups, readOnlyGroups) || (!globalReadOnlyGroups.isEmpty() && groupsIntersect(userGroups, globalReadOnlyGroups)); final boolean userIsPartOfRequiredGroups = requiredGroups.isEmpty() || groupsIntersect(userGroups, requiredGroups); if (userIsAdmin) { return true; // Admins Rule Everything Around Me } else if (scope == SingularityAuthorizationScope.READ) { return (userIsReadOnlyUser || userIsReadWriteUser || userIsJITA) && userIsPartOfRequiredGroups; } else if (scope == SingularityAuthorizationScope.WRITE) { return (userIsReadWriteUser || userIsJITA) && userIsPartOfRequiredGroups; } else { return false; } }
@Override public ImmutableSet<String> getRequiredJsLibNames() { return ImmutableSet.<String>builder() .addAll(bidiGlobalDirProvider.get().getNamespace().asSet()) .add("soy") .build(); }
private void applyCriteriaIfPresent(final SearchCriteriaBuilder scb, final Optional<SearchCriterion> criteria) { for (SearchCriterion searchCriterion : criteria.asSet()) { scb.add(searchCriterion); } }
private List<PreferenceValue> getPreferenceValuesFrom(String preferences) { List<PreferenceValue> preferenceValues = Lists.newArrayList(); if (StringUtils.isNotEmpty(preferences)) { List<String> arguments = split(preferences, ";"); for(String argument : arguments) { preferenceValues.addAll(convertToPreferenceValue(argument).asSet()); } } return preferenceValues; }
@Override public List<TestOutcome> loadReportsFrom(File outputDirectory) { File[] reportFiles = getAllJsonFilesFrom(outputDirectory); List<TestOutcome> testOutcomes = Lists.newArrayList(); if (reportFiles != null) { for (File reportFile : reportFiles) { testOutcomes.addAll(loadReportFrom(reportFile).asSet()); } } return testOutcomes; }
@Override public List<TestOutcome> loadReportsFrom(File outputDirectory) { File[] reportFiles = getAllJsonFilesFrom(outputDirectory); List<TestOutcome> testOutcomes = Lists.newArrayList(); if (reportFiles != null) { for (File reportFile : reportFiles) { testOutcomes.addAll(loadReportFrom(reportFile).asSet()); } } return testOutcomes; }
@Override public List<TestSuite> loadFrom(final File xUnitReport) throws IOException { List<TestSuite> testSuites = Lists.newArrayList(); Document doc = parseDocument(xUnitReport); NodeList testSuiteElements = doc.getElementsByTagName("testsuite"); shouldHaveAtLeastOneTestSuite(testSuiteElements, xUnitReport); for (int i = 0; i < testSuiteElements.getLength(); i++) { Optional<TestSuite> testSuite = testSuiteFrom(testSuiteElements.item(i)); testSuites.addAll(testSuite.asSet()); } return testSuites; }
private void applyProductCriteria(final TechnologyRawInputProductComponentsCriteria criteria, final SearchCriteriaBuilder scb) { for (SearchCriterion searchCriterion : criteria.getProductCriteria().asSet()) { scb.createCriteria(OperationProductInComponentFields.PRODUCT, "prod_alias", JoinType.INNER).add(searchCriterion); } }