/** * Initialize a type descriptor for the given type. Assumed immutable. * * @param type The Java type. * @param mutabilityPlan The plan for handling mutability aspects of the java type. */ @SuppressWarnings({ "unchecked" }) protected AbstractTypeDescriptor(Class<T> type, MutabilityPlan<T> mutabilityPlan) { this.type = type; this.mutabilityPlan = mutabilityPlan; this.comparator = Comparable.class.isAssignableFrom( type ) ? (Comparator<T>) ComparableComparator.INSTANCE : null; JavaTypeDescriptorRegistry.INSTANCE.addDescriptor( this ); }
/** * Initialize a type descriptor for the given type. Assumed immutable. * * @param javaType The Java type. * @param mutabilityPlan The plan for handling mutability aspects of the java type. */ @SuppressWarnings({ "unchecked" }) protected AbstractTypeDescriptor(Class<T> javaType, MutabilityPlan<T> mutabilityPlan) { this( javaType, mutabilityPlan, Comparable.class.isAssignableFrom( javaType ) ? (Comparator<T>) ComparableComparator.INSTANCE : null ); }
@Test public void testIsReplaceableByVersionBefore() throws Exception { String expectedValue = "Some value"; Value value = new Value(10, 100L, expectedValue); assertFalse(value.isReplaceableBy(99L, 9, ComparableComparator.INSTANCE)); }
@Test public void testIsReplaceableByVersionEqual() throws Exception { String expectedValue = "Some value"; Value value = new Value(10, 100L, expectedValue); assertFalse(value.isReplaceableBy(101L, 10, ComparableComparator.INSTANCE)); }
@Test public void testIsReplaceableByVersionAfter() throws Exception { String expectedValue = "Some value"; Value value = new Value(10, 100L, expectedValue); assertTrue(value.isReplaceableBy(99L, 11, ComparableComparator.INSTANCE)); }
@Test public void testIsReplaceableByVersionBefore() throws Exception { ExpiryMarker marker = new ExpiryMarker(10, 150L, "the-marker-id").expire(100L); assertFalse("marker is replaceable when it when version before", marker.isReplaceableBy(101L, 9, ComparableComparator.INSTANCE)); }
@Test public void testIsReplaceableByVersionEqual() throws Exception { ExpiryMarker marker = new ExpiryMarker(10, 150L, "the-marker-id").expire(100L); assertFalse("marker is replaceable when it when version equal", marker.isReplaceableBy(101L, 10, ComparableComparator.INSTANCE)); }
@Test public void testIsReplaceableByVersionAfter() throws Exception { ExpiryMarker marker = new ExpiryMarker(10, 150L, "the-marker-id").expire(100L); assertTrue("marker is replaceable when it when version after", marker.isReplaceableBy(99L, 11, ComparableComparator.INSTANCE)); }
@Override public Comparator<Instant> getComparator() { return ComparableComparator.INSTANCE; }