~ubuntu-branches/ubuntu/natty/jabref/natty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package gnu.dtools.ritopt;

/**
 * CharOption.java
 *
 * Version:
 *    $Id: CharOption.java 322 2004-05-20 20:45:47Z mortenalver $
 */

/**
 * This class is used for options with character values.
 *
 * <hr>
 *
 * <pre>
 * Copyright (C) Damian Ryan Eads, 2001. All Rights Reserved.
 *
 * ritopt is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * ritopt is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ritopt; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * </pre>
 *
 * @author Damian Eads
 */

public class CharOption extends Option {

    /**
     * The value of this character option.
     */

    private char value;

    /**
     * Constructs a character option that is set to the space character.
     */

    public CharOption() {
	this( ' ' );
    }

    /**
     * Constructs a character option by copying the character option passed.
     *
     * @param op     The character option to copy.
     */

    public CharOption( CharOption op ) {
	super( op );
	op.value = op.getValue();
    }

    /**
     * Constructs a character option initialized with the value passed.
     *
     * @param value    The initial value of this character option.
     */

    public CharOption( char value ) {
	this( value, null );
    }

    /**
     * Constructs a character option initialized with the value and
     * long option passed.
     *
     * @param value      The initial value of this character option.
     * @param longOption The long option associated with character option.
     */

    public CharOption( char value, String longOption ) {
	this( value, longOption, '\0' );
    }

    /**
     * Constructs a character option initialized with the value and
     * short option passed.
     *
     * @param value       The initial value of this character option.
     * @param shortOption The short option associated with this option.
     */

    public CharOption( char value, char shortOption ) {
	this( value, null, shortOption );
    }

    /**
     * Constructs a character option initialized with the value, short
     * and long option passed.
     *
     * @param shortOption The short option associated with this option.
     * @param longOption  The long option associated with this option.
     * @param value       The initial value of this character option.
     */

    public CharOption( char value, String longOption, char shortOption ) {
	super( longOption, shortOption );
	this.value = value;
    }

    /**
     * Return the value as an object.
     *
     * @return This value as an option.
     */

    public Object getObject() {
	return new Character( value );
    }

    /**
     * Modify this option based on a string representation.
     *
     * @param     value String representation of the object.
     * @exception OptionModificationException Thrown if an error occurs
     *                                  during modification of an option.
     */

    public void modify( String value ) throws OptionModificationException {
	this.value = ( value.length() > 0 ) ? value.charAt( 0 ) : ' ';
    }

    /**
     * Modify this option based on a string representation.
     *
     * @param     value String representation of the object.
     * @exception OptionModificationException Thrown if an error occurs
     *                                  during modification of an option.
     */

    public void setValue( String value ) throws OptionModificationException {
	modify( value );
    }

    /**
     * Modify this option using a character value.
     *
     * @param     value A character value.
     */

    public void setValue( char value ) {
	this.value = value;
    }

    /**
     * Return this option as a character.
     *
     * @return This option as a character.
     */

    public char getValue() {
	return value;
    }

    /**
     * Return this option as a string.
     *
     * @return This option as a string.
     */

    public String getStringValue() {
	return "" + value;
    }

    /**
     * Returns the type name of this option. For a ByteOption, "BYTE"
     * is returned.
     *
     * @return The type name of this option.
     */

    public String getTypeName() {
	return "CHAR";
    }

    /**
     * Returns a string representation of this object.
     *
     * @return A string representation of this object.
     */

    public String toString() {
	return getStringValue();
    }

} /** CharOption */