mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-4715 Freezable
X-SVN-Rev: 18740
This commit is contained in:
parent
40d9cff7f6
commit
ddcee69efa
4 changed files with 41 additions and 6 deletions
icu4j/src/com/ibm/icu
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
34
icu4j/src/com/ibm/icu/util/Freezable.java
Normal file
34
icu4j/src/com/ibm/icu/util/Freezable.java
Normal file
|
@ -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();
|
||||
}
|
Loading…
Add table
Reference in a new issue