use of uk.gov.gchq.gaffer.types.IntegerFreqMap in project Gaffer by gchq.
the class IntegerFreqMapSerialiser method deserialise.
@Override
public IntegerFreqMap deserialise(final byte[] bytes) throws SerialisationException {
IntegerFreqMap freqMap = new IntegerFreqMap();
if (bytes.length == 0) {
return freqMap;
}
String stringMap;
try {
stringMap = new String(bytes, CommonConstants.ISO_8859_1_ENCODING);
} catch (UnsupportedEncodingException e) {
throw new SerialisationException(e.getMessage(), e);
}
if (stringMap.isEmpty()) {
//No values so return the empty map
return freqMap;
}
String[] keyValues = stringMap.split(SEPERATOR_REGEX);
if (keyValues.length % 2 != 0) {
throw new SerialisationException("Uneven number of entries found for serialised frequency map, unable to deserialise.");
}
for (int i = 0; i < keyValues.length - 1; i += 2) {
freqMap.put(keyValues[i], Integer.parseInt(keyValues[i + 1]));
}
return freqMap;
}
Aggregations