/** * Increments the value of an existing key by 1. * If the key doesn't exist, initialises the value to 1. * * @param key The key to increment or insert. */ public void upsert(final String key) { upsert(key, 1); } }
@Override public FreqMap deserialiseEmpty() { return new FreqMap(); } }
@Override public Long apply(final FreqMap freqMap) { if (null != freqMap) { return freqMap.get(key); } return null; }
@Override protected FreqMap _apply(final FreqMap a, final FreqMap b) { for (final Entry<String, Long> entry : b.entrySet()) { if (a.containsKey(entry.getKey())) { a.put(entry.getKey(), a.get(entry.getKey()) + entry.getValue()); } else { a.put(entry.getKey(), entry.getValue()); } } return a; } }
@Override public Pair<TypeSubTypeValue, byte[]>[] getHistoricSerialisationPairs() { TypeSubTypeValue typeSubTypeValue = new TypeSubTypeValue(); typeSubTypeValue.setType("testType"); typeSubTypeValue.setSubType("testSubType"); return new Pair[]{ new Pair(typeSubTypeValue, new byte[]{116, 101, 115, 116, 84, 121, 112, 101, 0, 116, 101, 115, 116, 83, 117, 98, 84, 121, 112, 101, 0}) }; } }
/** * Adds a new key and value to the map if the key is not already there. * If the key is already there, the value supplied is added to the existing value for the key and the result is inserted into the map. * * @param key The key in the map to increment or insert. * @param value The value to increment by or initialise to. */ public void upsert(final String key, final Long value) { final Long currentValue = get(key); if (null == currentValue) { put(key, value); } else { put(key, currentValue + value); } }
@Override public IntegerFreqMap _apply(final IntegerFreqMap a, final IntegerFreqMap b) { for (final Entry<String, Integer> entry : b.entrySet()) { if (a.containsKey(entry.getKey())) { a.put(entry.getKey(), a.get(entry.getKey()) + entry.getValue()); } else { a.put(entry.getKey(), entry.getValue()); } } return a; } }
@Override public TypeSubTypeValue deserialiseEmpty() { return new TypeSubTypeValue(); } }
@Override public TypeValue apply(final Object value) { return new TypeValue(null, null != value ? value.toString() : null); } }
/** * Adds a new key and value to the map if the key is not already there. * If the key is already there, the value supplied is added to the existing value for the key and the result is inserted into the map. * * @param key The key in the map to increment or insert. * @param value The value to increment by or initialise to. */ public void upsert(final String key, final Integer value) { final Integer currentValue = get(key); if (null == currentValue) { put(key, value); } else { put(key, currentValue + value); } }
@Override @SuppressWarnings("unchecked") public Pair<IntegerFreqMap, byte[]>[] getHistoricSerialisationPairs() { IntegerFreqMap freqMap = new IntegerFreqMap(); freqMap.put("x", 10); freqMap.put("y", 5); freqMap.put("z", 20); return new Pair[]{ new Pair(freqMap, new byte[]{120, 92, 44, 49, 48, 92, 44, 121, 92, 44, 53, 92, 44, 122, 92, 44, 50, 48}) }; }
/** * Increments the value of an existing key by 1. * If the key doesn't exist, initialises the value to 1. * * @param key The key to increment or insert. */ public void upsert(final String key) { upsert(key, 1L); } }
@Override public IntegerFreqMap deserialiseEmpty() throws SerialisationException { return new IntegerFreqMap(); }
@Override public FreqMap apply(final Object value) { return new FreqMap(null != value ? value.toString() : null); } }
@Override public TypeSubTypeValue apply(final Object value) { return new TypeSubTypeValue(null, null, null != value ? value.toString() : null); } }
@Override public Pair<TypeValue, byte[]>[] getHistoricSerialisationPairs() { TypeValue typeValue = new TypeValue("testType", "testValue"); return new Pair[]{ new Pair(typeValue, new byte[]{116, 101, 115, 116, 84, 121, 112, 101, 0, 116, 101, 115, 116, 86, 97, 108, 117, 101}) }; } }
public FreqMap(final String initialKey) { super(); upsert(initialKey); }
@Before public void initialiseFreqMap() { freqMap = new FreqMap(); }