Java Reference
In-Depth Information
@Override
public DatabaseLine apply(final TextLine textLine) {
// Get the text id
int textId = lookupTextId(textLine);
// Get the line id
int lineId = lookupLineId(textId, textLine);
// Get the word ids
int[] words = textLine.getWords().parallelStream()
.mapToInt(this::lookupWord)
.toArray();
return new DatabaseLine(lineId, words);
}
private int lookupWord(final String word) {
return wordIds.computeIfAbsent(word, this::computeWordId);
}
private int lookupLineId(int textId, final TextLine textLine) {
ConcurrentMap<Integer, Integer> lineIds =
textLineIds.computeIfAbsent(textId, i -> new ConcurrentHashMap());
return lineIds.computeIfAbsent(
textLine.getLineNumber(),
i -> this.computeLineId(textId, i)
);
}
private int lookupTextId(final TextLine textLine) {
return textIds.computeIfAbsent(
textLine.getTitle(),
s -> this.computeTextId(s, textLine.getYear())
);
}
}
### DatabaseLine.java
import java.util.*;
/**
* A line of a text as understood by the database.
*/
public class DatabaseLine {
private final int lineId;
private final int[] words;
Search WWH ::




Custom Search