@Test public void testGetMultipleTimes() { SerializationCache cache = new SharedTypesSerializationCache(TestType.class); String value = "TEST-ORIG"; TestType origObj = new TestType(value); Object firstGetValue = cache.getCached(origObj); assertSame(origObj, firstGetValue); Object secondGetValue = cache.getCached(new TestType(value)); assertSame(origObj, secondGetValue); }
@Override public Object getCached(Object src) { for (Class<?> type: shareableTypes) { if (type.isInstance(src)) { Object prevValue = cache.putIfAbsent(src, src); return prevValue != null ? prevValue : src; } } return src; }
SharedTypesSerializationCache implements SerializationCache { @Override public Object getCached(Object src) { for (Class<?> type: shareableTypes) { if (type.isInstance(src)) { Object prevValue = cache.putIfAbsent(src, src); return prevValue != null ? prevValue : src; } } return src; } }
SharedTypesSerializationCache implements SerializationCache { @Override public Object getCached(Object src) { for (Class<?> type: shareableTypes) { if (type.isInstance(src)) { Object prevValue = cache.putIfAbsent(src, src); return prevValue != null ? prevValue : src; } } return src; } SharedTypesSerializationCache(Class<?>... shareableTypes); }
SharedTypesSerializationCache implements SerializationCache { @Override public Object getCached(Object src) { for (Class<?> type: shareableTypes) { if (type.isInstance(src)) { Object prevValue = cache.putIfAbsent(src, src); return prevValue != null ? prevValue : src; } } return src; } SharedTypesSerializationCache(Class<?>... shareableTypes); @Override Object getCached(Object src); }
SharedTypesSerializationCache implements SerializationCache { @Override public Object getCached(Object src) { for (Class<?> type: shareableTypes) { if (type.isInstance(src)) { Object prevValue = cache.putIfAbsent(src, src); return prevValue != null ? prevValue : src; } } return src; } SharedTypesSerializationCache(Class<?>... shareableTypes); @Override Object getCached(Object src);  }