Commit 0d976c4d by Hut

some cleanup

parent 6613e459
......@@ -20,7 +20,7 @@ public class Builder {
}
public Sentence random() {
return produce(p -> nextRandom(p));
return produce(this::nextRandom);
}
public Sentence average() {
......
......@@ -71,6 +71,6 @@ public class Data implements Serializable{
}
public void finish() {
data.values().forEach(l -> l.finishCollection());
data.values().forEach(Lookup::finishCollection);
}
}
......@@ -31,10 +31,8 @@ public class Glyph implements Serializable {
Glyph glyph = (Glyph) o;
if (type != glyph.type) {
return false;
}
return content != null ? content.equals(glyph.content) : glyph.content == null;
return type == glyph.type && (content != null ? content.equals(glyph.content) :
glyph.content == null);
}
@Override
......
......@@ -10,7 +10,7 @@ import java.util.stream.Collectors;
public class Lookup implements Serializable {
private final LinkedHashMap<Token, Integer> tokens = new LinkedHashMap<Token, Integer>();
private final LinkedHashMap<Token, Integer> tokens = new LinkedHashMap<>();
private Decission[] finalData;
private long[] finishedSums;
private boolean isFinishedCollecting = false;
......
......@@ -25,6 +25,7 @@ public class Parser {
c.reset();
}
});
return collectors.stream().collect(Collectors.toMap(c -> c.getPrefixLength(), c -> c.finishAndGetData()));
return collectors.stream().collect(Collectors.toMap(Collector::getPrefixLength,
Collector::finishAndGetData));
}
}
......@@ -71,7 +71,7 @@ public class Renderer {
sb.append(d.getToken().render(options.prefix));
}
if (options.propability) {
sb.append(" - " + sentence.propability());
sb.append(" - ").append(sentence.propability());
}
return sb.toString();
}
......
......@@ -42,8 +42,8 @@ public class Token implements Serializable, Comparable<Token> {
Token token = (Token) o;
if (content != null ? !content.equals(token.content) : token.content != null) return false;
return type == token.type;
return (content != null ? content.equals(token.content) : token.content == null) &&
type == token.type;
}
private final int hashCode;
......
......@@ -10,11 +10,15 @@ public class Tokenizer {
public Stream<Stream<Token>> tokenizeCombined(Stream<Stream<String>> input) {
return input.map(stringStream -> putMarkers(combineToTokens(stringStream.flatMap(s -> s.codePoints().boxed().map(integer -> glyphFromCodePoint(integer))))));
return input.map(stringStream -> putMarkers(combineToTokens(stringStream.flatMap(s -> s.codePoints().boxed().map(
this::glyphFromCodePoint)))));
}
public Stream<Stream<Token>> tokenize(Stream<String> input) {
return input.map(s -> putMarkers(combineToTokens(s.codePoints().boxed().map(integer -> glyphFromCodePoint(integer)))));
return input.map(s -> putMarkers(combineToTokens(s.codePoints().boxed().map(
this::glyphFromCodePoint))));
}
private Glyph glyphFromCodePoint(int codePoint) {
......@@ -58,11 +62,11 @@ public class Tokenizer {
} else {
return Stream.empty();
}
}).map(l -> getTokenFromGlyphs(l));
}).map(this::getTokenFromGlyphs);
}
private Token getTokenFromGlyphs(List<Glyph> l) {
String content = l.stream().map(glyph -> glyph.getContent()).collect(Collectors.joining());
String content = l.stream().map(Glyph::getContent).collect(Collectors.joining());
Glyph.Type type = l.get(0).getType();
return new Token(content, type);
}
......
......@@ -9,7 +9,7 @@ import java.util.function.Supplier;
public class ByteHuffmanCodeBuilder<ContentType, FrequencyType extends FrequenceType<FrequencyType>> extends HuffmanCodeBuilder<ContentType, List<Boolean>, Boolean, FrequencyType> {
private static final Supplier<List<Boolean>> rootCodeSupplier = () -> new ArrayList<>();
private static final Supplier<List<Boolean>> rootCodeSupplier = ArrayList::new;
private static final Supplier<Boolean> leftGlyph = () -> false;
private static final Supplier<Boolean> rightGlyph = () -> true;
private static final BiFunction<List<Boolean>, Boolean, List<Boolean>> combiner = (l, g) -> {
......@@ -17,7 +17,7 @@ public class ByteHuffmanCodeBuilder<ContentType, FrequencyType extends Frequence
l.add(g);
return l;
};
private static final Function<List<Boolean>, Iterator<Boolean>> splitter = l -> l.iterator();
private static final Function<List<Boolean>, Iterator<Boolean>> splitter = List::iterator;
public ByteHuffmanCodeBuilder() {
......
......@@ -55,7 +55,7 @@ public class HuffmanCodeBuilder<ContentType, SequenceType, GlyphType, FrequencyT
PriorityQueue<HuffmanTree<ContentType, SequenceType, FrequencyType>> trees = new PriorityQueue<>();
for (Map.Entry<ContentType, FrequencyType> e : frequencies.entrySet()) {
if (e.getValue().isGreaterZero())
trees.offer(new HuffmanLeaf<ContentType, SequenceType, FrequencyType>(e.getValue(), e.getKey()));
trees.offer(new HuffmanLeaf<>(e.getValue(), e.getKey()));
}
while (trees.size() > 1) {
......
......@@ -109,8 +109,8 @@ public class Utils {
public static Map<Integer, Data> createDataMap(int maxPrefix, File parent) {
System.out.println("generating data map...");
Stream<String> mails = Arrays.stream(parent.listFiles()).limit(500).map(
file -> file.toPath()).map(path -> {
Stream<String> mails = Arrays.stream(parent.listFiles()).limit(500).map(File::toPath).map
(path -> {
try {
MimeMessage m = new MimeMessage(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment