### Question:
PackedRatingMatrix implements RatingMatrix { @Override public synchronized Long2DoubleMap getUserRatingVector(long userId) { if (cache == null) { cache = new Long2ObjectOpenHashMap<>(); } Long2DoubleMap data = cache.get(userId); if (data != null) { return data; } else { Collection<RatingMatrixEntry> prefs = this.getUserRatings(userId); Long2DoubleMap map = new Long2DoubleOpenHashMap(); for (RatingMatrixEntry e: prefs) { map.put(e.getItemId(), e.getValue()); } data = new Long2DoubleSortedArrayMap(map); cache.put(userId, data); return data; } } PackedRatingMatrix(PackedRatingData data); @Override LongCollection getUserIds(); @Override LongCollection getItemIds(); @Override KeyIndex userIndex(); @Override KeyIndex itemIndex(); @Override List<RatingMatrixEntry> getRatings(); @Override Collection<RatingMatrixEntry> getUserRatings(long userId); @Override synchronized Long2DoubleMap getUserRatingVector(long userId); @PreDestroy void dispose();  }### Answer:
@Test public void testUserRatingVector() { Long2DoubleMap ratings = snap.getUserRatingVector(1); assertEquals(4, ratings.size()); assertEquals(4, ratings.get(7), EPSILON); assertEquals(5, ratings.get(8), EPSILON); assertEquals(3, ratings.get(9), EPSILON); assertEquals(5, ratings.get(11), EPSILON); ratings = snap.getUserRatingVector(2); assertEquals(0, ratings.size()); ratings = snap.getUserRatingVector(3); assertEquals(4, ratings.size()); assertEquals(3, ratings.get(7), EPSILON); assertEquals(3, ratings.get(8), EPSILON); assertEquals(4, ratings.get(9), EPSILON); assertEquals(5, ratings.get(11), EPSILON); ratings = snap.getUserRatingVector(4); assertEquals(5, ratings.size()); assertEquals(4, ratings.get(7), EPSILON); assertEquals(2, ratings.get(8), EPSILON); assertEquals(5, ratings.get(9), EPSILON); assertEquals(4, ratings.get(10), EPSILON); assertEquals(5, ratings.get(11), EPSILON); ratings = snap.getUserRatingVector(5); assertEquals(2, ratings.size()); assertEquals(3, ratings.get(7), EPSILON); assertEquals(5, ratings.get(8), EPSILON); ratings = snap.getUserRatingVector(6); assertEquals(2, ratings.size()); assertEquals(5, ratings.get(7), EPSILON); assertEquals(5, ratings.get(8), EPSILON); ratings = snap.getUserRatingVector(7); assertEquals(3, ratings.size()); assertEquals(2, ratings.get(8), EPSILON); assertEquals(3, ratings.get(9), EPSILON); assertEquals(4, ratings.get(10), EPSILON); }