当前位置: 首页>>代码示例>>Java>>正文


Java PSequence类代码示例

本文整理汇总了Java中org.pcollections.PSequence的典型用法代码示例。如果您正苦于以下问题:Java PSequence类的具体用法?Java PSequence怎么用?Java PSequence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PSequence类属于org.pcollections包,在下文中一共展示了PSequence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAllRegistrations

import org.pcollections.PSequence; //导入依赖的package包/类
/**
* Get all registered Cargo
*
* @return
*/
   @Override
   public ServiceCall<NotUsed, NotUsed, PSequence<Cargo>> getAllRegistrations() {
       return (userId, req) -> {
           CompletionStage<PSequence<Cargo>> result = db.selectAll("SELECT cargoid, name, description, owner, destination FROM cargo")
                   .thenApply(rows -> {
                       List<Cargo> cargos = rows.stream().map(row -> Cargo.of(row.getString("cargoid"),
                               row.getString("name"),
                               row.getString("description"),
                               row.getString("owner"),
                               row.getString("destination"))).collect(Collectors.toList());
                       return TreePVector.from(cargos);
                   });
           return result;
       };
   }
 
开发者ID:lagom,项目名称:activator-lagom-cargotracker,代码行数:21,代码来源:RegistrationServiceImpl.java

示例2: removeItem

import org.pcollections.PSequence; //导入依赖的package包/类
public BasketState removeItem(UUID itemId, int removedCount) {
    int totalCount = items.stream().filter(dbi-> dbi.getId().equals(itemId)).mapToInt(DomainBasketItem::getNumberOfItems).sum();
    PSequence<DomainBasketItem> newItems =
            TreePVector.from(
                    items.stream().filter(dbi-> !dbi.getId().equals(itemId)).collect(Collectors.toList())
            ).plus(new DomainBasketItem(itemId, totalCount-removedCount));
    return new BasketState(
            newItems,
            alreadyOrdered);
}
 
开发者ID:ignasi35,项目名称:lagom-java-workshop,代码行数:11,代码来源:BasketState.java

示例3: addItems

import org.pcollections.PSequence; //导入依赖的package包/类
@Test
public void addItems() {
    UUID bid = UUID.randomUUID();
    UUID orangeId = UUID.randomUUID();
    UUID bananaId = UUID.randomUUID();


    BasketCommand.AddItem cmd1 = new BasketCommand.AddItem(orangeId, 3);
    BasketCommand.AddItem cmd2 = new BasketCommand.AddItem(bananaId, 1);
    BasketCommand.GetBasket cmd3 = BasketCommand.GetBasket.INSTANCE;

    PersistentEntityTestDriver<BasketCommand, PEBasketEvent, BasketState> driver =
            new PersistentEntityTestDriver<>(system, new BasketEntity(), bid.toString());


    // add some oranges
    Outcome<PEBasketEvent, BasketState> outcome1 = driver.run(cmd1);
    assertEquals(Done.getInstance(), outcome1.getReplies().get(0));
    assertEquals(Collections.emptyList(), outcome1.issues());

    // and then add some bananas. Finally get the basket.
    Outcome<PEBasketEvent, BasketState> outcome3 = driver.run(cmd2, cmd3);

    PSequence<DomainBasketItem> items = TreePVector.<DomainBasketItem>empty()
            .plus(new DomainBasketItem(orangeId, 3))
            .plus(new DomainBasketItem(bananaId, 1));
    BasketState expected = new BasketState(items, false);
    assertEquals(expected, outcome3.getReplies().get(1));
    assertEquals(Collections.emptyList(), outcome1.issues());

}
 
开发者ID:ignasi35,项目名称:lagom-java-workshop,代码行数:32,代码来源:BasketEntityTest.java

示例4: getFollowers

