@Test public void createLRUMapTest() { Map<String, String> mapFixedSize = EnergyModellerQueueController.createLRUMap(4); mapFixedSize.put("a", "1"); mapFixedSize.put("b", "2"); mapFixedSize.put("c", "3"); mapFixedSize.put("d", "4"); assertEquals(4, mapFixedSize.size()); assertEquals("1", mapFixedSize.get("a")); assertEquals("2", mapFixedSize.get("b")); assertEquals("3", mapFixedSize.get("c")); assertEquals("4", mapFixedSize.get("d")); mapFixedSize.put("e", "5"); assertEquals(4, mapFixedSize.size()); assertEquals(null, mapFixedSize.get("a")); assertEquals("2", mapFixedSize.get("b")); assertEquals("3", mapFixedSize.get("c")); assertEquals("4", mapFixedSize.get("d")); assertEquals("5", mapFixedSize.get("e")); mapFixedSize.put("b", "7"); assertEquals(4, mapFixedSize.size()); assertEquals(null, mapFixedSize.get("a")); mapFixedSize.put("f", "6"); assertEquals(4, mapFixedSize.size()); assertEquals(null, mapFixedSize.get("a")); assertEquals(null, mapFixedSize.get("c")); }
public static <K, V> Map<K, V> createLRUMap(final int maxEntries) { return new LinkedHashMap<K, V>(maxEntries*10/7, 0.7f, true) { private static final long serialVersionUID = -3617640443322851203L; @Override protected boolean removeEldestEntry(Map.Entry<K, V> eldest) { return size() > maxEntries; } }; }
EnergyModellerQueueController implements InitializingBean { public static <K, V> Map<K, V> createLRUMap(final int maxEntries) { return new LinkedHashMap<K, V>(maxEntries*10/7, 0.7f, true) { private static final long serialVersionUID = -3617640443322851203L; @Override protected boolean removeEldestEntry(Map.Entry<K, V> eldest) { return size() > maxEntries; } }; } }
EnergyModellerQueueController implements InitializingBean { public static <K, V> Map<K, V> createLRUMap(final int maxEntries) { return new LinkedHashMap<K, V>(maxEntries*10/7, 0.7f, true) { private static final long serialVersionUID = -3617640443322851203L; @Override protected boolean removeEldestEntry(Map.Entry<K, V> eldest) { return size() > maxEntries; } }; } EnergyModellerQueueController(); }
EnergyModellerQueueController implements InitializingBean { public static <K, V> Map<K, V> createLRUMap(final int maxEntries) { return new LinkedHashMap<K, V>(maxEntries*10/7, 0.7f, true) { private static final long serialVersionUID = -3617640443322851203L; @Override protected boolean removeEldestEntry(Map.Entry<K, V> eldest) { return size() > maxEntries; } }; } EnergyModellerQueueController(); @Override void afterPropertiesSet(); void addMessage(EnergyModellerMessage emMessage, String type); EnergyModellerMessage getMeasurementMessage(String key); EnergyModellerMessage getPredictionMessage(String key); static Map<K, V> createLRUMap(final int maxEntries); static String generateKey(EnergyModellerMessage emMessage); static String generateKey(String applicationId, String eventId, String deploymentId, List<String> vmsId, String unit); }
EnergyModellerQueueController implements InitializingBean { public static <K, V> Map<K, V> createLRUMap(final int maxEntries) { return new LinkedHashMap<K, V>(maxEntries*10/7, 0.7f, true) { private static final long serialVersionUID = -3617640443322851203L; @Override protected boolean removeEldestEntry(Map.Entry<K, V> eldest) { return size() > maxEntries; } }; } EnergyModellerQueueController(); @Override void afterPropertiesSet(); void addMessage(EnergyModellerMessage emMessage, String type); EnergyModellerMessage getMeasurementMessage(String key); EnergyModellerMessage getPredictionMessage(String key); static Map<K, V> createLRUMap(final int maxEntries); static String generateKey(EnergyModellerMessage emMessage); static String generateKey(String applicationId, String eventId, String deploymentId, List<String> vmsId, String unit); static final String WATT; static final String WATTHOUR; static final String COUNT; static final String SEC; static final String APP_DURATION; static final String APP_COUNT; static final String MEASUREMENTS; static final String PREDICTIONS; }