mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
Reviewed-by: rriggs, smarks, sherman, tvaleev
This commit is contained in:
parent
17b8a043c4
commit
5a7aff9897
10 changed files with 651 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -88,6 +88,29 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the objects of two AbstractStringBuilder implementations lexicographically.
|
||||
*
|
||||
* @since 11
|
||||
*/
|
||||
int compareTo(AbstractStringBuilder another) {
|
||||
if (this == another) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
byte val1[] = value;
|
||||
byte val2[] = another.value;
|
||||
int count1 = this.count;
|
||||
int count2 = another.count;
|
||||
|
||||
if (coder == another.coder) {
|
||||
return isLatin1() ? StringLatin1.compareTo(val1, val2, count1, count2)
|
||||
: StringUTF16.compareTo(val1, val2, count1, count2);
|
||||
}
|
||||
return isLatin1() ? StringLatin1.compareToUTF16(val1, val2, count1, count2)
|
||||
: StringUTF16.compareToLatin1(val1, val2, count1, count2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length (character count).
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue