public KeyDefinition(KeyAndPredicate<S, K>[] keyAndPredicates, KeySourceGetter<K, ? super S> keySourceGetter, int index) { this.singleKeyAndPredicate = getSingle(keyAndPredicates); if (singleKeyAndPredicate == null) { this.keyAndPredicates = keyAndPredicates; } else { this.keyAndPredicates = null; } this.keySourceGetter = keySourceGetter; this.empty = keyAndPredicates == null || keyAndPredicates.length == 0; this.index = index; }
public void handleSource(S source) throws MappingException { if (definition == null) { return; } currentKey = definition.getValues(source); }
private static <S> KeyDefinition<S, ?> emptyToNull(KeyDefinition<S, ?> definition) { if (definition == null || definition.isEmpty()) { return null; } return definition; }
public static <S, K> KeyDefinition<S, K>[] toKeyDefinitions(KeyDefinitionBuilder<S, K>[] siblings) { KeyDefinition<S, K>[] keyDefinitions = new KeyDefinition[siblings.length]; for(KeyDefinitionBuilder<S, K> builder : siblings) { KeyDefinition<S, K> keyDefinition = new KeyDefinition<S, K>(toArray(builder.keyAndPredicates), builder.keySourceGetter, builder.index); keyDefinitions[builder.index]= keyDefinition; } return keyDefinitions; }
public Key getValues(S source) { if (empty) throw new IllegalStateException("cannot get value on empty keys"); try { if (singleKeyAndPredicate != null) { return singleValueKeys(source); } else { return multiValueKeys(source); } } catch (Exception e) { return ErrorHelper.rethrow(e); } }
public BreakDetectorMappingContext(KeyDefinition<S, ?> rootKeyDefinition, MappingContext<S> delegateContext, KeyDefinition<S, ?>[] keyDefinitions) { this.delegateContext = delegateContext; this.breakDetectors = toBreakDetectors(keyDefinitions); this.rootDetector = breakDetectors[rootKeyDefinition.getIndex()]; }
public static <S, K> KeyDefinition<S, K>[] toKeyDefinitions(KeyDefinitionBuilder<S, K>[] siblings) { KeyDefinition<S, K>[] keyDefinitions = new KeyDefinition[siblings.length]; for(KeyDefinitionBuilder<S, K> builder : siblings) { KeyDefinition<S, K> keyDefinition = new KeyDefinition<S, K>(toArray(builder.keyAndPredicates), builder.keySourceGetter, builder.index); keyDefinitions[builder.index]= keyDefinition; } return keyDefinitions; }
public Key getValues(S source) { if (empty) throw new IllegalStateException("cannot get value on empty keys"); try { if (singleKeyAndPredicate != null) { return singleValueKeys(source); } else { return multiValueKeys(source); } } catch (Exception e) { return ErrorHelper.rethrow(e); } }
public BreakDetectorMappingContext(KeyDefinition<S, ?> rootKeyDefinition, MappingContext<S> delegateContext, KeyDefinition<S, ?>[] keyDefinitions) { this.delegateContext = delegateContext; this.breakDetectors = toBreakDetectors(keyDefinitions); this.rootDetector = breakDetectors[rootKeyDefinition.getIndex()]; }
@Test public void testBreakDetector() throws Exception { KeySourceGetter<SampleFieldKey, Object> keySourceGetter = mock(KeySourceGetter.class); Object object = new Object(); SampleFieldKey key = new SampleFieldKey("k", 1); when(keySourceGetter.getValue(key, object)).thenReturn(new byte[] {1, 2}, new byte[] {1, 2}, new byte[] {1, 3}); KeyDefinition<Object, SampleFieldKey> keyDefinition = new KeyDefinition<Object, SampleFieldKey>( new KeyAndPredicate[] { new KeyAndPredicate<Object[], SampleFieldKey>(key, null) }, keySourceGetter, 0); BreakDetector<Object> breakDetector = new BreakDetector<Object>(keyDefinition); assertTrue(breakDetector.broke(object)); assertFalse(breakDetector.broke(object)); assertTrue(breakDetector.broke(object)); } }
public void handleSource(S source) throws MappingException { if (definition == null) { return; } currentKey = definition.getValues(source); }
public KeyDefinition(KeyAndPredicate<S, K>[] keyAndPredicates, KeySourceGetter<K, ? super S> keySourceGetter, int index) { this.singleKeyAndPredicate = getSingle(keyAndPredicates); if (singleKeyAndPredicate == null) { this.keyAndPredicates = keyAndPredicates; } else { this.keyAndPredicates = null; } this.keySourceGetter = keySourceGetter; this.empty = keyAndPredicates == null || keyAndPredicates.length == 0; this.index = index; }
private static <S> KeyDefinition<S, ?> emptyToNull(KeyDefinition<S, ?> definition) { if (definition == null || definition.isEmpty()) { return null; } return definition; }
public Key getKey(S source) { return definition.getValues(source); }
public Key getKey(S source) { return definition.getValues(source); }
public boolean broke(S source) throws MappingException { if (definition == null) { return true; } Key oldKey = currentKey; currentKey = definition.getValues(source); return oldKey == null || !oldKey.equals(currentKey); }
public boolean broke(S source) throws MappingException { if (definition == null) { return true; } Key oldKey = currentKey; currentKey = definition.getValues(source); return oldKey == null || !oldKey.equals(currentKey); }