From 46f7c481a76024b6583005d4b2cfe965237a8c47 Mon Sep 17 00:00:00 2001 From: Rifat Nabi Date: Wed, 2 Nov 2011 17:34:39 +0600 Subject: [PATCH] Sorted Pattern List --- src/com/omicronlab/avro/PhoneticParser.java | 3 +++ src/com/omicronlab/avro/phonetic/Pattern.java | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/com/omicronlab/avro/PhoneticParser.java b/src/com/omicronlab/avro/PhoneticParser.java index dd9b3f3..7deed37 100644 --- a/src/com/omicronlab/avro/PhoneticParser.java +++ b/src/com/omicronlab/avro/PhoneticParser.java @@ -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.*; @@ -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(); diff --git a/src/com/omicronlab/avro/phonetic/Pattern.java b/src/com/omicronlab/avro/phonetic/Pattern.java index 00c1518..fd73b81 100644 --- a/src/com/omicronlab/avro/phonetic/Pattern.java +++ b/src/com/omicronlab/avro/phonetic/Pattern.java @@ -30,7 +30,7 @@ import java.util.List; import java.util.ArrayList; -public class Pattern { +public class Pattern implements Comparable { private String find; private String replace; @@ -63,5 +63,17 @@ public List 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; + } + } }