import org.pcollections.PSequence; //导入依赖的package包/类
@Override
public ServiceCall<NotUsed, PSequence<String>> getFollowers(String userId) {
  return req -> {
    CompletionStage<PSequence<String>> result = db.selectAll("SELECT * FROM follower WHERE userId = ?", userId)
      .thenApply(rows -> {
      List<String> followers = rows.stream().map(row -> row.getString("followedBy")).collect(Collectors.toList());
      return TreePVector.from(followers);
    });
    return result;
  };
}
 
开发者ID:lagom,项目名称:lagom-java-chirper-example,代码行数:12,代码来源:FriendServiceImpl.java

示例5: shouldBeAbleToCreateUsersAndConnectFriends

import org.pcollections.PSequence; //导入依赖的package包/类
@Test
public void shouldBeAbleToCreateUsersAndConnectFriends() throws Exception {
  withServer(defaultSetup().withCassandra(true), server -> {
    FriendService friendService = server.client(FriendService.class);
    User usr1 = new User("usr1", "User 1");
    friendService.createUser().invoke(usr1).toCompletableFuture().get(10, SECONDS);
    User usr2 = new User("usr2", "User 2");
    friendService.createUser().invoke(usr2).toCompletableFuture().get(3, SECONDS);
    User usr3 = new User("usr3", "User 3");
    friendService.createUser().invoke(usr3).toCompletableFuture().get(3, SECONDS);

    friendService.addFriend("usr1").invoke(new FriendId(usr2.userId)).toCompletableFuture().get(3, SECONDS);
    friendService.addFriend("usr1").invoke(new FriendId(usr3.userId)).toCompletableFuture().get(3, SECONDS);

    User fetchedUsr1 = friendService.getUser("usr1").invoke().toCompletableFuture().get(3,
        SECONDS);
    assertEquals(usr1.userId, fetchedUsr1.userId);
    assertEquals(usr1.name, fetchedUsr1.name);
    assertEquals(TreePVector.empty().plus("usr2").plus("usr3"), fetchedUsr1.friends);

    eventually(FiniteDuration.create(10, SECONDS), () -> {
      PSequence<String> followers = friendService.getFollowers("usr2").invoke()
          .toCompletableFuture().get(3, SECONDS);
      assertEquals(TreePVector.empty().plus("usr1"), followers);
    });

  });
}
 
开发者ID:lagom,项目名称:lagom-java-chirper-example,代码行数:29,代码来源:FriendServiceTest.java

示例6: getHistoricalChirps

import org.pcollections.PSequence; //导入依赖的package包/类
@Override
public ServiceCall<HistoricalChirpsRequest, Source<Chirp, ?>> getHistoricalChirps() {
    return req -> {
        PSequence<String> userIds = req.userIds;
        long timestamp = req.fromTime.toEpochMilli();
        Source<Chirp, ?> result = chirps.getHistoricalChirps(userIds, timestamp);
        return CompletableFuture.completedFuture(result);
    };
}
 
开发者ID:lagom,项目名称:lagom-java-chirper-example,代码行数:10,代码来源:ChirpServiceImpl.java

示例7: getHistoricalChirps

import org.pcollections.PSequence; //导入依赖的package包/类
public Source<Chirp, ?> getHistoricalChirps(PSequence<String> userIds, long timestamp) {
    List<Source<Chirp, ?>> sources = new ArrayList<>();
    for (String userId : userIds) {
        sources.add(getHistoricalChirps(userId, timestamp));
    }
    // Chirps from one user are ordered by timestamp, but chirps from different
    // users are not ordered. That can be improved by implementing a smarter
    // merge that takes the timestamps into account.
    return Source.from(sources).flatMapMerge(sources.size(), s -> s);
}
 
开发者ID:lagom,项目名称:lagom-java-chirper-example,代码行数:11,代码来源:ChirpRepositoryImpl.java

示例8: getRecentChirps

import org.pcollections.PSequence; //导入依赖的package包/类
public CompletionStage<PSequence<Chirp>> getRecentChirps(PSequence<String> userIds) {
    CompletionStage<PSequence<Chirp>> results = CompletableFuture.completedFuture(TreePVector.empty());
    for (String userId : userIds) {
        results = results.thenCombine(getRecentChirps(userId), PSequence::plusAll);
    }

    return results.thenApply(this::limitRecentChirps);
}
 
开发者ID:lagom,项目名称:lagom-java-chirper-example,代码行数:9,代码来源:ChirpRepositoryImpl.java

示例9: limitRecentChirps

import org.pcollections.PSequence; //导入依赖的package包/类
private PSequence<Chirp> limitRecentChirps(PSequence<Chirp> all) {
    List<Chirp> limited = all.stream()
            .sorted(comparing((Chirp chirp) -> chirp.timestamp).reversed())
            .limit(NUM_RECENT_CHIRPS)
            .collect(Collectors.toCollection(ArrayList::new));

    Collections.reverse(limited);
    return TreePVector.from(limited);
}
 
开发者ID:lagom,项目名称:lagom-java-chirper-example,代码行数:10,代码来源:ChirpRepositoryImpl.java

示例10: getLiveActivityStream

import org.pcollections.PSequence; //导入依赖的package包/类
@Override
public ServiceCall<NotUsed, Source<Chirp, ?>> getLiveActivityStream(String userId) {
  return req -> {
    return friendService.getUser(userId).invoke().thenCompose(user -> {
      PSequence<String> userIds = user.friends.plus(userId);
      LiveChirpsRequest chirpsReq =  new LiveChirpsRequest(userIds);
      // Note that this stream will not include changes to friend associates,
      // e.g. adding a new friend.
      CompletionStage<Source<Chirp, ?>> result = chirpService.getLiveChirps().invoke(chirpsReq);
      return result;
    });
  };
}
 
开发者ID:lagom,项目名称:lagom-java-chirper-example,代码行数:14,代码来源:ActivityStreamServiceImpl.java

示例11: getHistoricalActivityStream

import org.pcollections.PSequence; //导入依赖的package包/类
@Override
public ServiceCall<NotUsed, Source<Chirp, ?>> getHistoricalActivityStream(String userId) {
  return req ->
    friendService.getUser(userId).invoke().thenCompose(user -> {
      PSequence<String> userIds = user.friends.plus(userId);
      // FIXME we should use HistoricalActivityStreamReq request parameter
      Instant fromTime = Instant.now().minus(Duration.ofDays(7));
      HistoricalChirpsRequest chirpsReq = new HistoricalChirpsRequest(fromTime, userIds);
      CompletionStage<Source<Chirp, ?>> result = chirpService.getHistoricalChirps().invoke(chirpsReq);
      return result;
    });
}
 
开发者ID:lagom,项目名称:lagom-java-chirper-example,代码行数:13,代码来源:ActivityStreamServiceImpl.java

示例12: getFollowers

import org.pcollections.PSequence; //导入依赖的package包/类
@Override
public ServiceCall<NotUsed, PSequence<String>> getFollowers(String userId) {
  return req -> {
    if (userId.equals(usr1.userId))
      return completedFuture(TreePVector.<String>empty());
    else if (userId.equals(usr2.userId))
      return completedFuture(TreePVector.<String>empty().plus("usr1"));
    else
      throw new NotFound(userId);
  };
}
 
开发者ID:lagom,项目名称:lagom-java-chirper-example,代码行数:12,代码来源:ActivityStreamServiceTest.java

示例13: addFriend

import org.pcollections.PSequence; //导入依赖的package包/类
default FriendState addFriend(String friendUserId) {
  Optional<User> user = getUser();
  if (!user.isPresent())
    throw new IllegalStateException("friend can't be added before user is created");
  PSequence<String> newFriends = user.get().getFriends().plus(friendUserId);
  return FriendState.of(Optional.of(AbstractUser.of(user.get().getUserId(), user.get().getName(), Optional.of(newFriends))));
}
 
