Skip to content

Commit

Permalink
simplify TokenElement constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuke committed Aug 17, 2015
1 parent fb8a72d commit 69d2ad7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
12 changes: 0 additions & 12 deletions redpen-core/src/main/java/cc/redpen/tokenizer/TokenElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ public final class TokenElement implements Serializable {
// the character position of the token in the sentence
final private int offset;

TokenElement(String word) {
this(word, Collections.unmodifiableList(new ArrayList<>()), 0);
}

TokenElement(String word, String tag) {
this(word, Collections.unmodifiableList(Arrays.asList(tag)), 0);
}

TokenElement(String word, List<String> tagList) {
this(word, Collections.unmodifiableList(tagList), 0);
}

TokenElement(String word, List<String> tagList, int offset) {
surface = word;
tags = Collections.unmodifiableList(tagList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@

import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class TokenElementTest {
@Test(expected = UnsupportedOperationException.class)
public void testTagsImmutable() {
TokenElement token = new TokenElement("foobar", "tag");
TokenElement token = new TokenElement("foobar", Collections.unmodifiableList(Arrays.asList("tag")), 0);
List<String> tags = token.getTags();
tags.add("baz");
}

@Test
public void testSurfaceImmutable() {
TokenElement token = new TokenElement("foobar", "tag");
TokenElement token = new TokenElement("foobar", Collections.unmodifiableList(Arrays.asList("tag")), 0);
String surface = token.getSurface();
surface = "baz";
assertEquals("foobar", token.getSurface());
Expand Down

0 comments on commit 69d2ad7

Please sign in to comment.