diff --git a/source/org/thdl/media/SmartPlayerFactory.java b/source/org/thdl/media/SmartPlayerFactory.java index 672f323..2adb9c5 100644 --- a/source/org/thdl/media/SmartPlayerFactory.java +++ b/source/org/thdl/media/SmartPlayerFactory.java @@ -21,6 +21,8 @@ package org.thdl.media; import java.lang.reflect.*; import java.util.*; +import org.thdl.util.ThdlDebug; + public class SmartPlayerFactory { /** You cannot instantiate this class. */ private SmartPlayerFactory() { } @@ -33,7 +35,7 @@ public class SmartPlayerFactory { for (int i=0; i 0) dp.setText(""); java.util.List textContent = text.getContent(); ImageIcon[] icons = sd.getSpeakerIcons(); Iterator textIter = textContent.iterator(); - boolean wasLastComponent = true; +// boolean wasLastComponent = true; while (textIter.hasNext()) { Object nextContent = textIter.next(); if (nextContent instanceof org.jdom.Text) { String wylie = ((org.jdom.Text)nextContent).getText(); dp.toTibetanMachineWeb(wylie, tDoc.getLength()); - wasLastComponent = false; +// wasLastComponent = false; } else if (nextContent instanceof org.jdom.Element) { org.jdom.Element e = (org.jdom.Element)nextContent; @@ -1050,7 +1045,7 @@ if (keyboard_url != null) { } */ new TimePoint(dp, clockIcon, Integer.valueOf(e.getAttributeValue("t"))); - wasLastComponent = true; +// wasLastComponent = true; } else if (e.getName().equals("who")) { /* if (!wasLastComponent) @@ -1062,7 +1057,7 @@ if (keyboard_url != null) { } */ dp.insertComponent(new JLabel(" ", icons[Integer.parseInt(e.getAttributeValue("id"))], SwingConstants.LEFT)); - wasLastComponent = true; +// wasLastComponent = true; } } } @@ -1534,7 +1529,7 @@ public JMenuBar getTextMenuBar() { return bar; } -public int findNextText(int startPos, TibetanDocument sourceDoc, TibetanDocument findDoc) { +public int findNextText(int startPos, StyledDocument sourceDoc, StyledDocument findDoc) { if (startPos<0 || startPos>sourceDoc.getLength()-1) return -1; diff --git a/source/org/thdl/savant/JdkVersionHacks.java b/source/org/thdl/savant/JdkVersionHacks.java index 26f34fa..bb935cf 100644 --- a/source/org/thdl/savant/JdkVersionHacks.java +++ b/source/org/thdl/savant/JdkVersionHacks.java @@ -146,8 +146,6 @@ public final class JdkVersionHacks { // f.getToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH) // if possible. - boolean success = false; - Method isFSSMethod = null; try { isFSSMethod diff --git a/source/org/thdl/savant/Savant.java b/source/org/thdl/savant/Savant.java index d821b96..cd04e9e 100644 --- a/source/org/thdl/savant/Savant.java +++ b/source/org/thdl/savant/Savant.java @@ -262,7 +262,7 @@ public class Savant extends JDesktopPane fullScreen.getContentPane().setBackground(Color.black); Dimension screenSize = fullScreen.getToolkit().getScreenSize(); Dimension videoSize = sp.getVisualComponent().getPreferredSize(); - Dimension controlSize = sp.getControlComponent().getPreferredSize(); +// Dimension controlSize = sp.getControlComponent().getPreferredSize(); int videoWidth = videoSize.width; int videoHeight = videoSize.height; float vWidth = new Integer(videoWidth).floatValue(); diff --git a/source/org/thdl/savant/tib/TibetanEnglish.java b/source/org/thdl/savant/tib/TibetanEnglish.java index d0ce83b..63e73f5 100644 --- a/source/org/thdl/savant/tib/TibetanEnglish.java +++ b/source/org/thdl/savant/tib/TibetanEnglish.java @@ -80,11 +80,11 @@ public class TibetanEnglish implements TranscriptView Element current = null; DuffData[] dd; - DuffData[] space = TibTextUtils.getTibetanMachineWeb("_"); +// DuffData[] space = TibTextUtils.getTibetanMachineWeb("_"); MutableAttributeSet mas = new SimpleAttributeSet(); StyleConstants.setForeground(mas, Color.blue); Position endPos = null; - int wherestart; +// int wherestart; TibetanDocument doc = new TibetanDocument(new StyleContext()); @@ -111,7 +111,7 @@ public class TibetanEnglish implements TranscriptView } else { - wherestart = endPos.getOffset(); +// wherestart = endPos.getOffset(); doc.insertString(endPos.getOffset(), wylie, mas); } @@ -153,7 +153,7 @@ public class TibetanEnglish implements TranscriptView { doc.insertString(endPos.getOffset(), "\n", null); String wylie = current.getAttributeValue("who"); - wherestart = endPos.getOffset(); +// wherestart = endPos.getOffset(); doc.insertString(endPos.getOffset(), wylie, mas); if (iter.hasNext()) current = (org.jdom.Element)iter.next(); diff --git a/source/org/thdl/savant/tib/TibetanWylie.java b/source/org/thdl/savant/tib/TibetanWylie.java index db24ce7..52bb63e 100644 --- a/source/org/thdl/savant/tib/TibetanWylie.java +++ b/source/org/thdl/savant/tib/TibetanWylie.java @@ -81,11 +81,11 @@ public class TibetanWylie implements TranscriptView String wylie; DuffData[] dd; - DuffData[] space = TibTextUtils.getTibetanMachineWeb("_"); +// DuffData[] space = TibTextUtils.getTibetanMachineWeb("_"); MutableAttributeSet mas = new SimpleAttributeSet(); StyleConstants.setForeground(mas, Color.blue); Position endPos = null; - int wherestart; +// int wherestart; TibetanDocument doc = new TibetanDocument(new StyleContext()); @@ -112,7 +112,7 @@ public class TibetanWylie implements TranscriptView } else { - wherestart = endPos.getOffset(); +// wherestart = endPos.getOffset(); doc.insertString(endPos.getOffset(), wylie, mas); } @@ -154,7 +154,7 @@ public class TibetanWylie implements TranscriptView { doc.insertString(endPos.getOffset(), "\n", null); wylie = current.getAttributeValue("who"); - wherestart = endPos.getOffset(); +// wherestart = endPos.getOffset(); doc.insertString(endPos.getOffset(), wylie, mas); if (iter.hasNext()) current = (org.jdom.Element)iter.next(); diff --git a/source/org/thdl/savant/tib/TibetanWylieEnglish.java b/source/org/thdl/savant/tib/TibetanWylieEnglish.java index 3d30d39..db871da 100644 --- a/source/org/thdl/savant/tib/TibetanWylieEnglish.java +++ b/source/org/thdl/savant/tib/TibetanWylieEnglish.java @@ -80,13 +80,13 @@ public class TibetanWylieEnglish implements TranscriptView Element current = null; DuffData[] dd; - DuffData[] space = TibTextUtils.getTibetanMachineWeb("_"); +// DuffData[] space = TibTextUtils.getTibetanMachineWeb("_"); MutableAttributeSet mas = new SimpleAttributeSet(); StyleConstants.setForeground(mas, Color.blue); MutableAttributeSet mas2 = new SimpleAttributeSet(); StyleConstants.setItalic(mas2, true); Position endPos = null; - int wherestart; +// int wherestart; String wylie; TibetanDocument doc = new TibetanDocument(new StyleContext()); @@ -113,7 +113,7 @@ public class TibetanWylieEnglish implements TranscriptView } else { - wherestart = endPos.getOffset(); +// wherestart = endPos.getOffset(); doc.insertString(endPos.getOffset(), wylie, mas); } @@ -156,7 +156,7 @@ public class TibetanWylieEnglish implements TranscriptView { doc.insertString(endPos.getOffset(), "\n", null); wylie = current.getAttributeValue("who"); - wherestart = endPos.getOffset(); +// wherestart = endPos.getOffset(); doc.insertString(endPos.getOffset(), wylie, mas); if (iter.hasNext()) current = (org.jdom.Element)iter.next(); diff --git a/source/org/thdl/savant/tib/Wylie.java b/source/org/thdl/savant/tib/Wylie.java index 9d62c8d..387f9fa 100644 --- a/source/org/thdl/savant/tib/Wylie.java +++ b/source/org/thdl/savant/tib/Wylie.java @@ -83,7 +83,7 @@ public class Wylie implements TranscriptView MutableAttributeSet mas = new SimpleAttributeSet(); StyleConstants.setForeground(mas, Color.blue); Position endPos = null; - AbstractDocument doc = new TibetanDocument(new StyleContext()); + StyledDocument doc = new TibetanDocument(new StyleContext()); idBuffer = new StringBuffer(); startBuffer = new StringBuffer(); diff --git a/source/org/thdl/savant/tib/WylieEnglish.java b/source/org/thdl/savant/tib/WylieEnglish.java index 8da69fd..90436a7 100644 --- a/source/org/thdl/savant/tib/WylieEnglish.java +++ b/source/org/thdl/savant/tib/WylieEnglish.java @@ -79,15 +79,14 @@ public class WylieEnglish implements TranscriptView Iterator iter = elements.iterator(); Element current = null; - DuffData[] dd; MutableAttributeSet mas = new SimpleAttributeSet(); StyleConstants.setForeground(mas, Color.blue); MutableAttributeSet mas2 = new SimpleAttributeSet(); StyleConstants.setItalic(mas2, true); Position endPos = null; - int wherestart; +// int wherestart; String wylie; - AbstractDocument doc = new TibetanDocument(new StyleContext()); + StyledDocument doc = new TibetanDocument(new StyleContext()); idBuffer = new StringBuffer(); startBuffer = new StringBuffer(); @@ -112,7 +111,7 @@ public class WylieEnglish implements TranscriptView } else { - wherestart = endPos.getOffset(); +// wherestart = endPos.getOffset(); doc.insertString(endPos.getOffset(), wylie, mas); } @@ -153,7 +152,7 @@ public class WylieEnglish implements TranscriptView { doc.insertString(endPos.getOffset(), "\n", null); wylie = current.getAttributeValue("who"); - wherestart = endPos.getOffset(); +// wherestart = endPos.getOffset(); doc.insertString(endPos.getOffset(), wylie, mas); if (iter.hasNext()) current = (org.jdom.Element)iter.next(); diff --git a/source/org/thdl/savant/ucuchi/All.java b/source/org/thdl/savant/ucuchi/All.java index e8b8a83..ea790bb 100644 --- a/source/org/thdl/savant/ucuchi/All.java +++ b/source/org/thdl/savant/ucuchi/All.java @@ -92,7 +92,6 @@ public class All implements TranscriptView StyleConstants.setFontFamily(mas3, "Monospaced"); StyleConstants.setFontSize(mas3, 14); Position endPos = null; - int wherestart; String wylie; idBuffer = new StringBuffer(); @@ -118,7 +117,7 @@ public class All implements TranscriptView } else { - wherestart = endPos.getOffset(); +// wherestart = endPos.getOffset(); doc.insertString(endPos.getOffset(), wylie, mas); } @@ -164,7 +163,7 @@ public class All implements TranscriptView { doc.insertString(endPos.getOffset(), "\n", null); wylie = current.getAttributeValue("who"); - wherestart = endPos.getOffset(); +// wherestart = endPos.getOffset(); doc.insertString(endPos.getOffset(), wylie, mas); if (iter.hasNext()) current = (org.jdom.Element)iter.next(); diff --git a/source/org/thdl/savant/ucuchi/QuechuaEnglish.java b/source/org/thdl/savant/ucuchi/QuechuaEnglish.java index 9dddd0e..1f93c70 100644 --- a/source/org/thdl/savant/ucuchi/QuechuaEnglish.java +++ b/source/org/thdl/savant/ucuchi/QuechuaEnglish.java @@ -91,7 +91,6 @@ public class QuechuaEnglish implements TranscriptView StyleConstants.setFontSize(mas2, 16); StyleConstants.setFontSize(mas2, 16); Position endPos = null; - int wherestart; String wylie; idBuffer = new StringBuffer(); @@ -117,7 +116,7 @@ public class QuechuaEnglish implements TranscriptView } else { - wherestart = endPos.getOffset(); +// wherestart = endPos.getOffset(); doc.insertString(endPos.getOffset(), wylie, mas); } @@ -160,7 +159,7 @@ public class QuechuaEnglish implements TranscriptView { doc.insertString(endPos.getOffset(), "\n", mas0); wylie = current.getAttributeValue("who"); - wherestart = endPos.getOffset(); +// wherestart = endPos.getOffset(); doc.insertString(endPos.getOffset(), wylie, mas); if (iter.hasNext()) current = (org.jdom.Element)iter.next(); diff --git a/source/org/thdl/tib/input/DuffPane.java b/source/org/thdl/tib/input/DuffPane.java index e7db208..6721c34 100644 --- a/source/org/thdl/tib/input/DuffPane.java +++ b/source/org/thdl/tib/input/DuffPane.java @@ -1605,7 +1605,6 @@ public void paste(int offset) { StringBuffer sb; AttributeSet attr; String fontName; - int fontNum; Position endPos; int i; @@ -1618,7 +1617,7 @@ public void paste(int offset) { attr = doc.getCharacterElement(i).getAttributes(); fontName = StyleConstants.getFontFamily(attr); - if ((0 != (fontNum = TibetanMachineWeb.getTMWFontNumber(fontName))) || i==endPos.getOffset()) { + if ((0 != TibetanMachineWeb.getTMWFontNumber(fontName)) || i==endPos.getOffset()) { if (i != start) { try { DuffData[] duffdata = TibTextUtils.getTibetanMachineWeb(sb.toString()); @@ -1653,7 +1652,7 @@ public void paste(int offset) { * document consists of both Tibetan and non-Tibetan fonts, however, * the conversion stops at the first non-Tibetan font. * @return the string of Wylie corresponding to the associated document -* @see org.thdl.tib.text.TibetanDocument.getWylie() */ +* @see org.thdl.tib.text.TibetanDocument#getWylie() */ public String getWylie() { return doc.getWylie(); } diff --git a/source/org/thdl/tib/input/Jskad2JavaScript.java b/source/org/thdl/tib/input/Jskad2JavaScript.java index fa66e4a..e07b817 100644 --- a/source/org/thdl/tib/input/Jskad2JavaScript.java +++ b/source/org/thdl/tib/input/Jskad2JavaScript.java @@ -26,6 +26,7 @@ import netscape.javascript.JSObject; import org.thdl.tib.text.*; import org.thdl.util.ThdlActionListener; +import org.thdl.util.ThdlDebug; /** * A version of Jskad which can be embedded into diff --git a/source/org/thdl/tib/input/Jskad4JavaScript.java b/source/org/thdl/tib/input/Jskad4JavaScript.java index 0a4325b..131ec88 100644 --- a/source/org/thdl/tib/input/Jskad4JavaScript.java +++ b/source/org/thdl/tib/input/Jskad4JavaScript.java @@ -68,7 +68,6 @@ public class Jskad4JavaScript extends JApplet { public void setWylie(String wylie) { try { - DuffData[] dd = TibTextUtils.getTibetanMachineWeb(wylie); TibetanDocument t_doc = (TibetanDocument)jskad.dp.getDocument(); if (t_doc.getLength() > 0) jskad.dp.newDocument(); // DLC FIXME: is it intended that t_doc is the new document? Because it is the old document at present. diff --git a/source/org/thdl/tib/scanner/AppletScannerFilter.java b/source/org/thdl/tib/scanner/AppletScannerFilter.java index 40b5a45..a075698 100644 --- a/source/org/thdl/tib/scanner/AppletScannerFilter.java +++ b/source/org/thdl/tib/scanner/AppletScannerFilter.java @@ -172,7 +172,6 @@ public class AppletScannerFilter extends JApplet implements ActionListener, Focu Object clicked = e.getSource(); StringSelection ss; String s = null; - int start, end; if (clicked==aboutItem) { diff --git a/source/org/thdl/tib/scanner/BinaryFileGenerator.java b/source/org/thdl/tib/scanner/BinaryFileGenerator.java index 3bf04a5..7e93855 100644 --- a/source/org/thdl/tib/scanner/BinaryFileGenerator.java +++ b/source/org/thdl/tib/scanner/BinaryFileGenerator.java @@ -101,7 +101,9 @@ public class BinaryFileGenerator extends LinkedList { final short newDefiniendum=1, halfDefiniendum=2, definition=3; short status=newDefiniendum; - int marker, len, marker2, n=0, total=0, currentPage=0, currentLine=1; + int marker, len, marker2; +// int n=0; + int currentPage=0, currentLine=1; char ch; BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(archivo))); String entrada="", s1="", s2="", currentLetter="", temp="", lastWeirdDefiniendum=""; @@ -383,7 +385,7 @@ public class BinaryFileGenerator extends LinkedList Link link, newLink; BinaryFileGenerator ultimo; String firstSillable; - int pos, marker = word.indexOf(" "), comp; + int marker = word.indexOf(" "), comp; if (marker<0) firstSillable = word; diff --git a/source/org/thdl/tib/scanner/ConsoleScannerFilter.java b/source/org/thdl/tib/scanner/ConsoleScannerFilter.java index d9ab099..2b767b4 100644 --- a/source/org/thdl/tib/scanner/ConsoleScannerFilter.java +++ b/source/org/thdl/tib/scanner/ConsoleScannerFilter.java @@ -102,7 +102,7 @@ class ConsoleScannerFilter public void run() throws Exception { - String inStr, outStr; + String inStr; while ((inStr=in.readLine())!=null) { diff --git a/source/org/thdl/tib/scanner/DuffCellRenderer.java b/source/org/thdl/tib/scanner/DuffCellRenderer.java index ec9593f..822bdef 100644 --- a/source/org/thdl/tib/scanner/DuffCellRenderer.java +++ b/source/org/thdl/tib/scanner/DuffCellRenderer.java @@ -22,10 +22,12 @@ import javax.swing.*; import javax.swing.table.TableCellRenderer; import javax.swing.border.*; import javax.swing.text.*; +import java.io.Serializable; + import org.thdl.tib.input.DuffPane; +import org.thdl.util.ThdlDebug; import org.thdl.tib.text.*; import org.thdl.tib.text.DuffData; -import java.io.Serializable; /** Used by DictionaryTable to display a Tibetan word or phrase (in either Roman or Tibetan script) in a single cell. diff --git a/source/org/thdl/tib/scanner/LocalTibetanScanner.java b/source/org/thdl/tib/scanner/LocalTibetanScanner.java index 06e242e..6816ba2 100644 --- a/source/org/thdl/tib/scanner/LocalTibetanScanner.java +++ b/source/org/thdl/tib/scanner/LocalTibetanScanner.java @@ -201,7 +201,6 @@ class LocalTibetanScanner implements TibetanScanner { boolean isDeclined =false; int len = sil.length(); - String dev; if (len<3) return null; @@ -223,7 +222,6 @@ class LocalTibetanScanner implements TibetanScanner public void scanBody(String in) { - Word word; boolean hayMasLineas=true; if (in.equals("")) finishUp(); @@ -263,7 +261,7 @@ class LocalTibetanScanner implements TibetanScanner public void scanLine(String linea) { - int init = 0, fin, i; + int init = 0, fin; char ch; String sil; boolean doNotFinishUp; @@ -349,7 +347,6 @@ outAHere: { int i=wordList.size(); Token token[] = new Token[i]; - Object obj; ListIterator li = wordList.listIterator(); while(li.hasNext()) token[--i] = (Token)li.next(); @@ -366,7 +363,6 @@ outAHere: { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(archivo + ".dic"))); LinkedList ll1 = new LinkedList(), ll2 = new LinkedList(); - int i; String s; while ((s=br.readLine())!=null) { diff --git a/source/org/thdl/tib/scanner/Manipulate.java b/source/org/thdl/tib/scanner/Manipulate.java index ff82fa3..40601cb 100644 --- a/source/org/thdl/tib/scanner/Manipulate.java +++ b/source/org/thdl/tib/scanner/Manipulate.java @@ -272,7 +272,7 @@ public class Manipulate { sil = sil.toLowerCase(); - int i=0, len=sil.length(); + int i=0; char ch, ch2; while (!isVowel(sil.charAt(i))) i++; diff --git a/source/org/thdl/tib/scanner/MemorySyllableListTree.java b/source/org/thdl/tib/scanner/MemorySyllableListTree.java index 0a87d53..dc1a312 100644 --- a/source/org/thdl/tib/scanner/MemorySyllableListTree.java +++ b/source/org/thdl/tib/scanner/MemorySyllableListTree.java @@ -85,7 +85,7 @@ public class MemorySyllableListTree extends LinkedList implements SyllableListTr { MemorySyllableListTree prefijo; String firstSillable; - int pos, marker = word.indexOf(" "); + int marker = word.indexOf(" "); if (marker<0) firstSillable = word; diff --git a/source/org/thdl/tib/scanner/OnLineScannerFilter.java b/source/org/thdl/tib/scanner/OnLineScannerFilter.java index 77580fe..3c97366 100644 --- a/source/org/thdl/tib/scanner/OnLineScannerFilter.java +++ b/source/org/thdl/tib/scanner/OnLineScannerFilter.java @@ -46,7 +46,7 @@ public class OnLineScannerFilter extends HttpServlet { String parrafo = request.getParameter("parrafo"), checkboxName, script; DictionarySource ds=null; boolean checkedDicts[], allUnchecked, wantsTibetan; - int percent=100; + // int percent=100; out.println(""); out.println(""); @@ -176,7 +176,7 @@ public class OnLineScannerFilter extends HttpServlet { synchronized public void desglosar(String in, PrintWriter pw, boolean tibetan) { - boolean hayMasLineas=true; + //boolean hayMasLineas=true; //int init = 0, fin; //String linea; Object words[]; diff --git a/source/org/thdl/tib/scanner/RemoteTibetanScanner.java b/source/org/thdl/tib/scanner/RemoteTibetanScanner.java index 0644616..832fc01 100644 --- a/source/org/thdl/tib/scanner/RemoteTibetanScanner.java +++ b/source/org/thdl/tib/scanner/RemoteTibetanScanner.java @@ -125,7 +125,6 @@ public class RemoteTibetanScanner implements TibetanScanner BufferedReader br = new BufferedReader(new InputStreamReader(uC.getInputStream())); LinkedList ll1 = new LinkedList(), ll2 = new LinkedList(); - int i; String s; while ((s=br.readLine())!=null) { diff --git a/source/org/thdl/tib/scanner/WindowScannerFilter.java b/source/org/thdl/tib/scanner/WindowScannerFilter.java index 6a61686..0205fe5 100644 --- a/source/org/thdl/tib/scanner/WindowScannerFilter.java +++ b/source/org/thdl/tib/scanner/WindowScannerFilter.java @@ -258,7 +258,6 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio Object clicked = e.getSource(); StringSelection ss; String s = null; - int start, end; if (clicked == mnuAbout) { diff --git a/source/org/thdl/tib/scanner/Word.java b/source/org/thdl/tib/scanner/Word.java index 4bc2002..861ebcc 100644 --- a/source/org/thdl/tib/scanner/Word.java +++ b/source/org/thdl/tib/scanner/Word.java @@ -99,7 +99,8 @@ public class Word extends Token public String getLink(boolean tibetan) { - String localWord, result; + String localWord; + // String result; if (wordSinDec==null) localWord = super.token; else localWord = wordSinDec; if (tibetan) localWord = TibetanHTML.getHTML(localWord + " "); diff --git a/source/org/thdl/tib/text/TibTextUtils.java b/source/org/thdl/tib/text/TibTextUtils.java index 02b67fc..4efe39c 100644 --- a/source/org/thdl/tib/text/TibTextUtils.java +++ b/source/org/thdl/tib/text/TibTextUtils.java @@ -929,9 +929,6 @@ public class TibTextUtils { if (dcs.length == 0) return null; - AttributeSet attr; - String fontName; - int fontNum; char ch; String wylie; @@ -944,7 +941,7 @@ public class TibTextUtils { for (int i=start; i 0 || !glyphList.isEmpty()) { diff --git a/source/org/thdl/tib/text/TibetanMachineWeb.java b/source/org/thdl/tib/text/TibetanMachineWeb.java index f1dd271..cdb953d 100644 --- a/source/org/thdl/tib/text/TibetanMachineWeb.java +++ b/source/org/thdl/tib/text/TibetanMachineWeb.java @@ -295,7 +295,7 @@ public class TibetanMachineWeb { System.out.println("reading "+fileName); String line; boolean hashOn = false; - boolean isSanskrit = false; + boolean isSanskrit = false; //FIXME: this is never read. boolean ignore = false; while ((line = in.readLine()) != null) { diff --git a/source/org/thdl/util/ThdlLazyExceptionTest.java b/source/org/thdl/util/ThdlLazyExceptionTest.java index 4a2f663..4404f17 100644 --- a/source/org/thdl/util/ThdlLazyExceptionTest.java +++ b/source/org/thdl/util/ThdlLazyExceptionTest.java @@ -67,7 +67,7 @@ public class ThdlLazyExceptionTest extends TestCase { junit.textui.TestRunner.run(ThdlLazyExceptionTest.class); } - /* + /** * Test for void ThdlLazyException() */ public void testThdlLazyException() { @@ -81,7 +81,7 @@ public class ThdlLazyExceptionTest extends TestCase { } /* don't catch anything else. */ } - /* + /** * Test for void ThdlLazyException(String) */ public void testThdlLazyExceptionString() { @@ -91,7 +91,7 @@ public class ThdlLazyExceptionTest extends TestCase { assertTrue(null == e.getRealException()); } - /* + /** * Test for void ThdlLazyException(String, Throwable) */ public void testThdlLazyExceptionStringThrowable() { @@ -103,7 +103,7 @@ public class ThdlLazyExceptionTest extends TestCase { assertTrue("bah".equals(e.getRealException().getMessage())); } - /* + /** * Test for void ThdlLazyException(Throwable) */ public void testThdlLazyExceptionThrowable() { diff --git a/source/org/thdl/util/Trie.java b/source/org/thdl/util/Trie.java index 1aa8fcc..67e5ee2 100644 --- a/source/org/thdl/util/Trie.java +++ b/source/org/thdl/util/Trie.java @@ -88,115 +88,161 @@ package org.thdl.util; public class Trie { - /** Size of the m_nextChar array. */ - public static final int ALPHA_SIZE = 128; + /** Size of the m_nextChar array. */ + public static final int ALPHA_SIZE = 128; - /** The root node of the tree. */ - Node m_Root; - - /** - * Constructs a trie. - */ - public Trie() - { - m_Root = new Node(); - } - - /** - * Puts an object into the trie for lookup. - * - * @param key must be a 7-bit ASCII string - * @param value any java object. - * - * @return The old object that matched key, or null. - */ - public Object put(String key, Object value) - { - - final int len = key.length(); - Node node = m_Root; - - for (int i = 0; i < len; i++) - { - Node nextNode = node.m_nextChar[Character.toUpperCase(key.charAt(i))]; - - if (nextNode != null) - { - node = nextNode; - } - else - { - for (; i < len; i++) - { - Node newNode = new Node(); - - node.m_nextChar[Character.toUpperCase(key.charAt(i))] = newNode; - node = newNode; - } - - break; - } - } - - Object ret = node.m_Value; - - node.m_Value = value; - - return ret; - } - - /** - * Gets an object that matches the key. - * - * @param key must be a 7-bit ASCII string - * - * @return The object that matches the key, or null. - */ - public Object get(String key) - { - - final int len = key.length(); - Node node = m_Root; - - for (int i = 0; i < len; i++) - { - try - { - node = node.m_nextChar[Character.toUpperCase(key.charAt(i))]; - } - catch (ArrayIndexOutOfBoundsException e) - { - - // the key is not 7-bit ASCII so we won't find it here - node = null; - } - - if (node == null) - return null; - } - - return node.m_Value; - } - - /** - * The node representation for the trie. - */ - class Node - { + /** The root node of the tree. */ + Node m_Root; /** - * Constructor, creates a Node[ALPHA_SIZE]. + * Constructs a trie. */ - Node() + public Trie() { - m_nextChar = new Node[ALPHA_SIZE]; - m_Value = null; + m_Root = new Node(); } - /** The next nodes. */ - Node m_nextChar[]; + /** + * Puts an object into the trie for lookup. + * + * @param key must be a 7-bit ASCII string + * @param value any java object, but not null. + * + * @return The old object that matched key, or null. + * @throws NullPointerException if value is null or if key is null + */ + public Object put(String key, Object value) + { + if (null == value) throw new NullPointerException(); - /** The value. */ - Object m_Value; - } + final int len = key.length(); + Node node = m_Root; + + for (int i = 0; i < len; i++) + { + Node nextNode = node.m_nextChar[Character.toUpperCase(key.charAt(i))]; + + if (nextNode != null) + { + node = nextNode; + } + else + { + for (; i < len; i++) + { + Node newNode = new Node(); + + node.m_nextChar[Character.toUpperCase(key.charAt(i))] = newNode; + node.m_isLeaf = false; + node = newNode; + } + + break; + } + } + + Object ret = node.m_Value; + + node.m_Value = value; + + return ret; + } + + /** + * Gets an object that matches the key. + * + * @param key must be a 7-bit ASCII string + * + * @return The object that matches the key, or null. + */ + public Object get(String key) + { + + final int len = key.length(); + Node node = m_Root; + + for (int i = 0; i < len; i++) + { + try + { + node = node.m_nextChar[Character.toUpperCase(key.charAt(i))]; + } + catch (ArrayIndexOutOfBoundsException e) + { + + // the key is not 7-bit ASCII so we won't find it here + node = null; + } + + if (node == null) + return null; + } + + return node.m_Value; + } + + /** + * Returns true if and only if key is a prefix of another, distinct + * member of the trie. Note that key may be in the trie as well as + * a prefix of something in the trie, but not all keys in the trie + * are prefixes of other keys. (In the trie you might naturally + * construct for the extended Wylie keyboard, "t" is a prefix, as is + * "ts", but "tsh", though a member of the trie, is not a prefix + * because there is no string x such that x begins with "tsh" but is + * not equal to "tsh" that is in the trie.) + * + * @param key must be a 7-bit ASCII string + * + * @return The object that matches the key, or null. */ + public boolean hasPrefix(String key) + { + + final int len = key.length(); + Node node = m_Root; + + for (int i = 0; i < len; i++) + { + try + { + node = node.m_nextChar[Character.toUpperCase(key.charAt(i))]; + } + catch (ArrayIndexOutOfBoundsException e) + { + + // the key is not 7-bit ASCII so we won't find it here + node = null; + } + + if (node == null) + return false; + } + + return !node.m_isLeaf; + } + + /** + * The node representation for the trie. + */ + class Node + { + + /** + * Constructor, creates a Node[ALPHA_SIZE]. + */ + Node() + { + m_nextChar = new Node[ALPHA_SIZE]; + m_Value = null; + m_isLeaf = true; + } + + /** The next nodes. */ + Node m_nextChar[]; + + /** The value. */ + Object m_Value; + + /** True if and only if this node has no children. */ + boolean m_isLeaf; + } } diff --git a/source/org/thdl/util/TrieTest.java b/source/org/thdl/util/TrieTest.java new file mode 100644 index 0000000..b124ec8 --- /dev/null +++ b/source/org/thdl/util/TrieTest.java @@ -0,0 +1,81 @@ +package org.thdl.util; + +import junit.framework.TestCase; + +/** + * @author David Chandler + * + * Tests {@link org.thdl.util.Trie} at the unit level. + */ +public class TrieTest extends TestCase { + + /** + * Constructor for TrieTest. + * @param arg0 + */ + public TrieTest(String arg0) { + super(arg0); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(TrieTest.class); + } + + /** + * Tests that the trie distinguishes between uppercase and + * lowercase. */ + public void testCaseSupport() { + Trie t = new Trie(); + t.put("S", "S value"); + assertTrue(t.get("S").equals("S value")); + assertTrue(null == t.get("s")); + t.put("Sh", "Sh value"); + assertTrue(t.get("Sh").equals("Sh value")); + assertTrue(t.get("S").equals("S value")); + assertTrue(null == t.get("s")); + assertTrue(null == t.get("sh")); + assertTrue(null == t.get("SH")); + assertTrue(null == t.get("sH")); + } + + /** + * Test for put(String, Object) + */ + public void testReplacement() { + Trie t = new Trie(); + t.put("S", "S value 1"); + assertTrue(t.get("S").equals("S value 1")); + t.put("S", "S value 2"); + assertTrue(t.get("S").equals("S value 2")); + } + + /** + * Tests that put(*, null) throws a NullPointerException. + */ + public void testPuttingNull() { + Trie t = new Trie(); + boolean threw = false; + try { + t.put("heya", null); + } catch (NullPointerException e) { + threw = true; + } + assertTrue(threw); + } + + /** + * Test for put(String, Object) + */ + public void testPrefix() { + Trie t = new Trie(); + t.put("t", "t value"); + t.put("ts", "ts value"); + t.put("tsh", "tsh value"); + assertTrue(t.get("t").equals("t value")); + assertTrue(t.get("ts").equals("ts value")); + assertTrue(t.get("tsh").equals("tsh value")); + assertTrue(t.hasPrefix("t")); + assertTrue(t.hasPrefix("ts")); + assertTrue(!t.hasPrefix("tsh")); + } +}