开发者ID:negokaz,项目名称:lagom-hands-on-development,代码行数:8,代码来源:AbstractFriendState.java

示例14: shouldBeAbleToCreateUsersAndConnectFriends

import org.pcollections.PSequence; //导入依赖的package包/类
@Test
public void shouldBeAbleToCreateUsersAndConnectFriends() throws Exception {
  withServer(defaultSetup(), server -> {
    FriendService friendService = server.client(FriendService.class);
    User usr1 = User.of("usr1", "User 1");
    friendService.createUser().invoke(usr1).toCompletableFuture().get(10, SECONDS);
    User usr2 = User.of("usr2", "User 2");
    friendService.createUser().invoke(usr2).toCompletableFuture().get(3, SECONDS);
    User usr3 = User.of("usr3", "User 3");
    friendService.createUser().invoke(usr3).toCompletableFuture().get(3, SECONDS);

    friendService.addFriend("usr1").invoke(FriendId.of(usr2.getUserId())).toCompletableFuture().get(3, SECONDS);
    friendService.addFriend("usr1").invoke(FriendId.of(usr3.getUserId())).toCompletableFuture().get(3, SECONDS);

    User fetchedUsr1 = friendService.getUser("usr1").invoke().toCompletableFuture().get(3,
        SECONDS);
    assertEquals(usr1.getUserId(), fetchedUsr1.getUserId());
    assertEquals(usr1.getName(), fetchedUsr1.getName());
    assertEquals(TreePVector.empty().plus("usr2").plus("usr3"), fetchedUsr1.getFriends());

    eventually(FiniteDuration.create(10, SECONDS), () -> {
      PSequence<String> followers = friendService.getFollowers("usr2").invoke()
          .toCompletableFuture().get(3, SECONDS);
      assertEquals(TreePVector.empty().plus("usr1"), followers);
    });

  });
}
 
开发者ID:negokaz,项目名称:lagom-hands-on-development,代码行数:29,代码来源:FriendServiceTest.java

示例15: recentChirps

import org.pcollections.PSequence; //导入依赖的package包/类
private CompletionStage<PSequence<Chirp>> recentChirps(PSequence<String> userIds) {
  int limit = 10;
  PSequence<CompletionStage<PSequence<Chirp>>> results = TreePVector.empty();
  for (String userId : userIds) {
    CompletionStage<PSequence<Chirp>> result = db
        .selectAll("SELECT * FROM chirp WHERE userId = ? ORDER BY timestamp DESC LIMIT ?", userId, limit)
        .thenApply(rows -> {
          List<Chirp> chirps = rows.stream().map(this::mapChirp).collect(Collectors.toList());
          return TreePVector.from(chirps);
        });
    results = results.plus(result);
  }

  CompletionStage<PSequence<Chirp>> combined = null;
  for (CompletionStage<PSequence<Chirp>> chirpsFromOneUser : results) {
    if (combined == null) {
      combined = chirpsFromOneUser;
    } else {
      combined = combined.thenCombine(chirpsFromOneUser, (a, b) -> a.plusAll(b));
    }
  }

  CompletionStage<PSequence<Chirp>> sortedLimited = combined.thenApply(all -> {
    List<Chirp> allSorted = new ArrayList<>(all);
    // reverse order
    Collections.sort(allSorted, (a, b) -> b.getTimestamp().compareTo(a.getTimestamp()));
    List<Chirp> limited = allSorted.stream().limit(limit).collect(Collectors.toList());
    List<Chirp> reversed = new ArrayList<>(limited);
    Collections.reverse(reversed);
    return TreePVector.from(reversed);
  });

  return sortedLimited;
}
 
开发者ID:negokaz,项目名称:lagom-hands-on-development,代码行数:35,代码来源:ChirpServiceImpl.java


注:本文中的org.pcollections.PSequence类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。