@Nonnull @Override public Long2DoubleMap userRatingVector(long user) { IdBox<Long2DoubleMap> cached = cachedValue; if (cached != null && cached.getId() == user) { return cached.getValue(); } Long2DoubleMap map; List<Entity> entities = dao.query(getEntityType()) .withAttribute(CommonAttributes.USER_ID, user) .get(); map = makeVector(entities); cachedValue = IdBox.create(user, map); return map; }
@Nullable @Override public IdBox<Long2DoubleMap> apply(@Nullable IdBox<List<Entity>> input) { if (input == null) { return null; } return IdBox.create(input.getId(), makeVector(input.getValue())); } });
@Override public ObjectStream<IdBox<Long2DoubleMap>> streamUsers() { ObjectStream<IdBox<List<Entity>>> stream = dao.query(getEntityType()) .groupBy(CommonAttributes.USER_ID) .stream(); return ObjectStreams.transform(stream, new Function<IdBox<List<Entity>>, IdBox<Long2DoubleMap>>() { @Nullable @Override public IdBox<Long2DoubleMap> apply(@Nullable IdBox<List<Entity>> input) { if (input == null) { return null; } return IdBox.create(input.getId(), makeVector(input.getValue())); } }); } }
@Nullable @Override public IdBox<Long2DoubleMap> apply(@Nullable IdBox<List<Entity>> input) { if (input == null) { return null; } return IdBox.create(input.getId(), makeVector(input.getValue())); } });
@Override public ObjectStream<IdBox<Long2DoubleMap>> streamUsers() { ObjectStream<IdBox<List<Entity>>> stream = dao.query(getEntityType()) .groupBy(CommonAttributes.USER_ID) .stream(); return ObjectStreams.transform(stream, new Function<IdBox<List<Entity>>, IdBox<Long2DoubleMap>>() { @Nullable @Override public IdBox<Long2DoubleMap> apply(@Nullable IdBox<List<Entity>> input) { if (input == null) { return null; } return IdBox.create(input.getId(), makeVector(input.getValue())); } }); } }
@Nonnull @Override public Long2DoubleMap userRatingVector(long user) { IdBox<Long2DoubleMap> cached = cachedValue; if (cached != null && cached.getId() == user) { return cached.getValue(); } Long2DoubleMap map; List<Entity> entities = dao.query(getEntityType()) .withAttribute(CommonAttributes.USER_ID, user) .get(); map = makeVector(entities); cachedValue = IdBox.create(user, map); return map; }