congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
FreqMap.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
uk.gov.gchq.gaffer.types.FreqMap
constructor

Best Java code snippets using uk.gov.gchq.gaffer.types.FreqMap.<init> (Showing top 20 results out of 315)

origin: gchq/Gaffer

  @Override
  public FreqMap deserialiseEmpty() {
    return new FreqMap();
  }
}
origin: gchq/Gaffer

  @Override
  public FreqMap apply(final Object value) {
    return new FreqMap(null != value ? value.toString() : null);
  }
}
origin: gchq/Gaffer

/**
 * Creates a filtered copy of the map using a supplied predicate.<br>
 * Returns a copy of the map if predicate supplied is null.
 *
 * @param map The frequency map that is to be sorted through
 * @return A new frequency map with only the filtered entries present.
 */
private FreqMap filterPredicate(final FreqMap map) {
  final FreqMap f = new FreqMap();
  if (predicate == null) {
    map.forEach(f::upsert);
  } else {
    map.entrySet().stream().filter(e -> predicate.test(e.getKey()))
        .forEach(e -> f.upsert(e.getKey(), e.getValue()));
  }
  return f;
}
origin: gchq/Gaffer

@Before
public void initialiseFreqMap() {
  freqMap = new FreqMap();
}
origin: gchq/Gaffer

@Override
public void shouldDeserialiseEmpty() throws SerialisationException {
  // When
  final FreqMap value = serialiser.deserialiseEmpty();
  // Then
  assertEquals(new FreqMap(), value);
}
origin: gchq/Gaffer

@Test
public void shouldConvertObjectToFreqMap() {
  // Given
  final ToFreqMap function = new ToFreqMap();
  final Object value = 1L;
  // When
  final FreqMap result = function.apply(value);
  // Then
  assertEquals(new FreqMap(value.toString()), result);
}
origin: gchq/Gaffer

@Test
public void shouldConvertStringToFreqMap() {
  // Given
  final ToFreqMap function = new ToFreqMap();
  final Object value = "value1";
  // When
  final FreqMap result = function.apply(value);
  // Then
  assertEquals(new FreqMap(value.toString()), result);
}
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

@Test
public void shouldConvertNullToFreqMap() {
  // Given
  final ToFreqMap function = new ToFreqMap();
  final Object value = null;
  // When
  final FreqMap result = function.apply(value);
  // Then
  assertEquals(new FreqMap((String) null), result);
}
origin: gchq/Gaffer

@Test
public void canSerialiseEmptyFreqMap() throws SerialisationException {
  byte[] b = serialiser.serialise(new FreqMap());
  Object o = serialiser.deserialise(b);
  assertEquals(FreqMap.class, o.getClass());
  assertEquals(0, ((FreqMap) o).size());
}
origin: gchq/Gaffer

@Override
public FreqMap deserialise(final byte[] bytes) throws
    SerialisationException {
  FreqMap freqMap = new FreqMap();
  if (bytes.length == 0) {
    return freqMap;
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

@Before
public void initFreqMap() {
  this.freqMap = new FreqMap();
  freqMap.upsert("cat");
  freqMap.upsert("cat");
  freqMap.upsert("dog");
  freqMap.upsert("cow");
  freqMap.upsert("cow");
  freqMap.upsert("catdog");
  freqMap.upsert("catdog");
  freqMap.upsert("catdog");
  freqMap.upsert("cat");
  freqMap.upsert("cat");
}
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 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 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 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: uk.gov.gchq.gaffer/type

  @Override
  public FreqMap deserialiseEmpty() {
    return new FreqMap();
  }
}
origin: uk.gov.gchq.gaffer/parquet-store

@Override
public FreqMap deserialise(final Object[] objects) throws SerialisationException {
  if (objects.length == 1) {
    if (objects[0] instanceof Map) {
      return new FreqMap((Map<String, Long>) objects[0]);
    } else if (null == objects[0]) {
      return null;
    }
  }
  throw new SerialisationException("Could not de-serialise objects to a FreqMap");
}
origin: uk.gov.gchq.gaffer/road-traffic-generators

  private FreqMap getVehicleCounts(final CSVRecord record) {
    final FreqMap freqMap = new FreqMap();
    for (final RoadTrafficDataField field : RoadTrafficDataField.VEHICLE_COUNTS) {
      final String value = record.get(field.fieldName());
      freqMap.upsert(field.name(), value.isEmpty() ? 0 : Long.parseLong(value));
    }
    return freqMap;
  }
}
uk.gov.gchq.gaffer.typesFreqMap<init>

Popular methods of FreqMap

  • put
  • 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

  • Running tasks concurrently on multiple threads
  • findViewById (Activity)
  • getSupportFragmentManager (FragmentActivity)
  • setScale (BigDecimal)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • Notification (javax.management)
  • Top 15 Vim Plugins
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