@Override
  public void setFriendIntoCircles(Context ctx, int reason, PeopleId friendId, int... circleIds) {
    ParamChecker.notNull("ctx", ctx);
    ParamChecker.notNull("friendId", friendId);
    ParamChecker.notNull("circleIds", circleIds);
    long viewerId = ctx.getViewer();
    AccountHelper.checkUser(account, ctx, viewerId);

    FriendEntries fes = getFriendEntries(ctx, viewerId);
    if (fes == null || !fes.hasAllCircles(circleIds)) throw new ServerException(E.INVALID_CIRCLE);

    FriendEntry fe = fes.ensureFriend(friendId);
    fe.setCircles(reason, DateHelper.nowMillis(), circleIds);
    putFriendEntries(viewerId, fes);
  }
  @Override
  public void removeFriendsInCircle(Context ctx, PeopleIds friendIds, int circleId) {
    ParamChecker.notNull("ctx", ctx);
    ParamChecker.notNull("friendIds", friendIds);
    ParamChecker.notNull("circleId", circleId);

    long viewerId = ctx.getViewer();
    AccountHelper.checkUser(account, ctx, viewerId);

    FriendEntries fes = getFriendEntries(ctx, viewerId);
    for (PeopleId friendId : friendIds) {
      FriendEntry fe = fes.ensureFriend(friendId);
      fe.removeCircle(circleId);
    }
    putFriendEntries(viewerId, fes);
  }
  @Override
  public void addFriendsIntoCircle(Context ctx, int reason, PeopleIds friendIds, int circleId) {
    ParamChecker.notNull("ctx", ctx);
    ParamChecker.notNull("friendIds", friendIds);
    ParamChecker.notNull("circleI", circleId);

    long viewerId = ctx.getViewer();
    AccountHelper.checkUser(account, ctx, viewerId);

    long now = DateHelper.nowMillis();
    FriendEntries fes = getFriendEntries(ctx, viewerId);
    if (fes == null || !fes.hasCircle(circleId)) throw new ServerException(E.INVALID_CIRCLE);

    for (PeopleId friendId : friendIds) {
      FriendEntry fe = fes.ensureFriend(friendId);
      fe.addCircle(circleId, reason, now);
    }
    putFriendEntries(viewerId, fes);
  }