[FOray-commit] SF.net SVN: foray: [7818] trunk/foray/foray-hyphen-r
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2006-07-23 19:36:41
|
Revision: 7818 Author: victormote Date: 2006-07-23 12:36:26 -0700 (Sun, 23 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7818&view=rev Log Message: ----------- Implement standard use of final modifier on local variable and method parameters. Modified Paths: -------------- trunk/foray/foray-hyphen-r/.project trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/ByteVector.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/CharVector.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphen.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphenation.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/SerializeHyphPattern.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/TernaryTree.java Modified: trunk/foray/foray-hyphen-r/.project =================================================================== --- trunk/foray/foray-hyphen-r/.project 2006-07-23 19:16:06 UTC (rev 7817) +++ trunk/foray/foray-hyphen-r/.project 2006-07-23 19:36:26 UTC (rev 7818) @@ -1,17 +1,17 @@ <?xml version="1.0" encoding="UTF-8"?> <projectDescription> - <name>FOrayHyphenR</name> + <name>FOrayHyphen-R</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> - <name>com.atlassw.tools.eclipse.checkstyle.CheckstyleBuilder</name> + <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> + <name>com.atlassw.tools.eclipse.checkstyle.CheckstyleBuilder</name> <arguments> </arguments> </buildCommand> Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/ByteVector.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/ByteVector.java 2006-07-23 19:16:06 UTC (rev 7817) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/ByteVector.java 2006-07-23 19:36:26 UTC (rev 7818) @@ -55,7 +55,7 @@ this(DEFAULT_BLOCK_SIZE); } - public ByteVector(int capacity) { + public ByteVector(final int capacity) { if (capacity > 0) { BLOCK_SIZE = capacity; } else { @@ -65,13 +65,13 @@ n = 0; } - public ByteVector(byte[] a) { + public ByteVector(final byte[] a) { BLOCK_SIZE = DEFAULT_BLOCK_SIZE; array = a; n = 0; } - public ByteVector(byte[] a, int capacity) { + public ByteVector(final byte[] a, final int capacity) { if (capacity > 0) { BLOCK_SIZE = capacity; } else { @@ -99,22 +99,22 @@ return array.length; } - public void put(int index, byte val) { + public void put(final int index, final byte val) { array[index] = val; } - public byte get(int index) { + public byte get(final int index) { return array[index]; } /** * This is to implement memory allocation in the array. Like malloc(). */ - public int alloc(int size) { - int index = n; - int len = array.length; + public int alloc(final int size) { + final int index = n; + final int len = array.length; if (n + size >= len) { - byte[] aux = new byte[len + BLOCK_SIZE]; + final byte[] aux = new byte[len + BLOCK_SIZE]; System.arraycopy(array, 0, aux, 0, len); array = aux; } @@ -124,7 +124,7 @@ public void trimToSize() { if (n < array.length) { - byte[] aux = new byte[n]; + final byte[] aux = new byte[n]; System.arraycopy(array, 0, aux, 0, n); array = aux; } Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/CharVector.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/CharVector.java 2006-07-23 19:16:06 UTC (rev 7817) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/CharVector.java 2006-07-23 19:36:26 UTC (rev 7818) @@ -55,7 +55,7 @@ this(DEFAULT_BLOCK_SIZE); } - public CharVector(int capacity) { + public CharVector(final int capacity) { if (capacity > 0) { BLOCK_SIZE = capacity; } else { @@ -65,13 +65,13 @@ n = 0; } - public CharVector(char[] a) { + public CharVector(final char[] a) { BLOCK_SIZE = DEFAULT_BLOCK_SIZE; array = a; n = a.length; } - public CharVector(char[] a, int capacity) { + public CharVector(final char[] a, final int capacity) { if (capacity > 0) { BLOCK_SIZE = capacity; } else { @@ -89,7 +89,7 @@ } public Object clone() { - CharVector cv = new CharVector((char[])array.clone(), BLOCK_SIZE); + final CharVector cv = new CharVector((char[])array.clone(), BLOCK_SIZE); cv.n = this.n; return cv; } @@ -112,19 +112,19 @@ return array.length; } - public void put(int index, char val) { + public void put(final int index, final char val) { array[index] = val; } - public char get(int index) { + public char get(final int index) { return array[index]; } - public int alloc(int size) { - int index = n; - int len = array.length; + public int alloc(final int size) { + final int index = n; + final int len = array.length; if (n + size >= len) { - char[] aux = new char[len + BLOCK_SIZE]; + final char[] aux = new char[len + BLOCK_SIZE]; System.arraycopy(array, 0, aux, 0, len); array = aux; } @@ -134,7 +134,7 @@ public void trimToSize() { if (n < array.length) { - char[] aux = new char[n]; + final char[] aux = new char[n]; System.arraycopy(array, 0, aux, 0, n); array = aux; } Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphen.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphen.java 2006-07-23 19:16:06 UTC (rev 7817) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphen.java 2006-07-23 19:36:26 UTC (rev 7818) @@ -46,13 +46,13 @@ public String noBreak; public String postBreak; - Hyphen(String pre, String no, String post) { + Hyphen(final String pre, final String no, final String post) { preBreak = pre; noBreak = no; postBreak = post; } - Hyphen(String pre) { + Hyphen(final String pre) { preBreak = pre; noBreak = null; postBreak = null; @@ -65,7 +65,7 @@ && preBreak.equals("-")) { return "-"; } - StringBuffer res = new StringBuffer("{"); + final StringBuffer res = new StringBuffer("{"); res.append(preBreak); res.append("}{"); res.append(postBreak); Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphenation.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphenation.java 2006-07-23 19:16:06 UTC (rev 7817) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphenation.java 2006-07-23 19:36:26 UTC (rev 7818) @@ -44,7 +44,7 @@ /* Always store the weights using the Liang weights. */ private byte[] hyphenValues; - Hyphenation(String word, int[] points, byte[] values) { + Hyphenation(final String word, final int[] points, final byte[] values) { this.word = word; this.hyphenPoints = points; this.hyphenValues = values; @@ -71,12 +71,12 @@ if (this.hyphenValues == null) { return null; } - byte[] returnArray = new byte[this.hyphenValues.length]; + final byte[] returnArray = new byte[this.hyphenValues.length]; for (int i = 0; i < this.hyphenValues.length; i++) { - byte value = this.hyphenValues[i]; + final byte value = this.hyphenValues[i]; try { returnArray[i] = convertLiangToWeight(value); - } catch (HyphenationException e) { + } catch (final HyphenationException e) { /* TODO: This exception should be passed upstream further. */ returnArray[i] = Byte.MIN_VALUE; } @@ -85,7 +85,7 @@ } public String toString() { - StringBuffer str = new StringBuffer(); + final StringBuffer str = new StringBuffer(); int start = 0; for (int i = 0; i < hyphenPoints.length; i++) { str.append(word.substring(start, hyphenPoints[i]) + "-"); @@ -112,7 +112,7 @@ + liangValue); } /* Save the low-order bit. */ - boolean good = (liangValue & 1) == 1; + final boolean good = (liangValue & 1) == 1; liangValue ++; liangValue /= 2; if (! good) { @@ -124,7 +124,7 @@ /** * {@inheritDoc} */ - public HyphenBreak getHyphenBreak(int index) { + public HyphenBreak getHyphenBreak(final int index) { /* TODO: Consider implementing this. */ return null; } Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java 2006-07-23 19:16:06 UTC (rev 7817) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java 2006-07-23 19:36:26 UTC (rev 7818) @@ -74,13 +74,14 @@ * Constructor. * @param logger The Log instance for user messages. */ - public HyphenationServer(Log logger, URL hyphenationDir) { + public HyphenationServer(final Log logger, final URL hyphenationDir) { this.logger = logger; // TODO: This is klunky. Use the URL. this.hyphenationDir = hyphenationDir.getFile(); } - private HyphenationTree getHyphenationTree(String lang, String country) { + private HyphenationTree getHyphenationTree(final String lang, + final String country) { String key = lang; // check whether the country code has been used if (country != null && !country.equals("none")) { @@ -95,9 +96,9 @@ } /* See if it is one that we already have tried and failed. */ - Iterator iter = hyphenTreesNotFound.iterator(); + final Iterator iter = hyphenTreesNotFound.iterator(); while (iter.hasNext()) { - String testedKey = (String) iter.next(); + final String testedKey = (String) iter.next(); if (key.equals(testedKey)) { return null; } @@ -121,20 +122,20 @@ return hTree; } - private InputStream getResourceStream(String key) { + private InputStream getResourceStream(final String key) { InputStream is = null; // Try to use Context Class Loader to load the properties file. try { - Method getCCL = + final Method getCCL = Thread.class.getMethod("getContextClassLoader", new Class[0]); if (getCCL != null) { - ClassLoader contextClassLoader = + final ClassLoader contextClassLoader = (ClassLoader)getCCL.invoke(Thread.currentThread(), new Object[0]); is = contextClassLoader.getResourceAsStream("hyph/" + key + ".hyp"); } - } catch (Exception e) {} + } catch (final Exception e) {} if (is == null) { is = HyphenationServer.class.getResourceAsStream("/hyph/" + key @@ -144,7 +145,7 @@ return is; } - private HyphenationTree getHyphenationTree(String key) { + private HyphenationTree getHyphenationTree(final String key) { HyphenationTree hTree = null; ObjectInputStream ois = null; InputStream is = null; @@ -178,14 +179,14 @@ } ois = new ObjectInputStream(is); hTree = (HyphenationTree)ois.readObject(); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } finally { if (ois != null) { try { ois.close(); - } catch (IOException e) { + } catch (final IOException e) { getLogger().error("can't close hyphenation object stream"); } } @@ -197,8 +198,8 @@ * load tree from serialized file or xml file * using configuration settings */ - private HyphenationTree loadHyphenationTree(String key, - String language) { + private HyphenationTree loadHyphenationTree(final String key, + final String language) { if (this.hyphenationDir == null) { return null; } @@ -215,14 +216,14 @@ try { ois = new ObjectInputStream(new FileInputStream(hyphenFile)); hTree = (HyphenationTree)ois.readObject(); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } finally { if (ois != null) { try { ois.close(); - } catch (IOException e) {} + } catch (final IOException e) {} } } return hTree; @@ -246,7 +247,7 @@ hTree.printStats(getLogger()); } return hTree; - } catch (HyphenationException ex) { + } catch (final HyphenationException ex) { if (errorDump) { getLogger().error("Can't load user patterns " + "from xml file " + this.hyphenationDir @@ -264,17 +265,19 @@ return null; } - public org.axsl.hyphenR.Hyphenation hyphenate(CharSequence word, int offset, - int len, String language, String country, int remainCount, - int pushCount, boolean includeInhibitors) { + public org.axsl.hyphenR.Hyphenation hyphenate(final CharSequence word, + final int offset, final int len, final String language, + final String country, final int remainCount, final int pushCount, + final boolean includeInhibitors) { return this.hyphenate(word.toString().toCharArray(), offset, len, language, country, remainCount, pushCount, includeInhibitors); } - public org.axsl.hyphenR.Hyphenation hyphenate(char[] word, int offset, - int len, String language, String country, int remainCount, - int pushCount, boolean includeInhibitors) { - HyphenationTree hTree = getHyphenationTree(language, country); + public org.axsl.hyphenR.Hyphenation hyphenate(final char[] word, + final int offset, final int len, final String language, + final String country, final int remainCount, + final int pushCount, final boolean includeInhibitors) { + final HyphenationTree hTree = getHyphenationTree(language, country); if (hTree == null) { return null; } @@ -282,13 +285,14 @@ includeInhibitors); } - public org.axsl.hyphenR.Hyphenation hyphenate(int[] word, int offset, - int len, String language, String country, int remainCount, - int pushCount, boolean includeInhibitors) { + public org.axsl.hyphenR.Hyphenation hyphenate(final int[] word, + final int offset, final int len, final String language, + final String country, final int remainCount, final int pushCount, + final boolean includeInhibitors) { /* Convert to a String using the 32-bit ICU4J method. */ /* TODO: After Java 5 is the minimum, use the standard String * constructor instead. */ - String string = StringUtilPre5.newString(word, offset, len); + final String string = StringUtilPre5.newString(word, offset, len); /* FIXME: The Hyphenation instance needs to know that it was created * from an int[] instead of a char[], so that it can properly handle * surrogate pairs (an int that would convert to 2 chars).*/ @@ -303,17 +307,17 @@ /** * {@inheritDoc} */ - public int wordSize(char[] characters, int wordStart, String language, - String country) { + public int wordSize(final char[] characters, final int wordStart, + final String language, final String country) { if (characters == null) { return 0; } boolean wordendFound = false; int counter = 0; - int[] newWord = new int[characters.length]; // create a buffer + final int[] newWord = new int[characters.length]; // create a buffer while ((!wordendFound) && ((wordStart + counter) < characters.length)) { - int tk = characters[wordStart + counter]; + final int tk = characters[wordStart + counter]; if (StringUtilPre5.isLetter(tk)) { newWord[counter] = tk; counter++; @@ -327,8 +331,8 @@ /** * {@inheritDoc} */ - public int wordSize(CharSequence characters, int wordStart, String language, - String country) { + public int wordSize(final CharSequence characters, final int wordStart, + final String language, final String country) { if (characters == null) { return 0; } @@ -339,15 +343,15 @@ /** * {@inheritDoc} */ - public int wordSize(int[] characters, int wordStart, String language, - String country) { + public int wordSize(final int[] characters, final int wordStart, + final String language, final String country) { if (characters == null) { return 0; } /* Convert to a String using the 32-bit ICU4J method. */ /* TODO: After Java 5 is the minimum, use the standard String * constructor instead. */ - String string = StringUtilPre5.newString(characters, wordStart, + final String string = StringUtilPre5.newString(characters, wordStart, (characters.length - wordStart)); /* FIXME: Return value needs to be reduced by the number of surrogate * pairs (an int that would convert to 2 chars) found.*/ @@ -357,14 +361,14 @@ /** * {@inheritDoc} */ - public int wordStarts(char[] characters, int startIndex, String language, - String country) { + public int wordStarts(final char[] characters, final int startIndex, + final String language, final String country) { if (characters == null) { return -1; } /* TODO: We need to handle language and country here. */ for (int i = startIndex; i < characters.length; i++) { - char c = characters[i]; + final char c = characters[i]; switch(c) { case '"': case '\'': { @@ -382,8 +386,8 @@ /** * {@inheritDoc} */ - public int wordStarts(CharSequence characters, int startIndex, - String language, String country) { + public int wordStarts(final CharSequence characters, final int startIndex, + final String language, final String country) { if (characters == null) { return -1; } @@ -391,15 +395,15 @@ language, country); } - public int wordStarts(int[] characters, int startIndex, - String language, String country) { + public int wordStarts(final int[] characters, final int startIndex, + final String language, final String country) { if (characters == null) { return -1; } /* Convert to a String using the 32-bit ICU4J method. */ /* TODO: After Java 5 is the minimum, use the standard String * constructor instead. */ - String string = StringUtilPre5.newString(characters, startIndex, + final String string = StringUtilPre5.newString(characters, startIndex, (characters.length - startIndex)); /* FIXME: Return value needs to be reduced by the number of surrogate * pairs (an int that would convert to 2 chars) found.*/ Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java 2006-07-23 19:16:06 UTC (rev 7817) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java 2006-07-23 19:36:26 UTC (rev 7818) @@ -89,14 +89,15 @@ * @return the index into the vspace array where the packed values * are stored. */ - protected int packValues(String values) { - int i, n = values.length(); - int m = (n & 1) == 1 ? (n >> 1) + 2 : (n >> 1) + 1; - int offset = vspace.alloc(m); - byte[] va = vspace.getArray(); + protected int packValues(final String values) { + int i; + final int n = values.length(); + final int m = (n & 1) == 1 ? (n >> 1) + 2 : (n >> 1) + 1; + final int offset = vspace.alloc(m); + final byte[] va = vspace.getArray(); for (i = 0; i < n; i++) { - int j = i >> 1; - byte v = (byte)((values.charAt(i) - '0' + 1) & 0x0f); + final int j = i >> 1; + final byte v = (byte)((values.charAt(i) - '0' + 1) & 0x0f); if ((i & 1) == 1) { va[j + offset] = (byte)(va[j + offset] | v); } else { @@ -108,7 +109,7 @@ } protected String unpackValues(int k) { - StringBuffer buf = new StringBuffer(); + final StringBuffer buf = new StringBuffer(); byte v = vspace.get(k++); while (v != 0) { char c = (char)((v >>> 4) - 1 + '0'); @@ -127,9 +128,9 @@ /** * Read hyphenation patterns from an XML file. */ - public void loadPatterns(String filename, Log logger) + public void loadPatterns(final String filename, final Log logger) throws HyphenationException { - PatternParser pp = new PatternParser(this, logger); + final PatternParser pp = new PatternParser(this, logger); ivalues = new TernaryTree(); pp.parse(filename); @@ -144,8 +145,8 @@ ivalues = null; } - public String findPattern(String pat) { - int k = super.find(pat); + public String findPattern(final String pat) { + final int k = super.find(pat); if (k >= 0) { return unpackValues(k); } @@ -156,7 +157,7 @@ * String compare, returns 0 if equal or * t is a substring of s */ - protected int hstrcmp(char[] s, int si, char[] t, int ti) { + protected int hstrcmp(final char[] s, int si, final char[] t, int ti) { for (; s[si] == t[ti]; si++, ti++) { if (s[si] == 0) { return 0; @@ -169,7 +170,7 @@ } protected byte[] getValues(int k) { - StringBuffer buf = new StringBuffer(); + final StringBuffer buf = new StringBuffer(); byte v = vspace.get(k++); while (v != 0) { char c = (char)((v >>> 4) - 1); @@ -182,7 +183,7 @@ buf.append(c); v = vspace.get(k++); } - byte[] res = new byte[buf.length()]; + final byte[] res = new byte[buf.length()]; for (int i = 0; i < res.length; i++) { res[i] = (byte)buf.charAt(i); } @@ -213,7 +214,8 @@ * @param index start index from word * @param il interletter values array to update */ - protected void searchPatterns(char[] word, int index, byte[] il) { + protected void searchPatterns(final char[] word, final int index, + final byte[] il) { byte[] values; int i = index; char p, q; @@ -234,7 +236,7 @@ } return; } - int d = sp - sc[p]; + final int d = sp - sc[p]; if (d == 0) { if (sp == 0) { break; @@ -285,14 +287,15 @@ * @return a {@link Hyphenation Hyphenation} object representing * the hyphenated word or null if word is not hyphenated. */ - public org.axsl.hyphenR.Hyphenation hyphenate(char[] w, int offset, int len, - int remainCharCount, int pushCharCount, boolean includeInhibitors) { - char[] word = normalizeWord(w, offset, len); + public org.axsl.hyphenR.Hyphenation hyphenate(final char[] w, + final int offset, final int len, final int remainCharCount, + final int pushCharCount, final boolean includeInhibitors) { + final char[] word = normalizeWord(w, offset, len); if (word == null) { return null; } - String theWord = new String(w, offset, len); + final String theWord = new String(w, offset, len); Hyphenation hyphenation = checkExceptions(theWord, remainCharCount, pushCharCount); if (hyphenation != null) { @@ -308,26 +311,27 @@ * @param k * @return The new Hyphenation instance. */ - private Hyphenation createHyphenation(String theWord, int[] points, - byte[] values, int k) { + private Hyphenation createHyphenation(final String theWord, + final int[] points, final byte[] values, final int k) { if (k > 0) { // trim result array - int[] returnPoints = new int[k]; + final int[] returnPoints = new int[k]; System.arraycopy(points, 0, returnPoints, 0, k); - byte[] returnValues = new byte[k]; + final byte[] returnValues = new byte[k]; System.arraycopy(values, 0, returnValues, 0, k); return new Hyphenation(theWord, returnPoints, returnValues); } return null; } - private char[] normalizeWord(char[] w, int offset, int len) { - char[] word = new char[len + 3]; + private char[] normalizeWord(final char[] w, final int offset, + final int len) { + final char[] word = new char[len + 3]; - char[] c = new char[2]; + final char[] c = new char[2]; for (int i = 1; i <= len; i++) { c[0] = w[offset + i - 1]; - int nc = classmap.find(c, 0); + final int nc = classmap.find(c, 0); if (nc < 0) { // found a non-letter character, abort return null; } @@ -336,20 +340,20 @@ return word; } - private Hyphenation checkExceptions(String sw, int remainCharCount, - int pushCharCount) { + private Hyphenation checkExceptions(final String sw, + final int remainCharCount, final int pushCharCount) { if (! stoplist.containsKey(sw)) { return null; } - int length = sw.length(); - int[] result = new int[length + 1]; + final int length = sw.length(); + final int[] result = new int[length + 1]; int k = 0; /* assume only simple hyphens (Hyphen.pre="-", * Hyphen.post = Hyphen.no = null) */ - ArrayList hw = (ArrayList)stoplist.get(sw); + final ArrayList hw = (ArrayList)stoplist.get(sw); int j = 0; for (int i = 0; i < hw.size(); i++) { - Object o = hw.get(i); + final Object o = hw.get(i); if (o instanceof String) { j += ((String)o).length(); if (j >= remainCharCount @@ -359,31 +363,32 @@ } } /* Assume that all found points have a value of 1. */ - byte[] values = new byte[result.length]; + final byte[] values = new byte[result.length]; for (int i = 0; i < values.length; i++) { values[i] = 1; } return createHyphenation(sw, result, values, k); } - private Hyphenation checkAlgorithm(String theWord, int remainCharCount, - int pushCharCount, char[] word, boolean includeInhibitors) { - int len = theWord.length(); + private Hyphenation checkAlgorithm(final String theWord, + final int remainCharCount, final int pushCharCount, + final char[] word, final boolean includeInhibitors) { + final int len = theWord.length(); // use algorithm to get hyphenation points - int[] result = new int[len + 1]; - byte[] values = new byte[result.length]; + final int[] result = new int[len + 1]; + final byte[] values = new byte[result.length]; int k = 0; word[0] = '.'; // word start marker word[len + 1] = '.'; // word end marker word[len + 2] = 0; // null terminated - byte[] il = new byte[len + 3]; // initialized to zero + final byte[] il = new byte[len + 3]; // initialized to zero for (int i = 0; i < len + 1; i++) { searchPatterns(word, i, il); } for (int i = 0; i < len; i++) { - byte interletterValue = il[i + 1]; - boolean reportValue = reportValue(interletterValue, i, len, + final byte interletterValue = il[i + 1]; + final boolean reportValue = reportValue(interletterValue, i, len, remainCharCount, pushCharCount, includeInhibitors); if (reportValue) { k++; @@ -394,8 +399,9 @@ return createHyphenation(theWord, result, values, k); } - private boolean reportValue(byte interletterValue, int index, int length, - int remainCharCount, int pushCharCount, boolean includeInhibitors) { + private boolean reportValue(final byte interletterValue, final int index, + final int length, final int remainCharCount, + final int pushCharCount, final boolean includeInhibitors) { /* Zeroes are never reported. */ if (interletterValue == 0) { return false; @@ -429,10 +435,10 @@ * for letter 'a', for example, should be defined as "aA", the first * character being the normalization char. */ - public void addClass(String chargroup) { + public void addClass(final String chargroup) { if (chargroup.length() > 0) { - char equivChar = chargroup.charAt(0); - char[] key = new char[2]; + final char equivChar = chargroup.charAt(0); + final char[] key = new char[2]; key[1] = 0; for (int i = 0; i < chargroup.length(); i++) { key[0] = chargroup.charAt(i); @@ -449,7 +455,8 @@ * @param hyphenatedword a ArrayList of alternating strings and * {@link Hyphen hyphen} objects. */ - public void addException(String word, ArrayList hyphenatedword) { + public void addException(final String word, + final ArrayList hyphenatedword) { stoplist.put(word, hyphenatedword); } @@ -463,7 +470,7 @@ * within the pattern. It should contain only digit characters. * (i.e. '0' to '9'). */ - public void addPattern(String pattern, String ivalue) { + public void addPattern(final String pattern, final String ivalue) { int k = ivalues.find(ivalue); if (k <= 0) { k = packValues(ivalue); @@ -472,16 +479,16 @@ insert(pattern, (char)k); } - public void printStats(Log logger) { + public void printStats(final Log logger) { logger.info("Value space size = " + Integer.toString(vspace.length())); super.printStats(logger); } - public static void main(String[] argv) throws Exception { - Log logger = Logging.makeDefaultLogger(); + public static void main(final String[] argv) throws Exception { + final Log logger = Logging.makeDefaultLogger(); HyphenationTree ht = null; int minCharCount = 2; - BufferedReader in = + final BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); for (; ; ) { logger.info("l:\tload patterns from XML\n" @@ -514,14 +521,14 @@ try { ois = new ObjectInputStream(new FileInputStream(token)); ht = (HyphenationTree)ois.readObject(); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } finally { if (ois != null) { try { ois.close(); - } catch (IOException e) {} + } catch (final IOException e) {} } } } else if (token.equals("w")) { @@ -531,17 +538,17 @@ try { oos = new ObjectOutputStream(new FileOutputStream(token)); oos.writeObject(ht); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } finally { if (oos != null) { try { oos.flush(); - } catch (IOException e) {} + } catch (final IOException e) {} try { oos.close(); - } catch (IOException e) {} + } catch (final IOException e) {} } } } else if (token.equals("h")) { @@ -561,19 +568,19 @@ int counter = 0; ; try { - BufferedReader reader = + final BufferedReader reader = new BufferedReader(new FileReader(token)); starttime = System.currentTimeMillis(); while ((reader.readLine()) != null) { counter++; } - } catch (Exception ioe) { + } catch (final Exception ioe) { logger.info("Exception " + ioe); ioe.printStackTrace(); } - long endtime = System.currentTimeMillis(); - long result = endtime - starttime; + final long endtime = System.currentTimeMillis(); + final long result = endtime - starttime; logger.info(counter + " words hypehanted in " + result + " milliseconds."); Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java 2006-07-23 19:16:06 UTC (rev 7817) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java 2006-07-23 19:36:26 UTC (rev 7818) @@ -65,7 +65,7 @@ static final int ELEM_PATTERNS = 3; static final int ELEM_HYPHEN = 4; - public PatternParser(Log logger) throws HyphenationException { + public PatternParser(final Log logger) throws HyphenationException { this.logger = logger; token = new StringBuffer(); parser = createParser(); @@ -74,26 +74,26 @@ hyphenChar = '-'; // default } - public PatternParser(PatternConsumer consumer, Log logger) + public PatternParser(final PatternConsumer consumer, final Log logger) throws HyphenationException { this(logger); this.consumer = consumer; } - public void setConsumer(PatternConsumer consumer) { + public void setConsumer(final PatternConsumer consumer) { this.consumer = consumer; } - public void parse(String filename) throws HyphenationException { - InputSource uri = fileInputSource(filename); + public void parse(final String filename) throws HyphenationException { + final InputSource uri = fileInputSource(filename); try { parser.parse(uri); - } catch (SAXException e) { + } catch (final SAXException e) { throw new HyphenationException(errMsg); - } catch (IOException e) { + } catch (final IOException e) { throw new HyphenationException(e.getMessage()); - } catch (NullPointerException e) { + } catch (final NullPointerException e) { throw new HyphenationException("SAX parser not available"); } } @@ -111,16 +111,16 @@ } try { return (XMLReader)Class.forName(parserClassName).newInstance(); - } catch (ClassNotFoundException e) { + } catch (final ClassNotFoundException e) { throw new HyphenationException("Could not find " + parserClassName); - } catch (InstantiationException e) { + } catch (final InstantiationException e) { throw new HyphenationException("Could not instantiate " + parserClassName); - } catch (IllegalAccessException e) { + } catch (final IllegalAccessException e) { throw new HyphenationException("Could not access " + parserClassName); - } catch (ClassCastException e) { + } catch (final ClassCastException e) { throw new HyphenationException(parserClassName + " is not a SAX driver"); } @@ -132,13 +132,13 @@ * @param filename the name of the file * @return the InputSource created */ - protected static InputSource fileInputSource(String filename) + protected static InputSource fileInputSource(final String filename) throws HyphenationException { /* this code adapted from James Clark's in XT */ - File file = new File(filename); + final File file = new File(filename); String path = file.getAbsolutePath(); - String fSep = System.getProperty("file.separator"); + final String fSep = System.getProperty("file.separator"); if (fSep != null && fSep.length() == 1) { path = path.replace(fSep.charAt(0), '/'); } @@ -148,12 +148,12 @@ try { return new InputSource(URLFactory.createURL("file", null, path).toString()); - } catch (MalformedURLException e) { + } catch (final MalformedURLException e) { throw new HyphenationException("unexpected MalformedURLException"); } } - protected String readToken(StringBuffer chars) { + protected String readToken(final StringBuffer chars) { String word; boolean space = false; int i; @@ -196,9 +196,9 @@ return null; } - protected static String getPattern(String word) { - StringBuffer pat = new StringBuffer(); - int len = word.length(); + protected static String getPattern(final String word) { + final StringBuffer pat = new StringBuffer(); + final int len = word.length(); for (int i = 0; i < len; i++) { if (!Character.isDigit(word.charAt(i))) { pat.append(word.charAt(i)); @@ -207,21 +207,21 @@ return pat.toString(); } - protected ArrayList normalizeException(ArrayList ex) { - ArrayList res = new ArrayList(); + protected ArrayList normalizeException(final ArrayList ex) { + final ArrayList res = new ArrayList(); for (int i = 0; i < ex.size(); i++) { - Object item = ex.get(i); + final Object item = ex.get(i); if (item instanceof String) { - String str = (String)item; - StringBuffer buf = new StringBuffer(); + final String str = (String)item; + final StringBuffer buf = new StringBuffer(); for (int j = 0; j < str.length(); j++) { - char c = str.charAt(j); + final char c = str.charAt(j); if (c != hyphenChar) { buf.append(c); } else { res.add(buf.toString()); buf.setLength(0); - char[] h = new char[1]; + final char[] h = new char[1]; h[0] = hyphenChar; // we use here hyphenChar which is not necessarily // the one to be printed @@ -238,10 +238,10 @@ return res; } - protected String getExceptionWord(ArrayList ex) { - StringBuffer res = new StringBuffer(); + protected String getExceptionWord(final ArrayList ex) { + final StringBuffer res = new StringBuffer(); for (int i = 0; i < ex.size(); i++) { - Object item = ex.get(i); + final Object item = ex.get(i); if (item instanceof String) { res.append((String)item); } else { @@ -253,12 +253,13 @@ return res.toString(); } - protected static String getInterletterValues(String pat) { - StringBuffer il = new StringBuffer(); - String word = pat + "a"; // add dummy letter to serve as sentinel - int len = word.length(); + protected static String getInterletterValues(final String pat) { + final StringBuffer il = new StringBuffer(); + // add dummy letter to serve as sentinel + final String word = pat + "a"; + final int len = word.length(); for (int i = 0; i < len; i++) { - char c = word.charAt(i); + final char c = word.charAt(i); if (Character.isDigit(c)) { il.append(c); i++; @@ -276,10 +277,10 @@ /** * Start element. */ - public void startElement(String uri, String local, String raw, - Attributes attrs) { + public void startElement(final String uri, final String local, + final String raw, final Attributes attrs) { if (local.equals("hyphen-char")) { - String h = attrs.getValue("value"); + final String h = attrs.getValue("value"); if (h != null && h.length() == 1) { hyphenChar = h.charAt(0); } @@ -301,10 +302,10 @@ token.setLength(0); } - public void endElement(String uri, String local, String raw) { - + public void endElement(final String uri, final String local, + final String raw) { if (token.length() > 0) { - String word = token.toString(); + final String word = token.toString(); switch (currElement) { case ELEM_CLASSES: consumer.addClass(word); @@ -337,8 +338,8 @@ /** * Characters. */ - public void characters(char ch[], int start, int length) { - StringBuffer chars = new StringBuffer(length); + public void characters(final char ch[], final int start, final int length) { + final StringBuffer chars = new StringBuffer(length); chars.append(ch, start, length); String word = readToken(chars); while (word != null) { @@ -370,7 +371,7 @@ /** * Warning. */ - public void warning(SAXParseException ex) { + public void warning(final SAXParseException ex) { errMsg = "[Warning] " + getLocationString(ex) + ": " + ex.getMessage(); } @@ -378,14 +379,14 @@ /** * Error. */ - public void error(SAXParseException ex) { + public void error(final SAXParseException ex) { errMsg = "[Error] " + getLocationString(ex) + ": " + ex.getMessage(); } /** * Fatal error. */ - public void fatalError(SAXParseException ex) throws SAXException { + public void fatalError(final SAXParseException ex) throws SAXException { errMsg = "[Fatal Error] " + getLocationString(ex) + ": " + ex.getMessage(); throw ex; @@ -394,12 +395,12 @@ /** * Returns a string of the location. */ - private String getLocationString(SAXParseException ex) { - StringBuffer str = new StringBuffer(); + private String getLocationString(final SAXParseException ex) { + final StringBuffer str = new StringBuffer(); String systemId = ex.getSystemId(); if (systemId != null) { - int index = systemId.lastIndexOf('/'); + final int index = systemId.lastIndexOf('/'); if (index != -1) { systemId = systemId.substring(index + 1); } @@ -416,22 +417,22 @@ // PatternConsumer implementation for testing purposes - public void addClass(String c) { + public void addClass(final String c) { this.logger.info("class: " + c); } - public void addException(String w, ArrayList e) { + public void addException(final String w, final ArrayList e) { this.logger.info("exception: " + w + " : " + e.toString()); } - public void addPattern(String p, String v) { + public void addPattern(final String p, final String v) { this.logger.info("pattern: " + p + " : " + v); } - public static void main(String[] args) throws Exception { - Log logger = Logging.makeDefaultLogger(); + public static void main(final String[] args) throws Exception { + final Log logger = Logging.makeDefaultLogger(); if (args.length > 0) { - PatternParser pp = new PatternParser(logger); + final PatternParser pp = new PatternParser(logger); pp.setConsumer(pp); pp.parse(args[0]); } Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/SerializeHyphPattern.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/SerializeHyphPattern.java 2006-07-23 19:16:06 UTC (rev 7817) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/SerializeHyphPattern.java 2006-07-23 19:36:26 UTC (rev 7818) @@ -50,8 +50,8 @@ * Main method, which is called by ant. */ public void execute() throws BuildException { - DirectoryScanner ds = this.getDirectoryScanner(sourceDir); - String[] files = ds.getIncludedFiles(); + final DirectoryScanner ds = this.getDirectoryScanner(sourceDir); + final String[] files = ds.getIncludedFiles(); for (int i = 0; i < files.length; i++) { processFile(files[i].substring(0, files[i].length() - 4)); } @@ -62,8 +62,8 @@ * Sets the source directory * */ - public void setSourceDir(String sourceDir) { - File dir = new File(sourceDir); + public void setSourceDir(final String sourceDir) { + final File dir = new File(sourceDir); if (!dir.exists()) { getLogger().error("Fatal Error: source directory " + sourceDir + " for hyphenation files doesn't exist."); @@ -76,8 +76,8 @@ * Sets the target directory * */ - public void setTargetDir(String targetDir) { - File dir = new File(targetDir); + public void setTargetDir(final String targetDir) { + final File dir = new File(targetDir); this.targetDir = dir; } @@ -85,7 +85,7 @@ * more error information * */ - public void setErrorDump(boolean errorDump) { + public void setErrorDump(final boolean errorDump) { this.errorDump = errorDump; } @@ -94,9 +94,9 @@ * Checks whether input or output files exists or the latter is older than * input file and start build if necessary */ - private void processFile(String filename) { - File infile = new File(sourceDir, filename + ".xml"); - File outfile = new File(targetDir, filename + ".hyp"); + private void processFile(final String filename) { + final File infile = new File(sourceDir, filename + ".xml"); + final File outfile = new File(targetDir, filename + ".hyp"); boolean startProcess = true; startProcess = rebuild(infile, outfile); @@ -108,16 +108,16 @@ /* * serializes pattern files */ - private void buildPatternFile(File infile, File outfile) { + private void buildPatternFile(final File infile, final File outfile) { getLogger().info("Processing " + infile); - HyphenationTree hTree = new HyphenationTree(); + final HyphenationTree hTree = new HyphenationTree(); try { hTree.loadPatterns(infile.toString(), getLogger()); if (errorDump) { getLogger().info("Stats: "); hTree.printStats(getLogger()); } - } catch (HyphenationException ex) { + } catch (final HyphenationException ex) { getLogger().error("Can't load patterns from xml file " + infile + " - Maybe hyphenation.dtd is missing?"); if (errorDump) { @@ -126,11 +126,11 @@ } // serialize class try { - ObjectOutputStream out = + final ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(outfile)); out.writeObject(hTree); out.close(); - } catch (IOException ioe) { + } catch (final IOException ioe) { getLogger().error("Can't write compiled pattern file: " + outfile); getLogger().error(ioe.toString()); } @@ -140,7 +140,7 @@ * Checks for existence of output file and compares * dates with input and stylesheet file */ - private boolean rebuild(File infile, File outfile) { + private boolean rebuild(final File infile, final File outfile) { if (outfile.exists()) { // checks whether output file is older than input file if (outfile.lastModified() < infile.lastModified()) { Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/TernaryTree.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/TernaryTree.java 2006-07-23 19:16:06 UTC (rev 7817) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/TernaryTree.java 2006-07-23 19:36:26 UTC (rev 7818) @@ -147,21 +147,21 @@ * is inserted. This saves a lot of space, * specially for long keys. */ - public void insert(String key, char val) { + public void insert(final String key, final char val) { // make sure we have enough room in the arrays int len = key.length() + 1; // maximum number of nodes that may be generated if (freenode + len > eq.length) { redimNodeArrays(eq.length + BLOCK_SIZE); } - char strkey[] = new char[len--]; + final char strkey[] = new char[len--]; key.getChars(0, len, strkey, 0); strkey[len] = 0; root = insert(root, strkey, 0, val); } - public void insert(char[] key, int start, char val) { - int len = strlen(key) + 1; + public void insert(final char[] key, final int start, final char val) { + final int len = strlen(key) + 1; if (freenode + len > eq.length) { redimNodeArrays(eq.length + BLOCK_SIZE); } @@ -171,8 +171,9 @@ /** * The actual insertion function, recursive version. */ - private char insert(char p, char[] key, int start, char val) { - int len = strlen(key, start); + private char insert(char p, final char[] key, final int start, + final char val) { + final int len = strlen(key, start); if (p == 0) { // this means there is no branch, this node will start a new branch. // Instead of doing that, we store the key somewhere else and create @@ -194,7 +195,7 @@ } if (sc[p] == 0xFFFF) { - char pp = freenode++; + final char pp = freenode++; lo[pp] = lo[p]; eq[pp] = eq[p]; lo[p] = 0; @@ -218,7 +219,7 @@ return p; } } - char s = key[start]; + final char s = key[start]; if (s < sc[p]) { lo[p] = insert(lo[p], key, start, val); } else if (s == sc[p]) { @@ -238,7 +239,8 @@ /** * Compares 2 null terminated char arrays */ - public static int strcmp(char[] a, int startA, char[] b, int startB) { + public static int strcmp(final char[] a, int startA, final char[] b, + int startB) { for (; a[startA] == b[startB]; startA++, startB++) { if (a[startA] == 0) { return 0; @@ -250,8 +252,11 @@ /** * Compares a string with null terminated char array */ - public static int strcmp(String str, char[] a, int start) { - int i, d, len = str.length(); + public static int strcmp(final String str, final char[] a, + final int start) { + int i; + int d; + final int len = str.length(); for (i = 0; i < len; i++) { d = str.charAt(i) - a[start + i]; if (d != 0) { @@ -268,14 +273,15 @@ } - public static void strcpy(char[] dst, int di, char[] src, int si) { + public static void strcpy(final char[] dst, int di, final char[] src, + int si) { while (src[si] != 0) { dst[di++] = src[si++]; } dst[di] = 0; } - public static int strlen(char[] a, int start) { + public static int strlen(final char[] a, final int start) { int len = 0; for (int i = start; i < a.length && a[i] != 0; i++) { len++; @@ -283,20 +289,20 @@ return len; } - public static int strlen(char[] a) { + public static int strlen(final char[] a) { return strlen(a, 0); } - public int find(String key) { - int len = key.length(); - char strkey[] = new char[len + 1]; + public int find(final String key) { + final int len = key.length(); + final char strkey[] = new char[len + 1]; key.getChars(0, len, strkey, 0); strkey[len] = 0; return find(strkey, 0); } - public int find(char[] key, int start) { + public int find(final char[] key, final int start) { int d; char p = root; int i = start; @@ -326,13 +332,13 @@ return -1; } - public boolean knows(String key) { + public boolean knows(final String key) { return (find(key) >= 0); } // redimension the arrays - private void redimNodeArrays(int newsize) { - int len = newsize < lo.length ? newsize : lo.length; + private void redimNodeArrays(final int newsize) { + final int len = newsize < lo.length ? newsize : lo.length; char[] na = new char[newsize]; System.arraycopy(lo, 0, na, 0, len); lo = na; @@ -352,7 +358,7 @@ } public Object clone() { - TernaryTree t = new TernaryTree(); + final TernaryTree t = new TernaryTree(); t.lo = (char[])this.lo.clone(); t.hi = (char[])this.hi.clone(); t.eq = (char[])this.eq.clone(); @@ -371,7 +377,8 @@ * tree. The array of keys is assumed to be sorted in ascending * order. */ - protected void insertBalanced(String[] k, char[] v, int offset, int n) { + protected void insertBalanced(final String[] k, final char[] v, + final int offset, final int n) { int m; if (n < 1) { return; @@ -389,10 +396,11 @@ * Balance the tree for best search performance */ public void balance() { - int i = 0, n = length; - String[] k = new String[n]; - char[] v = new char[n]; - Iterator iter = new Iterator(); + int i = 0; + final int n = length; + final String[] k = new String[n]; + final char[] v = new char[n]; + final Iterator iter = new Iterator(); while (iter.hasMoreElements()) { v[i] = iter.getValue(); k[i++] = (String)iter.nextElement(); @@ -423,15 +431,16 @@ redimNodeArrays(freenode); // ok, compact kv array - CharVector kx = new CharVector(); + final CharVector kx = new CharVector(); kx.alloc(1); - TernaryTree map = new TernaryTree(); + final TernaryTree map = new TernaryTree(); compact(kx, map, root); kv = kx; kv.trimToSize(); } - private void compact(CharVector kx, TernaryTree map, char p) { + private void compact(final CharVector kx, final TernaryTree map, + final char p) { int k; if (p == 0) { return; @@ -479,7 +488,7 @@ child = 0; } - public Item(char p, char c) { + public Item(final char p, final char c) { parent = p; child = c; } @@ -515,7 +524,7 @@ } public Object nextElement() { - String res = new String(curkey); + final String res = new String(curkey); cur = up(); run(); return res; @@ -620,7 +629,7 @@ } // The current node should be a data node and // the key should be in the key stack (at least partially) - StringBuffer buf = new StringBuffer(ks.toString()); + final StringBuffer buf = new StringBuffer(ks.toString()); if (sc[cur] == 0xFFFF) { int p = lo[cur]; while (kv.get(p) != 0) { @@ -633,7 +642,7 @@ } - public void printStats(Log logger) { + public void printStats(final Log logger) { logger.info("Number of keys = " + Integer.toString(length)); logger.info("Node count = " + Integer.toString(freenode)); logger.info("Key Array length = " + Integer.toString(kv.length())); @@ -651,9 +660,9 @@ } - public static void main(String[] args) throws Exception { - Log logger = Logging.makeDefaultLogger(); - TernaryTree tt = new TernaryTree(); + public static void main(final String[] args) throws Exception { + final Log logger = Logging.makeDefaultLogger(); + final TernaryTree tt = new TernaryTree(); tt.insert("Carlos", 'C'); tt.insert("Car", 'r'); tt.insert("palos", 'l'); @@ -666,4 +675,3 @@ } } - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |