congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
FreqMap.put
Code IndexAdd Tabnine 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)

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
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • onRequestPermissionsResult (Fragment)
  • scheduleAtFixedRate (Timer)
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • JComboBox (javax.swing)
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • 21 Best Atom Packages for 2021
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now