-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacterSequence.java
More file actions
148 lines (106 loc) · 5.79 KB
/
CharacterSequence.java
File metadata and controls
148 lines (106 loc) · 5.79 KB
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
package sequence;
import java.io.Serializable;
/** This interface provides the specification for a sequence of characters.
*
* Note it extends CharSequence, provided by java.lang, that's also a supertype
* of String.
*
* @see <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/CharSequence.html">java.lang.CharSequence</a>
*
* @author Earl Foxwell (adapted by D. Hughes)
* @version 1.0 (Feb, 2016) */
public interface CharacterSequence extends CharSequence, Serializable {
/** This method compares this character sequence to the provided sequence, cs.
* If the provided sequence is null, or if the two sequences differ by at least
* one character, returns false. Otherwise, returns true.
*
* @param cs the other character sequence against which to compare
* @return boolean true if cs matches this one; false otherwise */
public boolean equals ( CharSequence cs );
/** This method performs lexicographic comparison of this character sequence
* against another.
*
* Returns a positive value if this character sequence comes after the provided
* sequence, cs. Returns a negative value if this character sequence comes before
* the provided sequence. Returns zero if this character sequence has the same
* lexicographic position as the provided sequence. (i.e. returns 0 if the two
* sequences are equal.
*
* @param cs the other character sequence against which to compare
* @return int neagtive if less, 0 if equal positive if greater. */
public int compareTo ( CharSequence cs );
/** This method creates and returns a new version of the character sequence, where
* all uppercase letters have been replaced with their lowercase counterparts.
* Non-alphabetic characters (and lowercase letters) are unaffected.
*
* @return CharacterSequence A copy of this character sequence all lowercase.*/
public CharacterSequence toLowerCase ( );
/** This method creates and returns a new version of the character sequence, where
* all lowercase letters have been replaced with their uppercase counterparts.
* Non-alphabetic characters (and uppercase letters) are unaffected.
*
* @return CharacterSequence A copy of this character sequence all uppercase.*/
public CharacterSequence toUpperCase();
/** This method returns a copy of the character sequence, with leading and
* trailing whitespace removed. If the original character sequence was empty it
* returns an empty character sequence. If the original sequence consisted only
* of whitespace itreturn an empty character sequence. Otherwise it returns a
* character sequence that represents the largest sub-sequence that doesn't
* begin or end with whitespace characters.
*
* For the sake of identifying whitespace, it is acceptable to either use the
* Character class's isWhitespace() function.
*
* @return CharacterSequence A copy of this character sequence with no leading
* or trailing whitespace. */
public CharacterSequence trim ( );
/** This method returns a new CharacterSequence resulting from replacing all
* occurrences of oldChar with newChar.
*
* @param oldChar the old character
* @param newChar the replacement character
*
* @return CharacterSequence The resulting character sequence. */
public CharacterSequence replace ( char oldChar, char newChar );
/** This method returns a new CharacterSequence that represents the concatenation
* of this sequence followed by the provided sequence. If the provided additional
* sequence is null, then a copy of this sequence is all that's returned.
*
* @param tail character sequence to append to end of this sequence
*
* @return CharacterSequence a character sequence consisting of this sequence
* followed by tail. */
public CharacterSequence concat ( CharSequence tail );
/* Note: The following declarations are already inherited from the CharSequenc
* interface. They're included here for offline readability. */
/** This method eturns the character at the specified position (zero-based) of the
* sequence. (Inherited from CharSequence)
*
* @param index position of requested character in sequence.
*
* @return char requested character
* @throws IndexOutOfBoundsException if the index is not within the range
* [0,length()) */
public char charAt( int index );
/** This emthod returns the number of characters in this sequence.
* (Inherited from CharSequence)
*
* @return int number of characters in this sequence. */
public int length ( );
/** This method returns a slice (or substring) from this character sequence.start
* must be in range [0,length()). end must be in the range [0,length()].
* (Inherited from CharSequence)
*
* @param start starting index, inclusive
* @param end end index, exclusive
*
* @return CharSequence the requested slice
* @throws IndexOutOfBoundsException if either index is out of bounds. */
public CharSequence subSequence ( int start, int end );
/** Converts this character sequence into a java.lang.String
* (Inherited from CharSequence)
*
* @return String the equivalent String representation of this character
* sequence. */
public String toString();
}