Skip to content

Commit 8a33a93

Browse files
hansonrhansonr
authored andcommitted
Java 9 String static fields and methods as java.lang.String9
1 parent 0b71303 commit 8a33a93

File tree

4 files changed

+2069
-0
lines changed

4 files changed

+2069
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package java.lang;
2+
3+
public final class String9 {
4+
5+
static final boolean COMPACT_STRINGS;
6+
7+
static {
8+
COMPACT_STRINGS = true;
9+
}
10+
11+
12+
private final byte coder = 0;
13+
14+
static final byte LATIN1 = 0;
15+
static final byte UTF16 = 1;
16+
17+
private boolean isLatin1() {
18+
return COMPACT_STRINGS && coder == LATIN1;
19+
}
20+
21+
22+
/*
23+
* StringIndexOutOfBoundsException if {@code index} is
24+
* negative or greater than or equal to {@code length}.
25+
*/
26+
static void checkIndex(int index, int length) {
27+
if (index < 0 || index >= length) {
28+
throw new StringIndexOutOfBoundsException("index " + index);
29+
}
30+
}
31+
32+
/*
33+
* StringIndexOutOfBoundsException if {@code offset}
34+
* is negative or greater than {@code length}.
35+
*/
36+
static void checkOffset(int offset, int length) {
37+
if (offset < 0 || offset > length) {
38+
throw new StringIndexOutOfBoundsException("offset " + offset +
39+
",length " + length);
40+
}
41+
}
42+
43+
static void checkBoundsOffCount(int offset, int count, int length) {
44+
if (offset < 0 || count < 0 || offset > length - count) {
45+
throw new StringIndexOutOfBoundsException(
46+
"offset " + offset + ", count " + count + ", length " + length);
47+
}
48+
}
49+
50+
51+
52+
}

0 commit comments

Comments
 (0)