Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.skiwi.tessutils4j.data;
- import com.skiwi.tessutils4j.Objects;
- import java.io.InvalidObjectException;
- import java.io.ObjectInputStream;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.List;
- /**
- *
- * @author Frank van Heeswijk
- */
- public class Word implements Serializable {
- private static final long serialVersionUID = 9084633893292833L;
- private final String word;
- private final float confidence;
- private final FontAttributes fontAttributes;
- private final boolean fromDictionary;
- private final boolean numeric;
- private final Rectangle boundingBox;
- private final Rectangle baseline;
- private final List<Symbol> symbols;
- private Word(final String word, final float confidence, final FontAttributes fontAttributes, final boolean fromDictionary, final boolean numeric, final Rectangle boundingBox, final Rectangle baseline, final List<Symbol> symbols) {
- this.word = Objects.requireNonNull(word, "word");
- this.confidence = confidence;
- this.fontAttributes = Objects.requireNonNull(fontAttributes, "fontAttributes");
- this.fromDictionary = fromDictionary;
- this.numeric = numeric;
- this.boundingBox = Objects.requireNonNull(boundingBox, "boundingBox");
- this.baseline = Objects.requireNonNull(baseline, "baseline");
- this.symbols = Objects.requireNonNull(symbols, "symbols");
- }
- public String getWord() {
- return word;
- }
- public float getConfidence() {
- return confidence;
- }
- public FontAttributes getFontAttributes() {
- return fontAttributes;
- }
- public boolean isFromDictionary() {
- return fromDictionary;
- }
- public boolean isNumeric() {
- return numeric;
- }
- public Rectangle getBoundingBox() {
- return boundingBox;
- }
- public Rectangle getBaseline() {
- return baseline;
- }
- public List<Symbol> getSymbols() {
- return symbols;
- }
- public static class WordBuilder {
- private final String word;
- private final float confidence;
- private final FontAttributes fontAttributes;
- private final boolean fromDictionary;
- private final boolean numeric;
- private final Rectangle boundingBox;
- private final Rectangle baseline;
- private final List<Symbol> symbols = new ArrayList<Symbol>();
- private WordBuilder(final String word, final float confidence, final FontAttributes fontAttributes, final boolean fromDictionary, final boolean numeric, final Rectangle boundingBox, final Rectangle baseline) {
- this.word = word;
- this.confidence = confidence;
- this.fontAttributes = fontAttributes;
- this.fromDictionary = fromDictionary;
- this.numeric = numeric;
- this.boundingBox = boundingBox;
- this.baseline = baseline;
- }
- public WordBuilder addSymbol(final Symbol symbol) {
- symbols.add(Objects.requireNonNull(symbol, "symbol"));
- return this;
- }
- public Word build() {
- return new Word(word, confidence, fontAttributes, fromDictionary, numeric, boundingBox, baseline, symbols);
- }
- }
- private Object writeReplace() {
- return new SerializationProxy(this);
- }
- private void readObject(final ObjectInputStream stream) throws InvalidObjectException {
- throw new InvalidObjectException("Proxy required");
- }
- private static class SerializationProxy implements Serializable {
- private static final long serialVersionUID = 794943938877393932L;
- private final String word;
- private final float confidence;
- private final FontAttributes fontAttributes;
- private final boolean fromDictionary;
- private final boolean numeric;
- private final Rectangle boundingBox;
- private final Rectangle baseline;
- private final List<Symbol> symbols;
- private SerializationProxy(final Word word) {
- this.word = word.word;
- this.confidence = word.confidence;
- this.fontAttributes = word.fontAttributes;
- this.fromDictionary = word.fromDictionary;
- this.numeric = word.numeric;
- this.boundingBox = word.boundingBox;
- this.baseline = word.baseline;
- this.symbols = word.symbols;
- }
- private Object readResolve() {
- return new Word(word, confidence, fontAttributes, fromDictionary, numeric, boundingBox, baseline, symbols);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment