@Override public void clear() { model = null; data = new FastByIDMap<Collection<Preference>>(); timestampData = new FastByIDMap<FastByIDMap<Long>>(); } }
public FileIDMigrator(File dataFile, long minReloadIntervalMS) throws FileNotFoundException { longToString = new FastByIDMap<String>(100); this.dataFile = Preconditions.checkNotNull(dataFile); if (!dataFile.exists() || dataFile.isDirectory()) { throw new FileNotFoundException(dataFile.toString()); } log.info("Creating FileReadonlyIDMigrator for file {}", dataFile); this.reloadLock = new ReentrantLock(); this.lastModified = dataFile.lastModified(); this.minReloadIntervalMS = minReloadIntervalMS; reload(); }
public FileIDMigrator(File dataFile, long minReloadIntervalMS) throws FileNotFoundException { longToString = new FastByIDMap<String>(100); this.dataFile = Preconditions.checkNotNull(dataFile); if (!dataFile.exists() || dataFile.isDirectory()) { throw new FileNotFoundException(dataFile.toString()); } log.info("Creating FileReadonlyIDMigrator for file {}", dataFile); this.reloadLock = new ReentrantLock(); this.lastModified = dataFile.lastModified(); this.minReloadIntervalMS = minReloadIntervalMS; reload(); }
public FileIDMigrator(File dataFile, long minReloadIntervalMS) throws FileNotFoundException { longToString = new FastByIDMap<>(100); this.dataFile = Preconditions.checkNotNull(dataFile); if (!dataFile.exists() || dataFile.isDirectory()) { throw new FileNotFoundException(dataFile.toString()); } log.info("Creating FileReadonlyIDMigrator for file {}", dataFile); this.reloadLock = new ReentrantLock(); this.lastModified = dataFile.lastModified(); this.minReloadIntervalMS = minReloadIntervalMS; reload(); }
private FastByIDMap<String> buildMapping() throws IOException { FastByIDMap<String> mapping = new FastByIDMap<String>(); for (String line : new FileLineIterable(dataFile)) { mapping.put(toLongID(line), line); } lastModified = dataFile.lastModified(); return mapping; }
private FastByIDMap<String> buildMapping() throws IOException { FastByIDMap<String> mapping = new FastByIDMap<String>(); for (String line : new FileLineIterable(dataFile)) { mapping.put(toLongID(line), line); } lastModified = dataFile.lastModified(); return mapping; }
private FastByIDMap<String> buildMapping() throws IOException { FastByIDMap<String> mapping = new FastByIDMap<>(); for (String line : new FileLineIterable(dataFile)) { mapping.put(toLongID(line), line); } lastModified = dataFile.lastModified(); return mapping; }
private static FastByIDMap<Integer> createIDMapping(int size, LongPrimitiveIterator idIterator) { FastByIDMap<Integer> mapping = new FastByIDMap<Integer>(size); int index = 0; while (idIterator.hasNext()) { mapping.put(idIterator.nextLong(), index++); } return mapping; }
private static FastByIDMap<Integer> createIDMapping(int size, LongPrimitiveIterator idIterator) { FastByIDMap<Integer> mapping = new FastByIDMap<Integer>(size); int index = 0; while (idIterator.hasNext()) { mapping.put(idIterator.nextLong(), index++); } return mapping; }
private static FastByIDMap<Integer> createIDMapping(int size, LongPrimitiveIterator idIterator) { FastByIDMap<Integer> mapping = new FastByIDMap<>(size); int index = 0; while (idIterator.hasNext()) { mapping.put(idIterator.nextLong(), index++); } return mapping; }
public static void main(String[] args) { FastByIDMap<PreferenceArray> preferences = new FastByIDMap<PreferenceArray>(); PreferenceArray prefsForUser1 = new GenericUserPreferenceArray(10); prefsForUser1.setUserID(0, 1L); prefsForUser1.setItemID(0, 101L); prefsForUser1.setValue(0, 3.0f); prefsForUser1.setItemID(1, 102L); prefsForUser1.setValue(1, 4.5f); preferences.put(1L, prefsForUser1); DataModel model = new GenericDataModel(preferences); System.out.println(model); }
/** * Prepares a testable object without delegate data */ private static PlusAnonymousConcurrentUserDataModel getTestableWithoutDelegateData(int maxConcurrentUsers) { FastByIDMap<PreferenceArray> delegatePreferences = new FastByIDMap<PreferenceArray>(); return new PlusAnonymousConcurrentUserDataModel(new GenericDataModel(delegatePreferences), maxConcurrentUsers); }
private static FastByIDMap<String> buildTestFastMap() { FastByIDMap<String> map = new FastByIDMap<String>(); map.put(500000L, "alpha"); map.put(47L, "bang"); map.put(2L, "beta"); return map; }
@Test public void testPutAndGet() { FastByIDMap<Long> map = new FastByIDMap<Long>(); assertNull(map.get(500000L)); map.put(500000L, 2L); assertEquals(2L, (long) map.get(500000L)); }
@Test public void testGrow() { FastByIDMap<String> map = new FastByIDMap<String>(1,1); map.put(500000L, "alpha"); map.put(47L, "bang"); assertNull(map.get(500000L)); assertEquals("bang", map.get(47L)); }
@Test public void testClear() { FastByIDMap<Long> map = new FastByIDMap<Long>(); map.put(500000L, 2L); map.clear(); assertEquals(0, map.size()); assertTrue(map.isEmpty()); assertNull(map.get(500000L)); }
@Test public void testRemove() { FastByIDMap<Long> map = new FastByIDMap<Long>(); map.put(500000L, 2L); map.remove(500000L); assertEquals(0, map.size()); assertTrue(map.isEmpty()); assertNull(map.get(500000L)); }
@Test public void lessItemsThanBatchSize() throws Exception { FastByIDMap<PreferenceArray> userData = new FastByIDMap<PreferenceArray>(); userData.put(1, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(1, 1, 1), new GenericPreference(1, 2, 1), new GenericPreference(1, 3, 1)))); userData.put(2, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(2, 1, 1), new GenericPreference(2, 2, 1), new GenericPreference(2, 4, 1)))); DataModel dataModel = new GenericDataModel(userData); ItemBasedRecommender recommender = new GenericItemBasedRecommender(dataModel, new TanimotoCoefficientSimilarity(dataModel)); BatchItemSimilarities batchSimilarities = new MultithreadedBatchItemSimilarities(recommender, 10); batchSimilarities.computeItemSimilarities(1, 1, mock(SimilarItemsWriter.class)); }
@Test public void testMaxSize() { FastByIDMap<String> map = new FastByIDMap<String>(); map.put(4, "bang"); assertEquals(1, map.size()); map.put(47L, "bang"); assertEquals(2, map.size()); assertNull(map.get(500000L)); map.put(47L, "buzz"); assertEquals(2, map.size()); assertEquals("buzz", map.get(47L)); }
@Test public void testSizeEmpty() { FastByIDMap<Long> map = new FastByIDMap<Long>(); assertEquals(0, map.size()); assertTrue(map.isEmpty()); map.put(500000L, 2L); assertEquals(1, map.size()); assertFalse(map.isEmpty()); map.remove(500000L); assertEquals(0, map.size()); assertTrue(map.isEmpty()); }