本文整理汇总了Java中org.pcollections.POrderedSet类的典型用法代码示例。如果您正苦于以下问题:Java POrderedSet类的具体用法?Java POrderedSet怎么用?Java POrderedSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
POrderedSet类属于org.pcollections包,在下文中一共展示了POrderedSet类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBehavesLikePSet
import org.pcollections.POrderedSet; //导入依赖的package包/类
public void testBehavesLikePSet() {
PSet<Integer> s = Empty.set();
POrderedSet<Integer> os = Empty.orderedSet();
Random r = new Random();
for (int i = 0; i < 100000; i++) {
int v = r.nextInt(1000);
if (r.nextFloat() < 0.8) {
s = s.plus(v);
os = os.plus(v);
} else {
s = s.minus(v);
os = os.minus(v);
}
}
assertEquals(s, os);
}
示例2: getFavorites
import org.pcollections.POrderedSet; //导入依赖的package包/类
@Override
public ServiceCall<NotUsed, POrderedSet<String>> getFavorites(String userId) {
return notUsed -> {
CompletionStage<GetFavoritesReply> favorites =
favoriteEntityRef(userId).ask(GetFavorites.of());
return favorites.thenApply(rep -> rep.getFavoriteIds());
};
}
示例3: shouldBeAbleToAddAndDeleteFavorites
import org.pcollections.POrderedSet; //导入依赖的package包/类
@Test
public void shouldBeAbleToAddAndDeleteFavorites() throws Exception {
FavoriteService favoriteService = server.client(FavoriteService.class);
FavoriteId fav1 = FavoriteId.of("favorite-A-1");
favoriteService.addFavorite("user-A").invoke(fav1).toCompletableFuture().get(10, SECONDS);
FavoriteId fav2 = FavoriteId.of("favorite-A-2");
favoriteService.addFavorite("user-A").invoke(fav2).toCompletableFuture().get(3, SECONDS);
FavoriteId fav3 = FavoriteId.of("favorite-B-1");
favoriteService.addFavorite("user-B").invoke(fav3).toCompletableFuture().get(3, SECONDS);
favoriteService.addFavorite("user-C").invoke(fav3).toCompletableFuture().get(3, SECONDS);
favoriteService.deleteFavorite("user-A").invoke(fav1).toCompletableFuture().get(3, SECONDS);
POrderedSet<String> userAFavorites =
favoriteService.getFavorites("user-A").invoke().toCompletableFuture().get(3, SECONDS);
assertEquals(userAFavorites.size(), 1);
Assert.assertEquals(fav2.getFavoriteId(), userAFavorites.get(0));
POrderedSet<String> userBFavorites =
favoriteService.getFavorites("user-B").invoke().toCompletableFuture().get(3, SECONDS);
assertEquals(userBFavorites.size(), 1);
Assert.assertEquals(fav3.getFavoriteId(), userBFavorites.get(0));
int favorCount =
favoriteService.getFavorCount("favorite-B-1").invoke().toCompletableFuture().get(3, SECONDS);
assertEquals(favorCount, 2);
}
示例4: testPlus
import org.pcollections.POrderedSet; //导入依赖的package包/类
public void testPlus() {
POrderedSet<Integer> s = Empty.orderedSet();
s = s.plus(3).plus(2).plus(1).plus(1).plus(2).plus(3).plus(4);
int vals[] = new int[] { 3, 2, 1, 4 };
assertEquals(vals.length, s.size());
Iterator<Integer> it = s.iterator();
for (int i = 0; i < vals.length; i++) {
assertEquals(vals[i], s.get(i).intValue());
assertEquals(vals[i], it.next().intValue());
}
}
示例5: testPlusMinus
import org.pcollections.POrderedSet; //导入依赖的package包/类
public void testPlusMinus() {
POrderedSet<Integer> s = Empty.orderedSet();
s = s.plus(3).plus(2).plus(1).minus(1).plus(2).plus(3).minus(17)
.plus(5).plus(1).plus(4);
int vals[] = new int[] { 3, 2, 5, 1, 4 };
assertEquals(vals.length, s.size());
Iterator<Integer> it = s.iterator();
for (int i = 0; i < vals.length; i++) {
assertEquals(vals[i], s.get(i).intValue());
assertEquals(vals[i], it.next().intValue());
}
}
示例6: getFavoriteIds
import org.pcollections.POrderedSet; //导入依赖的package包/类
@Value.Default
default POrderedSet<String> getFavoriteIds() {
return OrderedPSet.empty();
}
示例7: getLiveChirps
import org.pcollections.POrderedSet; //导入依赖的package包/类
@Override
public ServiceCall<LiveChirpsRequest, Source<Chirp, ?>> getLiveChirps(String userId) {
return req -> {
CompletionStage<Source<Chirp, ?>> recentChirpSource =
recentChirps(req.getUserIds()).thenApply(recentChirps -> {
List<Source<Chirp, ?>> sources = new ArrayList<>();
for (String uid : req.getUserIds()) {
PubSubRef<Chirp> topic = topics.refFor(TopicId.of(Chirp.class, topicQualifier(uid)));
sources.add(topic.subscriber());
}
HashSet<String> users = new HashSet<>(req.getUserIds());
Source<Chirp, ?> publishedChirps = Source.from(sources).flatMapMerge(sources.size(), s -> s)
.filter(c -> users.contains(c.getUserId()));
// We currently ignore the fact that it is possible to get duplicate chirps
// from the recent and the topic. That can be solved with a de-duplication stage.
return Source.from(recentChirps).concat(publishedChirps);
});
// お気に入りの一覧
CompletionStage<POrderedSet<String>> favorites = favoriteService.getFavorites(userId).invoke();
return recentChirpSource.thenApply(source -> { // source: つぶやきのストリーム
return source.mapAsync(2, chirp -> {
// TODO: STEP2 - お気に入りされた数を取得
CompletionStage<Integer> favorCount =
CompletableFuture.completedFuture(0);
CompletionStage<Chirp> chirpAppliedFavorite =
favorites.thenCompose(favs ->
favorCount.thenApply(count ->
// お気に入りされている場合は isFavorite を true にする
// お気に入りされた数を favorCount に設定
favs.contains(chirp.getUuid())
? chirp.withIsFavorite(true).withFavorCount(count)
: chirp.withFavorCount(count)
));
return chirpAppliedFavorite;
});
});
};
}
示例8: getFavorites
import org.pcollections.POrderedSet; //导入依赖的package包/类
@Override
public ServiceCall<NotUsed, POrderedSet<String>> getFavorites(String userId) {
return request -> {
return CompletableFuture.completedFuture(OrderedPSet.empty());
};
}
示例9: getFavorites
import org.pcollections.POrderedSet; //导入依赖的package包/类
/**
* お気に入りのリストを取得する
*/
ServiceCall<NotUsed, POrderedSet<String>> getFavorites(String userId);