Skip to content

Commit

Permalink
Sorted Pattern List
Browse files Browse the repository at this point in the history
  • Loading branch information
torifat committed Nov 2, 2011
1 parent 19c4732 commit 46f7c48
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/com/omicronlab/avro/PhoneticParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package com.omicronlab.avro;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.omicronlab.avro.phonetic.*;
Expand Down Expand Up @@ -68,6 +69,8 @@ public synchronized void init() throws Exception {
}
Data data = loader.getData();
patterns = data.getPatterns();
Collections.sort(patterns);

vowel = data.getVowel();
consonant = data.getConsonant();
casesensitive = data.getCasesensitive();
Expand Down
14 changes: 13 additions & 1 deletion src/com/omicronlab/avro/phonetic/Pattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.List;
import java.util.ArrayList;

public class Pattern {
public class Pattern implements Comparable<Pattern> {

private String find;
private String replace;
Expand Down Expand Up @@ -63,5 +63,17 @@ public List<Rule> getRules() {
public void addRule(Rule rule) {
rules.add(rule);
}

@Override
public int compareTo(Pattern p) {
if(this.find.length() < p.getFind().length()) {
return 1;
}
else if(this.find.length() == p.getFind().length()) {
return 0;
} else {
return -1;
}
}

}

0 comments on commit 46f7c48

Please sign in to comment.