Skip to content

Commit

Permalink
remove unused method
Browse files Browse the repository at this point in the history
Signed-off-by: Dharin Shah <[email protected]>
  • Loading branch information
Dharin-shah committed Jan 27, 2024
1 parent c025016 commit 9938f11
Showing 1 changed file with 0 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -632,48 +632,6 @@ public String[] readOptionalStringArray() throws IOException {
return null;
}

/**
* Reads a {@link Map} from a data source using provided key and value readers and a map constructor.
*
* This method is a flexible utility for reading a map from a data source, such as a file or network stream.
* It uses the provided `keyReader` and `valueReader` to read each key-value pair. The size of the map is
* determined first by reading the array size. A map constructor is also provided to create a map of the
* appropriate size, allowing for optimized performance based on the expected number of entries.
*
* If the read size is zero, an empty map is returned. Otherwise, the method iterates over the size,
* reading keys and values and adding them to the map.
*
* Usage example:
* <pre><code>
* Map&lt;Integer, String&gt; map = readMap(StreamInput::readInteger, StreamInput::readString, HashMap::new);
* </code></pre>
*
* Note: If the map is empty, an immutable empty map is returned. Otherwise, a mutable map is created.
*
* @param keyReader The {@link Writeable.Reader} used to read the keys of the map.
* @param valueReader The {@link Writeable.Reader} used to read the values of the map.
* @param constructor A function that takes an integer (the initial size) and returns a new map.
* This allows for the creation of a map with an initial capacity matching the
* expected size, optimizing performance.
* @return A {@link Map} containing the keys and values read from the data source. This map is either
* empty (and immutable) or mutable and filled with the read data.
* @throws IOException If an I/O error occurs during reading from the data source.
*/
private <K, V> Map<K, V> readMap(Writeable.Reader<K> keyReader, Writeable.Reader<V> valueReader, IntFunction<Map<K, V>> constructor)
throws IOException {
int size = readArraySize();
if (size == 0) {
return Collections.emptyMap();
}
Map<K, V> map = constructor.apply(size);
for (int i = 0; i < size; i++) {
K key = keyReader.read(this);
V value = valueReader.read(this);
map.put(key, value);
}
return map;
}

/**
* If the returned map contains any entries it will be mutable. If it is empty it might be immutable.
*/
Expand Down

0 comments on commit 9938f11

Please sign in to comment.