下面列出了java.util.Locale#clone ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void TestSimpleObjectStuff() {
Locale test1 = new Locale("aa", "AA");
Locale test2 = new Locale("aa", "AA");
Locale test3 = (Locale)test1.clone();
Locale test4 = new Locale("zz", "ZZ");
if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3)
errln("Some of the test variables point to the same locale!");
if (test3 == null)
errln("clone() failed to produce a valid object!");
if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3))
errln("clone() or equals() failed: objects that should compare equal don't");
if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4))
errln("equals() failed: objects that shouldn't compare equal do");
int hash1 = test1.hashCode();
int hash2 = test2.hashCode();
int hash3 = test3.hashCode();
if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3)
errln("hashCode() failed: objects that should have the same hash code don't");
}
public void TestSimpleObjectStuff() {
Locale test1 = new Locale("aa", "AA");
Locale test2 = new Locale("aa", "AA");
Locale test3 = (Locale)test1.clone();
Locale test4 = new Locale("zz", "ZZ");
if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3)
errln("Some of the test variables point to the same locale!");
if (test3 == null)
errln("clone() failed to produce a valid object!");
if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3))
errln("clone() or equals() failed: objects that should compare equal don't");
if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4))
errln("equals() failed: objects that shouldn't compare equal do");
int hash1 = test1.hashCode();
int hash2 = test2.hashCode();
int hash3 = test3.hashCode();
if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3)
errln("hashCode() failed: objects that should have the same hash code don't");
}
public void TestSimpleObjectStuff() {
Locale test1 = new Locale("aa", "AA");
Locale test2 = new Locale("aa", "AA");
Locale test3 = (Locale)test1.clone();
Locale test4 = new Locale("zz", "ZZ");
if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3)
errln("Some of the test variables point to the same locale!");
if (test3 == null)
errln("clone() failed to produce a valid object!");
if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3))
errln("clone() or equals() failed: objects that should compare equal don't");
if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4))
errln("equals() failed: objects that shouldn't compare equal do");
int hash1 = test1.hashCode();
int hash2 = test2.hashCode();
int hash3 = test3.hashCode();
if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3)
errln("hashCode() failed: objects that should have the same hash code don't");
}
public void TestSimpleObjectStuff() {
Locale test1 = new Locale("aa", "AA");
Locale test2 = new Locale("aa", "AA");
Locale test3 = (Locale)test1.clone();
Locale test4 = new Locale("zz", "ZZ");
if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3)
errln("Some of the test variables point to the same locale!");
if (test3 == null)
errln("clone() failed to produce a valid object!");
if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3))
errln("clone() or equals() failed: objects that should compare equal don't");
if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4))
errln("equals() failed: objects that shouldn't compare equal do");
int hash1 = test1.hashCode();
int hash2 = test2.hashCode();
int hash3 = test3.hashCode();
if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3)
errln("hashCode() failed: objects that should have the same hash code don't");
}
public void TestSimpleObjectStuff() {
Locale test1 = new Locale("aa", "AA");
Locale test2 = new Locale("aa", "AA");
Locale test3 = (Locale)test1.clone();
Locale test4 = new Locale("zz", "ZZ");
if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3)
errln("Some of the test variables point to the same locale!");
if (test3 == null)
errln("clone() failed to produce a valid object!");
if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3))
errln("clone() or equals() failed: objects that should compare equal don't");
if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4))
errln("equals() failed: objects that shouldn't compare equal do");
int hash1 = test1.hashCode();
int hash2 = test2.hashCode();
int hash3 = test3.hashCode();
if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3)
errln("hashCode() failed: objects that should have the same hash code don't");
}
public void TestSimpleObjectStuff() {
Locale test1 = new Locale("aa", "AA");
Locale test2 = new Locale("aa", "AA");
Locale test3 = (Locale)test1.clone();
Locale test4 = new Locale("zz", "ZZ");
if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3)
errln("Some of the test variables point to the same locale!");
if (test3 == null)
errln("clone() failed to produce a valid object!");
if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3))
errln("clone() or equals() failed: objects that should compare equal don't");
if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4))
errln("equals() failed: objects that shouldn't compare equal do");
int hash1 = test1.hashCode();
int hash2 = test2.hashCode();
int hash3 = test3.hashCode();
if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3)
errln("hashCode() failed: objects that should have the same hash code don't");
}
public void TestSimpleObjectStuff() {
Locale test1 = new Locale("aa", "AA");
Locale test2 = new Locale("aa", "AA");
Locale test3 = (Locale)test1.clone();
Locale test4 = new Locale("zz", "ZZ");
if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3)
errln("Some of the test variables point to the same locale!");
if (test3 == null)
errln("clone() failed to produce a valid object!");
if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3))
errln("clone() or equals() failed: objects that should compare equal don't");
if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4))
errln("equals() failed: objects that shouldn't compare equal do");
int hash1 = test1.hashCode();
int hash2 = test2.hashCode();
int hash3 = test3.hashCode();
if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3)
errln("hashCode() failed: objects that should have the same hash code don't");
}
public void TestSimpleObjectStuff() {
Locale test1 = new Locale("aa", "AA");
Locale test2 = new Locale("aa", "AA");
Locale test3 = (Locale)test1.clone();
Locale test4 = new Locale("zz", "ZZ");
if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3)
errln("Some of the test variables point to the same locale!");
if (test3 == null)
errln("clone() failed to produce a valid object!");
if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3))
errln("clone() or equals() failed: objects that should compare equal don't");
if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4))
errln("equals() failed: objects that shouldn't compare equal do");
int hash1 = test1.hashCode();
int hash2 = test2.hashCode();
int hash3 = test3.hashCode();
if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3)
errln("hashCode() failed: objects that should have the same hash code don't");
}
public void TestSimpleObjectStuff() {
Locale test1 = new Locale("aa", "AA");
Locale test2 = new Locale("aa", "AA");
Locale test3 = (Locale)test1.clone();
Locale test4 = new Locale("zz", "ZZ");
if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3)
errln("Some of the test variables point to the same locale!");
if (test3 == null)
errln("clone() failed to produce a valid object!");
if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3))
errln("clone() or equals() failed: objects that should compare equal don't");
if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4))
errln("equals() failed: objects that shouldn't compare equal do");
int hash1 = test1.hashCode();
int hash2 = test2.hashCode();
int hash3 = test3.hashCode();
if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3)
errln("hashCode() failed: objects that should have the same hash code don't");
}
public void TestSimpleObjectStuff() {
Locale test1 = new Locale("aa", "AA");
Locale test2 = new Locale("aa", "AA");
Locale test3 = (Locale)test1.clone();
Locale test4 = new Locale("zz", "ZZ");
if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3)
errln("Some of the test variables point to the same locale!");
if (test3 == null)
errln("clone() failed to produce a valid object!");
if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3))
errln("clone() or equals() failed: objects that should compare equal don't");
if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4))
errln("equals() failed: objects that shouldn't compare equal do");
int hash1 = test1.hashCode();
int hash2 = test2.hashCode();
int hash3 = test3.hashCode();
if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3)
errln("hashCode() failed: objects that should have the same hash code don't");
}
public void TestSimpleObjectStuff() {
Locale test1 = new Locale("aa", "AA");
Locale test2 = new Locale("aa", "AA");
Locale test3 = (Locale)test1.clone();
Locale test4 = new Locale("zz", "ZZ");
if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3)
errln("Some of the test variables point to the same locale!");
if (test3 == null)
errln("clone() failed to produce a valid object!");
if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3))
errln("clone() or equals() failed: objects that should compare equal don't");
if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4))
errln("equals() failed: objects that shouldn't compare equal do");
int hash1 = test1.hashCode();
int hash2 = test2.hashCode();
int hash3 = test3.hashCode();
if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3)
errln("hashCode() failed: objects that should have the same hash code don't");
}
public void TestSimpleObjectStuff() {
Locale test1 = new Locale("aa", "AA");
Locale test2 = new Locale("aa", "AA");
Locale test3 = (Locale)test1.clone();
Locale test4 = new Locale("zz", "ZZ");
if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3)
errln("Some of the test variables point to the same locale!");
if (test3 == null)
errln("clone() failed to produce a valid object!");
if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3))
errln("clone() or equals() failed: objects that should compare equal don't");
if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4))
errln("equals() failed: objects that shouldn't compare equal do");
int hash1 = test1.hashCode();
int hash2 = test2.hashCode();
int hash3 = test3.hashCode();
if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3)
errln("hashCode() failed: objects that should have the same hash code don't");
}
/**
* Creates a new {@link LocaleList}.
*
* <p>For empty lists of {@link Locale} items it is better to use {@link #getEmptyLocaleList()},
* which returns a pre-constructed empty list.</p>
*
* @throws NullPointerException if any of the input locales is <code>null</code>.
* @throws IllegalArgumentException if any of the input locales repeat.
*/
public LocaleList(@NonNull Locale... list) {
if (list.length == 0) {
mList = sEmptyList;
mStringRepresentation = "";
} else {
final Locale[] localeList = new Locale[list.length];
final HashSet<Locale> seenLocales = new HashSet<Locale>();
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.length; i++) {
final Locale l = list[i];
if (l == null) {
throw new NullPointerException("list[" + i + "] is null");
} else if (seenLocales.contains(l)) {
throw new IllegalArgumentException("list[" + i + "] is a repetition");
} else {
final Locale localeClone = (Locale) l.clone();
localeList[i] = localeClone;
sb.append(localeClone.toLanguageTag());
if (i < list.length - 1) {
sb.append(',');
}
seenLocales.add(localeClone);
}
}
mList = localeList;
mStringRepresentation = sb.toString();
}
}
public void TestSimpleObjectStuff() {
Locale test1 = new Locale("aa", "AA");
Locale test2 = new Locale("aa", "AA");
Locale test3 = (Locale) test1.clone();
Locale test4 = new Locale("zz", "ZZ");
if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3) {
errln("Some of the test variables point to the same locale!");
}
if (test3 == null) {
errln("clone() failed to produce a valid object!");
}
if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3)) {
errln("clone() or equals() failed: objects that should compare equal don't");
}
if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4)) {
errln("equals() failed: objects that shouldn't compare equal do");
}
int hash1 = test1.hashCode();
int hash2 = test2.hashCode();
int hash3 = test3.hashCode();
if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3) {
errln("hashCode() failed: objects that should have the same hash code don't");
}
}
/**
* Constructs a locale list, with the topLocale moved to the front if it already is
* in otherLocales, or added to the front if it isn't.
*
* {@hide}
*/
public LocaleList(@NonNull Locale topLocale, LocaleList otherLocales) {
if (topLocale == null) {
throw new NullPointerException("topLocale is null");
}
final int inputLength = (otherLocales == null) ? 0 : otherLocales.mList.length;
int topLocaleIndex = -1;
for (int i = 0; i < inputLength; i++) {
if (topLocale.equals(otherLocales.mList[i])) {
topLocaleIndex = i;
break;
}
}
final int outputLength = inputLength + (topLocaleIndex == -1 ? 1 : 0);
final Locale[] localeList = new Locale[outputLength];
localeList[0] = (Locale) topLocale.clone();
if (topLocaleIndex == -1) {
// topLocale was not in otherLocales
for (int i = 0; i < inputLength; i++) {
localeList[i + 1] = (Locale) otherLocales.mList[i].clone();
}
} else {
for (int i = 0; i < topLocaleIndex; i++) {
localeList[i + 1] = (Locale) otherLocales.mList[i].clone();
}
for (int i = topLocaleIndex + 1; i < inputLength; i++) {
localeList[i] = (Locale) otherLocales.mList[i].clone();
}
}
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < outputLength; i++) {
sb.append(localeList[i].toLanguageTag());
if (i < outputLength - 1) {
sb.append(',');
}
}
mList = localeList;
mStringRepresentation = sb.toString();
}