Java源码示例:io.vavr.collection.Set
示例1
/**
* Returns all rights that a certain user, being a member of certain groups, has.
* If the user (or one of its groups) has the special "admin" right, this function always returns the complete set of rights.
* @param user The user to check
* @param userGroups Groups the user is in (in protobuf format, since that's typically where clustered apps will maintain them)
* @return all rights that the user, and all of its groups, have
*/
public Set<R> getRights(UUID userId, List<com.tradeshift.reaktive.protobuf.Types.UUID> userGroups) {
Set<R> set = HashSet.empty();
for (R right: rightsType.getEnumConstants()) {
if (isGranted(userId, userGroups, right)) {
set = set.add(right);
}
}
return set;
}
示例2
/**
* Returns a new ACL with the given change applied.
*/
public ACL<R,C> apply(C change) {
for (UUID target: builder.getTargetId(change)) {
Map<R,Set<UUID>> entries = this.entries;
for (R granted: builder.getGranted(change)) {
entries = entries.put(granted, entries.getOrElse(granted, HashSet.empty()).add(target));
}
for (R revoked: builder.getRevoked(change)) {
entries = entries.put(revoked, entries.getOrElse(revoked, HashSet.empty()).remove(target));
}
return (entries.eq(this.entries)) ? this : new ACL<>(builder, entries);
}
return this;
}
示例3
/** Asserts that we receive the given events, in any order, while permitting duplicates. */
private void assertReceiveOutOfOrder(Iterable<Envelope> events) {
long timeout = System.currentTimeMillis() + 5000;
Set<Envelope> received = HashSet.empty();
while (System.currentTimeMillis() < timeout && !received.containsAll(events)) {
received = received.add(materialized.expectMsgClass(Envelope.class));
}
assertThat(received).containsOnlyElementsOf(events);
}
示例4
@Test
public void demo() {
// Type-safe column identifiers
final StringColumnId NAME = StringColumnId.of("Name");
final CategoryColumnId COLOR = CategoryColumnId.of("Color");
final DoubleColumnId SERVING_SIZE = DoubleColumnId.of("Serving Size (g)");
// Convenient column creation
StringColumn nameColumn = StringColumn.ofAll(NAME, "Banana", "Blueberry", "Lemon", "Apple");
CategoryColumn colorColumn = CategoryColumn.ofAll(COLOR, "Yellow", "Blue", "Yellow", "Green");
DoubleColumn servingSizeColumn = DoubleColumn.ofAll(SERVING_SIZE, 118, 148, 83, 182);
// Grouping columns into a data frame
DataFrame dataFrame = DataFrame.ofAll(nameColumn, colorColumn, servingSizeColumn);
// Typed random access to individual values (based on rowIndex / columnId)
String lemon = dataFrame.getValueAt(2, NAME);
double appleServingSize = dataFrame.getValueAt(3, SERVING_SIZE);
// Typed stream-based access to all values
DoubleStream servingSizes = servingSizeColumn.valueStream();
double maxServingSize = servingSizes.summaryStatistics().getMax();
// Smart column implementations
Set<String> colors = colorColumn.getCategories();
}
示例5
@SuppressWarnings("unchecked")
@Override
Set<?> create(List<Object> result, DeserializationContext ctx) throws JsonMappingException {
if (io.vavr.collection.SortedSet.class.isAssignableFrom(collectionType.getRawClass())) {
checkContainedTypeIsComparable(ctx, collectionType.containedTypeOrUnknown(0));
return io.vavr.collection.TreeSet.ofAll((Comparator<Object> & Serializable) (o1, o2) -> ((Comparable) o1).compareTo(o2), result);
}
if (io.vavr.collection.LinkedHashSet.class.isAssignableFrom(collectionType.getRawClass())) {
return io.vavr.collection.LinkedHashSet.ofAll(result);
}
// default deserialization [...] -> Set
return HashSet.ofAll(result);
}
示例6
@SuppressWarnings("unchecked")
@Test
void test7() throws IOException {
Either<List<Integer>, Set<Double>> either = Either.left(List.of(42));
String json = mapper().writer().writeValueAsString(either);
Either<List<Integer>, Set<Double>> restored = mapper().readValue(json, new TypeReference<Either<List<Integer>, Set<Double>>>() {});
Assertions.assertEquals(either, restored);
}
示例7
@SuppressWarnings("unchecked")
@Test
void test8() throws IOException {
Either<List<Integer>, Set<Double>> either = Either.right(HashSet.of(42.0));
String json = mapper().writer().writeValueAsString(either);
Either<List<Integer>, Set<Double>> restored = mapper().readValue(json, new TypeReference<Either<List<Integer>, Set<Double>>>() {});
Assertions.assertEquals(either, restored);
}
示例8
@Test
void test1() throws IOException {
ObjectWriter writer = mapper().writer();
Set<?> src = of(1, 2, 5);
String json = writer.writeValueAsString(src);
Assertions.assertEquals(genJsonList(1, 2, 5), json);
Set<?> dst = mapper().readValue(json, typeReference());
Assertions.assertEquals(src, dst);
}
示例9
@Test
void test2() throws IOException {
ObjectMapper mapper = mapper().addMixIn(clz(), WrapperObject.class);
Set<?> src = of(1);
String plainJson = mapper().writeValueAsString(src);
String wrappedJson = mapper.writeValueAsString(src);
Assertions.assertEquals(wrappedJson, wrapToObject(clz().getName(), plainJson));
Set<?> restored = mapper.readValue(wrappedJson, typeReference());
Assertions.assertEquals(src, restored);
}
示例10
@Test
void test3() throws IOException {
ObjectMapper mapper = mapper().addMixIn(clz(), WrapperArray.class);
Set<?> src = of(1);
String plainJson = mapper().writeValueAsString(src);
String wrappedJson = mapper.writeValueAsString(src);
Assertions.assertEquals(wrappedJson, wrapToArray(clz().getName(), plainJson));
Set<?> restored = mapper.readValue(wrappedJson, typeReference());
Assertions.assertEquals(src, restored);
}
示例11
@Test
void test4() throws IOException {
VavrModule.Settings settings = new VavrModule.Settings();
settings.deserializeNullAsEmptyCollection(true);
ObjectMapper mapper = mapper(settings);
Set<?> restored = mapper.readValue("null", typeReference());
Assertions.assertTrue(restored.isEmpty());
}
示例12
@Test
void test6() throws IOException {
ObjectMapper mapper = mapper();
Set<?> restored = mapper.readValue("[]", typeReference());
Assertions.assertTrue(restored.isEmpty());
Assertions.assertTrue(clz().isAssignableFrom(restored.getClass()));
}
示例13
@Test
void testSerializable() throws IOException {
ObjectMapper mapper = mapper();
Set<?> src = of(1);
Set<?> restored = mapper.readValue(mapper.writeValueAsString(src), typeReference());
checkSerialization(restored);
}
示例14
@Test
@SuppressWarnings("unchecked")
void testJaxbXmlSerialization() throws IOException {
ObjectMapper mapper = xmlMapperJaxb();
String javaUtilValue = mapper.writeValueAsString(new JaxbXmlSerializeVavr().init((Set<Integer>) of(1, 2, 3)));
Assertions.assertEquals(mapper.writeValueAsString(new JaxbXmlSerializeJavaUtil().init(new java.util.HashSet<>(Arrays.asList(1, 2, 3)))), javaUtilValue);
JaxbXmlSerializeVavr restored = mapper.readValue(javaUtilValue, JaxbXmlSerializeVavr.class);
Assertions.assertEquals(restored.transitTypes.size(), 3);
}
示例15
@Test
@SuppressWarnings("unchecked")
void testXmlSerialization() throws IOException {
ObjectMapper mapper = xmlMapper();
String javaUtilValue = mapper.writeValueAsString(new XmlSerializeVavr().init((Set<Integer>) of(1, 2, 3)));
Assertions.assertEquals(mapper.writeValueAsString(new XmlSerializeJavaUtil().init(new java.util.HashSet<>(Arrays.asList(1, 2, 3)))), javaUtilValue);
XmlSerializeVavr restored = mapper.readValue(javaUtilValue, XmlSerializeVavr.class);
Assertions.assertEquals(restored.transitTypes.size(), 3);
}
示例16
@Test
public void givenJavaList_whenConverted_thenCorrect() {
java.util.List<Integer> javaList = java.util.Arrays.asList(1, 2, 3, 4);
List<Integer> vavrList = List.ofAll(javaList);
assertEquals(4, vavrList.size());
assertEquals(1, vavrList.head().intValue());
java.util.stream.Stream<Integer> javaStream = javaList.stream();
Set<Integer> vavrSet = HashSet.ofAll(javaStream);
assertEquals(4, vavrSet.size());
assertEquals(2, vavrSet.tail().head().intValue());
}
示例17
@Test
public void givenVavrList_whenCollected_thenCorrect() {
java.util.Set<Integer> javaSet = List.of(1, 2, 3)
.collect(Collectors.toSet());
assertEquals(3, javaSet.size());
assertEquals(1, javaSet.toArray()[0]);
}
示例18
@Test
public void givenParams_WhenVavarListConvertedToLinkedSet_thenReturnLinkedSet() {
List<String> vavrList = List.of("Java", "Haskell", "Scala", "Java");
Set<String> linkedSet = vavrList.toLinkedSet();
assertEquals(3, linkedSet.size());
assertTrue(linkedSet instanceof LinkedHashSet);
}
示例19
@GetMapping("/echo")
String echo(@RequestParam Set<String> set);
示例20
public Reimport(Set<String> entityIds) {
this.entityIds = entityIds;
}
示例21
/** Returns, per right, the set of users that have been granted that right. */
public Map<R,Set<UUID>> getGrantedUsers() {
return userAcl.getGranted();
}
示例22
/** Returns, per right, the set of groups that have been granted that right. */
public Map<R,Set<UUID>> getGrantedGroups() {
return groupAcl.getGranted();
}
示例23
protected ACL(ACLBuilder<R,C> builder, Map<R, Set<UUID>> entries) {
this.entries = entries;
this.builder = builder;
}
示例24
/** Returns all the rights granted in this ACL */
public Map<R,Set<UUID>> getGranted() {
return entries;
}
示例25
protected SelectedSubTagProtocol(Set<QName> names) {
this.names = names;
}
示例26
public Set<String> getCategories() {
return categories.toSet();
}
示例27
@Test
void test5() throws IOException {
ObjectMapper mapper = mapper();
Set<?> restored = mapper.readValue("null", typeReference());
Assertions.assertNull(restored);
}
示例28
public JaxbXmlSerializeVavr init(Set<Integer> slangSet) {
transitTypes = slangSet;
return this;
}
示例29
public JaxbXmlSerializeJavaUtil init(java.util.Set<Integer> javaSet) {
transitTypes = javaSet;
return this;
}
示例30
public XmlSerializeVavr init(Set<Integer> slangSet) {
transitTypes = slangSet;
return this;
}