duplicates

This commit is contained in:
Alexey Kudravtsev
2011-06-27 18:32:37 +04:00
parent afc13d3160
commit 2b7b32048e
3 changed files with 8 additions and 25 deletions
@@ -15,7 +15,8 @@
*/
package com.intellij.openapi.util.text;
/** This interface implementations must have hashCode values equals those for String
/**
* This interface implementations must have hashCode values equal to those for String
* @see com.intellij.openapi.util.text.StringUtil#stringHashCode(CharSequence)
*/
public interface CharSequenceWithStringHash extends CharSequence{
@@ -800,12 +800,7 @@ public class StringUtil {
if (chars instanceof CharSequenceWithStringHash) return chars.hashCode();
if (chars instanceof CharArrayCharSequence) return chars.hashCode();
int h = 0;
int to = chars.length();
for (int off = 0; off < to; off++) {
h = 31 * h + chars.charAt(off);
}
return h;
return stringHashCode(chars, 0, chars.length());
}
public static int stringHashCode(CharSequence chars, int from, int to) {
@@ -841,12 +836,7 @@ public class StringUtil {
}
public static int stringHashCodeInsensitive(@NotNull CharSequence chars) {
int h = 0;
final int len = chars.length();
for (int i = 0; i < len; i++) {
h = 31 * h + toLowerCase(chars.charAt(i));
}
return h;
return stringHashCodeInsensitive(chars, 0, chars.length());
}
/**
@@ -1946,12 +1936,7 @@ public class StringUtil {
}
public static int hashCode(@NotNull CharSequence s) {
int result = 0;
for (int i = 0; i < s.length(); i++) {
// Copied from java.lang.String.hashCode()
result = 31 * result + s.charAt(i);
}
return result;
return stringHashCode(s);
}
public static boolean equals(@Nullable CharSequence s1, @Nullable CharSequence s2) {
@@ -15,6 +15,8 @@
*/
package com.intellij.util.text;
import com.intellij.openapi.util.text.StringUtil;
public class CharArrayCharSequence implements CharSequenceBackedByArray {
private final char[] myChars;
private final int myStart;
@@ -59,12 +61,7 @@ public class CharArrayCharSequence implements CharSequenceBackedByArray {
}
public int hashCode() {
int h = 0;
int to = myEnd;
for (int off = myStart; off < to; off++) {
h = 31 * h + myChars[off];
}
return h;
return StringUtil.stringHashCode(myChars, myStart, myEnd);
}
public void getChars(char[] dst, int dstOffset) {