Modernise Java codebase (Java 8 features)
This commit is contained in:
parent
22092218af
commit
b787a1fdaa
|
|
@ -38,7 +38,7 @@ public abstract class BinaryParser implements BlockReaderAdapter {
|
|||
/** Take a Info protocol buffer containing a date and convert it into a java Date object */
|
||||
protected Date getDate(Osmformat.Info info) {
|
||||
if (info.hasTimestamp()) {
|
||||
return new Date(date_granularity * (long) info.getTimestamp());
|
||||
return new Date(date_granularity * info.getTimestamp());
|
||||
} else
|
||||
return NODATE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,8 +82,8 @@ public class BinarySerializer implements Closeable, Flushable {
|
|||
/** How many primitives have been seen in this batch */
|
||||
protected int batch_size = 0;
|
||||
protected int total_entities = 0;
|
||||
private StringTable stringtable = new StringTable();
|
||||
protected List<PrimGroupWriterInterface> groups = new ArrayList<PrimGroupWriterInterface>();
|
||||
private final StringTable stringtable = new StringTable();
|
||||
protected List<PrimGroupWriterInterface> groups = new ArrayList<>();
|
||||
protected BlockOutputStream output;
|
||||
|
||||
public BinarySerializer(BlockOutputStream output) {
|
||||
|
|
|
|||
|
|
@ -37,11 +37,7 @@ public class StringTable {
|
|||
private String set[];
|
||||
|
||||
public void incr(String s) {
|
||||
if (counts.containsKey(s)) {
|
||||
counts.put(s, new Integer(counts.get(s).intValue() + 1));
|
||||
} else {
|
||||
counts.put(s, new Integer(1));
|
||||
}
|
||||
counts.merge(s, 1, Integer::sum);
|
||||
}
|
||||
|
||||
/** After the stringtable has been built, return the offset of a string in it.
|
||||
|
|
@ -51,17 +47,11 @@ public class StringTable {
|
|||
* @return
|
||||
*/
|
||||
public int getIndex(String s) {
|
||||
return stringmap.get(s).intValue();
|
||||
return stringmap.get(s);
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
Comparator<String> comparator = new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(final String s1, String s2) {
|
||||
int diff = counts.get(s2) - counts.get(s1);
|
||||
return diff;
|
||||
}
|
||||
};
|
||||
Comparator<String> comparator = (s1, s2) -> counts.get(s2) - counts.get(s1);
|
||||
|
||||
/* Sort the stringtable */
|
||||
|
||||
|
|
@ -114,15 +104,15 @@ public class StringTable {
|
|||
Arrays.sort(set, Math.min(1 << 14, set.length-1), Math.min(1 << 21,
|
||||
set.length-1), comparator);
|
||||
}
|
||||
stringmap = new HashMap<String, Integer>(2 * set.length);
|
||||
stringmap = new HashMap<>(2 * set.length);
|
||||
for (int i = 0; i < set.length; i++) {
|
||||
stringmap.put(set[i], new Integer(i+1)); // Index 0 is reserved for use as a delimiter.
|
||||
stringmap.put(set[i], i + 1); // Index 0 is reserved for use as a delimiter.
|
||||
}
|
||||
counts = null;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
counts = new HashMap<String, Integer>(100);
|
||||
counts = new HashMap<>(100);
|
||||
stringmap = null;
|
||||
set = null;
|
||||
}
|
||||
|
|
@ -131,8 +121,9 @@ public class StringTable {
|
|||
Osmformat.StringTable.Builder builder = Osmformat.StringTable
|
||||
.newBuilder();
|
||||
builder.addS(ByteString.copyFromUtf8("")); // Add a unused string at offset 0 which is used as a delimiter.
|
||||
for (int i = 0; i < set.length; i++)
|
||||
builder.addS(ByteString.copyFromUtf8(set[i]));
|
||||
for (String s : set) {
|
||||
builder.addS(ByteString.copyFromUtf8(s));
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,6 @@ public class BlockOutputStream {
|
|||
}
|
||||
|
||||
OutputStream outwrite;
|
||||
List<FileBlockPosition> writtenblocks = new ArrayList<FileBlockPosition>();
|
||||
List<FileBlockPosition> writtenblocks = new ArrayList<>();
|
||||
CompressFlags compression;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue