Codota Logo
FreqMap.put
Code IndexAdd Codota to your IDE (free)

How to use
put
method
in
uk.gov.gchq.gaffer.types.FreqMap

Best Java code snippets using uk.gov.gchq.gaffer.types.FreqMap.put (Showing top 18 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Point p =
  • Codota Iconnew Point(x, y)
  • Codota Iconnew Point()
  • Codota IconMouseEvent e;e.getPoint()
  • Smart code suggestions by Codota
}
origin: gchq/Gaffer

/**
 * 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);
  }
}
origin: gchq/Gaffer

  @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;
  }
}
origin: gchq/Gaffer

  @Override
  public Pair<FreqMap, byte[]>[] getHistoricSerialisationPairs() {
    final FreqMap freqMap = new FreqMap();
    freqMap.put("x", 10L);
    freqMap.put("y", 5L);
    freqMap.put("z", 20L);
    return new Pair[]{
        new Pair(freqMap, new byte[]{120, 0, 10, 0, 121, 0, 5, 0, 122, 0, 20})
    };
  }
}
origin: gchq/Gaffer

    freqMap.put(key, value);
    key = null;
freqMap.put(key, value);
origin: gchq/Gaffer

@Test
public void shouldMergeFreqMaps() {
  // Given
  final FreqMapAggregator aggregator = new FreqMapAggregator();
  final FreqMap freqMap1 = new FreqMap();
  freqMap1.put("1", 2L);
  freqMap1.put("2", 3L);
  final FreqMap freqMap2 = new FreqMap();
  freqMap2.put("2", 4L);
  freqMap2.put("3", 5L);
  // When
  final FreqMap result = aggregator.apply(freqMap1, freqMap2);
  // Then
  assertEquals((Long) 2L, result.get("1"));
  assertEquals((Long) 7L, result.get("2"));
  assertEquals((Long) 5L, result.get("3"));
}
origin: gchq/Gaffer

@Test
public void shouldSkipEntryWithNullKey() throws SerialisationException {
  // Given
  final FreqMap freqMap = new FreqMap();
  freqMap.put(null, 10L);
  freqMap.put("y", 5L);
  freqMap.put("z", 20L);
  // When
  final byte[] serialised = serialiser.serialise(freqMap);
  final FreqMap deserialised = serialiser.deserialise(serialised);
  assertFalse(deserialised.containsKey("x"));
  assertEquals((Long) 5L, deserialised.get("y"));
  assertEquals((Long) 20L, deserialised.get("z"));
}
origin: gchq/Gaffer

@Test
public void shouldSkipEntryWithNullValues() throws SerialisationException {
  // Given
  final FreqMap freqMap = new FreqMap();
  freqMap.put("v", null);
  freqMap.put("w", 5L);
  freqMap.put("x", null);
  freqMap.put("y", 20L);
  freqMap.put("z", null);
  // When
  final byte[] serialised = serialiser.serialise(freqMap);
  final FreqMap deserialised = serialiser.deserialise(serialised);
  assertFalse(deserialised.containsKey("v"));
  assertEquals((Long) 5L, deserialised.get("w"));
  assertFalse(deserialised.containsKey("x"));
  assertEquals((Long) 20L, deserialised.get("y"));
  assertFalse(deserialised.containsKey("z"));
}
origin: gchq/Gaffer

@Test
public void shouldSerialiseDeserialiseFreqMapWithAnEmptyKey() throws SerialisationException {
  // Given
  final FreqMap freqMap = new FreqMap();
  freqMap.put("", 10L);
  freqMap.put("y", 5L);
  freqMap.put("z", 20L);
  // When
  final byte[] serialised = serialiser.serialise(freqMap);
  final FreqMap deserialised = serialiser.deserialise(serialised);
  assertEquals((Long) 10L, deserialised.get(""));
  assertEquals((Long) 5L, deserialised.get("y"));
  assertEquals((Long) 20L, deserialised.get("z"));
}
origin: gchq/Gaffer

@Test
public void shouldSerialiseDeserialiseFreqMapWithValues() throws SerialisationException {
  // Given
  final FreqMap freqMap = new FreqMap();
  freqMap.put("x", 10L);
  freqMap.put("y", 5L);
  freqMap.put("z", 20L);
  // When
  final byte[] serialised = serialiser.serialise(freqMap);
  final FreqMap deserialised = serialiser.deserialise(serialised);
  // Then
  assertEquals((Long) 10L, deserialised.get("x"));
  assertEquals((Long) 5L, deserialised.get("y"));
  assertEquals((Long) 20L, deserialised.get("z"));
}
origin: gchq/Gaffer

@Test
public void testUpsertUpdatesExistingKeyValue() {
  //given
  final String key = "test";
  final Long initialValue = 3L;
  final Long increment = 11L;
  final Long expected = 14L;
  freqMap.put(key, initialValue);
  //when
  freqMap.upsert(key, increment);
  //then
  assertEquals(freqMap.get(key), expected);
}
origin: gchq/Gaffer

  @Test
  public void testKeyExistsButValueNullIsHandled() {

    //given
    final String key = "test";
    freqMap.put(key, null);
    final Long initialValue = 7L;
    final Long expectedValue = 8L;

    //when
    freqMap.upsert(key, 7L);
    freqMap.upsert(key);

    //then
    assertEquals(freqMap.get(key), expectedValue);
  }
}
origin: uk.gov.gchq.gaffer/type

/**
 * 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);
  }
}
origin: uk.gov.gchq.gaffer/type

  @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;
  }
}
origin: uk.gov.gchq.gaffer/example-graph

public void freqMapIsMoreThan2() {
  // ---------------------------------------------------------
  final MapFilter function = new MapFilter("key1", new IsMoreThan(2L));
  // ---------------------------------------------------------
  final FreqMap map1 = new FreqMap();
  map1.put("key1", 1L);
  final FreqMap map2 = new FreqMap();
  map2.put("key1", 2L);
  final FreqMap map3 = new FreqMap();
  map3.put("key1", 3L);
  final FreqMap map4 = new FreqMap();
  map4.put("key1", 3L);
  map4.put("key2", 0L);
  final FreqMap map5 = new FreqMap();
  map5.put("key2", 3L);
  runExample(function, map1, map2, map3, map4, map5);
}
origin: uk.gov.gchq.gaffer/example-graph

public void freqMapIsMoreThanOrEqualTo2() {
  // ---------------------------------------------------------
  final MapFilter function = new MapFilter("key1", new IsMoreThan(2L, true));
  // ---------------------------------------------------------
  final FreqMap map1 = new FreqMap();
  map1.put("key1", 1L);
  final FreqMap map2 = new FreqMap();
  map2.put("key1", 2L);
  final FreqMap map3 = new FreqMap();
  map3.put("key1", 3L);
  final FreqMap map4 = new FreqMap();
  map4.put("key1", 3L);
  map4.put("key2", 0L);
  final FreqMap map5 = new FreqMap();
  map5.put("key2", 3L);
  runExample(function, map1, map2, map3, map4, map5);
}
origin: uk.gov.gchq.gaffer/doc

public void freqMapIsMoreThan2() {
  // ---------------------------------------------------------
  final PredicateMap function = new PredicateMap("key1", new IsMoreThan(2L));
  // ---------------------------------------------------------
  final FreqMap map1 = new FreqMap();
  map1.put("key1", 1L);
  final FreqMap map2 = new FreqMap();
  map2.put("key1", 2L);
  final FreqMap map3 = new FreqMap();
  map3.put("key1", 3L);
  final FreqMap map4 = new FreqMap();
  map4.put("key1", 3L);
  map4.put("key2", 0L);
  final FreqMap map5 = new FreqMap();
  map5.put("key2", 3L);
  runExample(function,
      null,
      map1, map2, map3, map4, map5);
}
origin: uk.gov.gchq.gaffer/doc

public void freqMapIsMoreThanOrEqualTo2() {
  // ---------------------------------------------------------
  final PredicateMap function = new PredicateMap("key1", new IsMoreThan(2L, true));
  // ---------------------------------------------------------
  final FreqMap map1 = new FreqMap();
  map1.put("key1", 1L);
  final FreqMap map2 = new FreqMap();
  map2.put("key1", 2L);
  final FreqMap map3 = new FreqMap();
  map3.put("key1", 3L);
  final FreqMap map4 = new FreqMap();
  map4.put("key1", 3L);
  map4.put("key2", 0L);
  final FreqMap map5 = new FreqMap();
  map5.put("key2", 3L);
  runExample(function,
      null,
      map1, map2, map3, map4, map5);
}
origin: uk.gov.gchq.gaffer/type

    freqMap.put(key, value);
    key = null;
freqMap.put(key, value);
uk.gov.gchq.gaffer.typesFreqMapput

Popular methods of FreqMap

  • <init>
  • upsert
    Adds a new key and value to the map if the key is not already there. If the key is already there, th
  • containsKey
  • get
  • entrySet
  • forEach
  • size
  • values

Popular in Java

  • Finding current android device location
  • addToBackStack (FragmentTransaction)
  • onRequestPermissionsResult (Fragment)
  • setScale (BigDecimal)
    Returns a BigDecimal whose scale is the specified value, and whose value is numerically equal to thi
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • HashSet (java.util)
    This class implements the Set interface, backed by a hash table (actually a HashMap instance). It m
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • LogFactory (org.apache.commons.logging)
    A minimal incarnation of Apache Commons Logging's LogFactory API, providing just the common Log look
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now