diff --git a/icu4j/src/com/ibm/icu/dev/test/util/TestUtilities.java b/icu4j/src/com/ibm/icu/dev/test/util/TestUtilities.java index 1c1ccb6af65..d7f32b1b023 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/TestUtilities.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/TestUtilities.java @@ -107,7 +107,7 @@ public class TestUtilities extends TestFmwk { }; logln("Trying Compose"); - UnicodeMap composed = ((UnicodeMap)scripts.clone()).composeWith(map1, composer); + UnicodeMap composed = ((UnicodeMap)scripts.cloneAsThawed()).composeWith(map1, composer); Object last = ""; for (int i = 0; i < 0x10FFFF; ++i) { Object comp = composed.getValue(i); diff --git a/icu4j/src/com/ibm/icu/dev/test/util/UnicodeMap.java b/icu4j/src/com/ibm/icu/dev/test/util/UnicodeMap.java index 3e1e2b8e52f..7ec67463b77 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/UnicodeMap.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/UnicodeMap.java @@ -35,6 +35,7 @@ import com.ibm.icu.impl.Utility; import com.ibm.icu.text.UTF16; import com.ibm.icu.text.UnicodeSet; import com.ibm.icu.text.UnicodeSetIterator; +import com.ibm.icu.util.Freezable; /** * Class for mapping Unicode characters to values * Much smaller storage than using HashMap, and much faster and more compact than @@ -42,7 +43,7 @@ import com.ibm.icu.text.UnicodeSetIterator; * @author Davis */ -public final class UnicodeMap implements Cloneable, Lockable, Externalizable { +public final class UnicodeMap implements Cloneable, Freezable, Externalizable { static final boolean ASSERTIONS = false; static final long GROWTH_PERCENT = 200; // 100 is no growth! static final long GROWTH_GAP = 10; // extra bump! @@ -98,7 +99,7 @@ public final class UnicodeMap implements Cloneable, Lockable, Externalizable { /** * Standard clone. Warning, as with Collections, does not do deep clone. */ - public Object clone() { + public Object cloneAsThawed() { UnicodeMap that = new UnicodeMap(); that.length = length; that.transitions = (int[]) transitions.clone(); @@ -606,7 +607,7 @@ public final class UnicodeMap implements Cloneable, Lockable, Externalizable { /* (non-Javadoc) * @see com.ibm.icu.dev.test.util.Lockable#isLocked() */ - public boolean isLocked() { + public boolean isFrozen() { // TODO Auto-generated method stub return locked; } @@ -614,7 +615,7 @@ public final class UnicodeMap implements Cloneable, Lockable, Externalizable { /* (non-Javadoc) * @see com.ibm.icu.dev.test.util.Lockable#lock() */ - public Object lock() { + public Object freeze() { locked = true; return this; } diff --git a/icu4j/src/com/ibm/icu/dev/test/util/UnicodeProperty.java b/icu4j/src/com/ibm/icu/dev/test/util/UnicodeProperty.java index 5723e85a57c..0477345d109 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/UnicodeProperty.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/UnicodeProperty.java @@ -325,7 +325,7 @@ Name: Unicode_1_Name * @return the unicode map */ public UnicodeMap getUnicodeMap(boolean getShortest) { - if (!getShortest) return (UnicodeMap) getUnicodeMap_internal().clone(); + if (!getShortest) return (UnicodeMap) getUnicodeMap_internal().cloneAsThawed(); UnicodeMap result = new UnicodeMap(); for (int i = 0; i <= 0x10FFFF; ++i) { //if (DEBUG && i == 0x41) System.out.println(i + "\t" + getValue(i)); diff --git a/icu4j/src/com/ibm/icu/util/Freezable.java b/icu4j/src/com/ibm/icu/util/Freezable.java new file mode 100644 index 00000000000..63f8a66dfd7 --- /dev/null +++ b/icu4j/src/com/ibm/icu/util/Freezable.java @@ -0,0 +1,34 @@ +/* + ****************************************************************************** + * Copyright (C) 2005, International Business Machines Corporation and * + * others. All Rights Reserved. * + ****************************************************************************** +*/ +package com.ibm.icu.util; + +/** + * Provides a flexible mechanism for controlling access, without requiring that a class be immutable. + * Once locked, an object can never be unlocked, so it is thread-safe from that point onward. + * The implementation of both methods must be synchronized. + * Once the object has been locked, it must guarantee that no changes can be made to it. + * Any attempt to alter it must raise an UnsupportedOperationException exception. + * This means that when the object returns internal objects, + * or if anyone has references to those internal objects, that those internal objects must either be immutable, + * or must also raise exceptions if any attempt to modify them is made. Of course, the object can return clones + * of internal objects, since those are safe. * @author davis + */ +public interface Freezable extends Cloneable { + /** + * Determines whether the object has been locked or not. + */ + public boolean isFrozen(); + /** + * Locks the object. + * @return the object itself. + */ + public Object freeze(); + /** + * Provides for the clone operation. Any clone is initially unlocked. + */ + public Object cloneAsThawed(); +} \ No newline at end of file