source: trunk/gsdl3/src/java/org/greenstone/gsdl3/selfContained/Increment.java@ 5663

Last change on this file since 5663 was 5663, checked in by kjdon, 21 years ago

fixed up some bad javadoc

  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/*
2 * Increment.java
3 * Copyright (C) 2000-2001 Stuart Yeates
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20// the package we're in
21package org.greenstone.gsdl3.selfContained;
22
23// java standard library classes used
24import java.io.IOException;
25import java.io.Reader;
26import java.io.Serializable;
27import java.io.Writer;
28
29
30/**
31 * Class Increment is an abstract class for incrementing streams and strings
32 *
33 *
34 * @author <a href="http://www.cs.waikato.ac.nz/~say1/">stuart yeates</a> (<a href="mailto:[email protected]">[email protected]</a>) at the <a href="http://www.nzdl.org">New Zealand Digital Library</a>
35 * @version $Revision: 5663 $
36 */
37
38abstract public class Increment implements Cloneable, Serializable
39{
40 /**
41 * Increment a string of characters
42 *
43 * @exception java.io.Exception if any of the characters in the string are outside the range of first-last
44 * @param str the string to be incremented
45 * @return the incremented string
46 * @see Increment
47 */
48 abstract String incrementString(String str);
49
50 /**
51 * Increment a stream of characters, reading from the reader and writing the incremented characters to the writer
52 *
53 * @exception java.io.Exception if any of the characters in the string are outside the range of first-last
54 * @param str the string to be incremented
55 * @return the incremented string
56 * @see Increment
57 */
58 abstract long incrementStream(Reader rdr, Writer wtr);
59
60 /**
61 * Print to standard out a verbose message about the
62 * results of incrementing this string
63 *
64 * @param s the string to increment
65 * @see #incrementString(String)
66 */
67 final void checkStr(String s) {
68 try {
69 System.out.println("incrementing: \"" + s +
70 "\" to \"" + incrementString(s) +
71 "\" " + stringToOctal(s) +
72 " ===> " + stringToHex(incrementString(s)));
73 } catch (Exception e) {
74 System.out.println("Caught exception: " + e);
75 }
76 }
77
78 /**
79 * Converts a unicode string to Hex
80 *
81 * @exception java.io.IOException when ...
82 * @param s the string to convert
83 * @return a string in hex
84 * @see Integer#toHexString(int)
85 */
86 static final String stringToHex(String s) {
87 StringBuffer buffer = new StringBuffer();
88 for (int i=0;i<s.length();i++) {
89 buffer.append(" 0x");
90 buffer.append(Integer.toHexString(s.charAt(i)));
91 }
92 return buffer.toString();
93 }
94
95 /**
96 * Converts a unicode string to Octal
97 *
98 * @param s the string
99 * @return the string in octal
100 * @see Integer#toOctalString(int)
101 */
102 static final String stringToOctal(String s) {
103 StringBuffer buffer = new StringBuffer();
104 for (int i=0;i<s.length();i++) {
105 buffer.append(" 0x");
106 buffer.append(Integer.toOctalString(s.charAt(i)));
107 }
108 return buffer.toString();
109 }
110}
111
Note: See TracBrowser for help on using the repository browser.