All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.chen0040.data.text.BasicVocabulary Maven / Gradle / Ivy

There is a newer version: 1.0.3
Show newest version
package com.github.chen0040.data.text;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


/**
 * Created by xschen on 14/8/15.
 */
public class BasicVocabulary implements Serializable, Vocabulary {
    private static final long serialVersionUID = -4386706542135437234L;
    private List words;
    public BasicVocabulary(List words){
        this.words = words;
    }

    public BasicVocabulary(){
        words = new ArrayList<>();
    }

    public int getLength(){
        return words.size();
    }

    public String get(int index){
        return words.get(index);
    }

    public boolean contains(String word){
        return words.indexOf(word) != -1;
    }

    public void add(String word){
        words.add(word);
    }

    public void setWords(List words){
        this.words = words;
    }

    @Override
    public Vocabulary makeCopy(){
        BasicVocabulary clone = new BasicVocabulary(clone(words));
        return clone;
    }

    private List clone(List rhs){
        List clone = new ArrayList<>();
        clone.addAll(rhs);
        return clone;
    }

    public int indexOf(String word){
        return words.indexOf(word);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy