}
/**
- * Equals any CharSequence with the same chars as this segment.
+ * Returns true if this segment contains the same characters as the other CharSequence.
*
- * <p>
- * This method does not perform case folding; if you want case-insensitive equality, use
+ * <p>This method does not perform case folding; if you want case-insensitive equality, use
* {@link #getCommonPrefixLength}.
*/
- @Override
- public boolean equals(Object other) {
- if (!(other instanceof CharSequence))
- return false;
- return Utility.charSequenceEquals(this, (CharSequence) other);
- }
-
- /** Returns a hash code equivalent to calling .toString().hashCode() */
- @Override
- public int hashCode() {
- return Utility.charSequenceHashCode(this);
+ public boolean contentEquals(CharSequence other) {
+ return Utility.charSequenceEquals(this, other);
}
/** Returns a string representation useful for debugging. */
/** @return Whether we successfully found and parsed a trailing zero option. */
private static boolean parseTrailingZeroOption(StringSegment segment, MacroProps macros) {
- if (segment.equals("w")) {
+ if (segment.contentEquals("w")) {
macros.precision = macros.precision.trailingZeroDisplay(TrailingZeroDisplay.HIDE_IF_WHOLE);
return true;
}
package com.ibm.icu.dev.test.impl;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
public void testCharAt() {
StringSegment segment = new StringSegment(SAMPLE_STRING, false);
assertCharSequenceEquals(SAMPLE_STRING, segment);
+ assertTrue(segment.contentEquals(SAMPLE_STRING));
segment.adjustOffset(3);
assertCharSequenceEquals("radio 📻", segment);
+ assertTrue(segment.contentEquals("radio 📻"));
+ assertFalse(segment.contentEquals(SAMPLE_STRING));
segment.setLength(5);
assertCharSequenceEquals("radio", segment);
+ assertTrue(segment.contentEquals("radio"));
+ assertFalse(segment.contentEquals(SAMPLE_STRING));
}
@Test