harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r462605 [1/8] - in /incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java: java/text/ org/apache/harmony/text/ org/apache/harmony/text/internal/nls/
Date Tue, 10 Oct 2006 22:18:37 GMT
Author: tellison
Date: Tue Oct 10 15:18:35 2006
New Revision: 462605

URL: http://svn.apache.org/viewvc?view=rev&rev=462605
Log:
Tidy-up of TEXT implementation including
 - formatting
 - adding @Override annotations
 - fix minor compile warnings

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Annotation.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedCharacterIterator.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedString.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Bidi.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/BreakIterator.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/CharacterIterator.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/ChoiceFormat.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/CollationElementIterator.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/CollationKey.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Collator.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormat.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DateFormatSymbols.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DecimalFormat.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DecimalFormatSymbols.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/FieldPosition.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Format.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/MessageFormat.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/NumberFormat.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/ParseException.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/ParsePosition.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/RuleBasedBreakIterator.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/RuleBasedCollator.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/SimpleDateFormat.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/StringCharacterIterator.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/org/apache/harmony/text/BidiRun.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/org/apache/harmony/text/BidiWrapper.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/org/apache/harmony/text/internal/nls/Messages.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Annotation.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Annotation.java?view=diff&rev=462605&r1=462604&r2=462605
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Annotation.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Annotation.java Tue Oct 10 15:18:35 2006
@@ -17,23 +17,23 @@
 
 package java.text;
 
-
 /**
  * Annotation
  */
 public class Annotation {
 
-	private Object value;
+    private Object value;
 
-	public Annotation(Object attribute) {
-		value = attribute;
-	}
+    public Annotation(Object attribute) {
+        value = attribute;
+    }
 
-	public Object getValue() {
-		return value;
-	}
+    public Object getValue() {
+        return value;
+    }
 
-	public String toString() {
-		return getClass().getName() + "[value=" + value + ']'; //$NON-NLS-1$
-	}
+    @Override
+    public String toString() {
+        return getClass().getName() + "[value=" + value + ']'; //$NON-NLS-1$
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedCharacterIterator.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedCharacterIterator.java?view=diff&rev=462605&r1=462604&r2=462605
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedCharacterIterator.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedCharacterIterator.java Tue Oct 10 15:18:35 2006
@@ -17,7 +17,6 @@
 
 package java.text;
 
-
 import java.io.InvalidObjectException;
 import java.io.Serializable;
 import java.util.Map;
@@ -30,71 +29,79 @@
  */
 public interface AttributedCharacterIterator extends CharacterIterator {
 
-	public static class Attribute implements Serializable {
+    public static class Attribute implements Serializable {
 
-		private static final long serialVersionUID = -9142742483513960612L;
+        private static final long serialVersionUID = -9142742483513960612L;
 
-		public static final Attribute INPUT_METHOD_SEGMENT = new Attribute(
-				"input_method_segment"); //$NON-NLS-1$
+        public static final Attribute INPUT_METHOD_SEGMENT = new Attribute(
+                "input_method_segment"); //$NON-NLS-1$
 
-		public static final Attribute LANGUAGE = new Attribute("language"); //$NON-NLS-1$
+        public static final Attribute LANGUAGE = new Attribute("language"); //$NON-NLS-1$
 
-		public static final Attribute READING = new Attribute("reading"); //$NON-NLS-1$
+        public static final Attribute READING = new Attribute("reading"); //$NON-NLS-1$
 
-		private String name;
+        private String name;
 
-		protected Attribute(String name) {
-			this.name = name;
-		}
+        protected Attribute(String name) {
+            this.name = name;
+        }
 
-		public final boolean equals(Object object) {
-			if (object == null || !(object.getClass().equals(this.getClass())))
-				return false;
-			return name.equals(((Attribute) object).name);
-		}
+        @Override
+        public final boolean equals(Object object) {
+            if (object == null || !(object.getClass().equals(this.getClass()))) {
+                return false;
+            }
+            return name.equals(((Attribute) object).name);
+        }
 
-		protected String getName() {
-			return name;
-		}
+        protected String getName() {
+            return name;
+        }
 
-		public final int hashCode() {
-			return name.hashCode();
-		}
+        @Override
+        public final int hashCode() {
+            return name.hashCode();
+        }
 
-		protected Object readResolve() throws InvalidObjectException {
-			if (this.getClass() != Attribute.class)
+        protected Object readResolve() throws InvalidObjectException {
+            if (this.getClass() != Attribute.class) {
                 // text.0C=cannot resolve subclasses
-				throw new InvalidObjectException(Messages.getString("text.0C")); //$NON-NLS-1$
-			if (this.equals(INPUT_METHOD_SEGMENT))
-				return INPUT_METHOD_SEGMENT;
-			if (this.equals(LANGUAGE))
-				return LANGUAGE;
-			if (this.equals(READING))
-				return READING;
+                throw new InvalidObjectException(Messages.getString("text.0C")); //$NON-NLS-1$
+            }
+            if (this.equals(INPUT_METHOD_SEGMENT)) {
+                return INPUT_METHOD_SEGMENT;
+            }
+            if (this.equals(LANGUAGE)) {
+                return LANGUAGE;
+            }
+            if (this.equals(READING)) {
+                return READING;
+            }
             // text.02=Unknown attribute
-			throw new InvalidObjectException(Messages.getString("text.02")); //$NON-NLS-1$
-		}
+            throw new InvalidObjectException(Messages.getString("text.02")); //$NON-NLS-1$
+        }
 
-		public String toString() {
-			return getClass().getName() + '(' + getName() + ')';
-		}
-	}
+        @Override
+        public String toString() {
+            return getClass().getName() + '(' + getName() + ')';
+        }
+    }
 
-	public Set<Attribute> getAllAttributeKeys();
+    public Set<Attribute> getAllAttributeKeys();
 
-	public Object getAttribute(Attribute attribute);
+    public Object getAttribute(Attribute attribute);
 
-	public Map<Attribute, Object> getAttributes();
+    public Map<Attribute, Object> getAttributes();
 
-	public int getRunLimit();
+    public int getRunLimit();
 
-	public int getRunLimit(Attribute attribute);
+    public int getRunLimit(Attribute attribute);
 
-	public int getRunLimit(Set<? extends Attribute> attributes);
+    public int getRunLimit(Set<? extends Attribute> attributes);
 
-	public int getRunStart();
+    public int getRunStart();
 
-	public int getRunStart(Attribute attribute);
+    public int getRunStart(Attribute attribute);
 
-	public int getRunStart(Set<? extends Attribute> attributes);
+    public int getRunStart(Set<? extends Attribute> attributes);
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedString.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedString.java?view=diff&rev=462605&r1=462604&r2=462605
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedString.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/AttributedString.java Tue Oct 10 15:18:35 2006
@@ -69,7 +69,8 @@
         }
 
         AttributedIterator(AttributedString attrString,
-                AttributedCharacterIterator.Attribute[] attributes, int begin, int end) {
+                AttributedCharacterIterator.Attribute[] attributes, int begin,
+                int end) {
             if (begin < 0 || end > attrString.text.length() || begin > end) {
                 throw new IllegalArgumentException();
             }
@@ -78,7 +79,8 @@
             offset = begin;
             this.attrString = attrString;
             if (attributes != null) {
-                HashSet<Attribute> set = new HashSet<Attribute>((attributes.length * 4 / 3) + 1);
+                HashSet<Attribute> set = new HashSet<Attribute>(
+                        (attributes.length * 4 / 3) + 1);
                 for (int i = attributes.length; --i >= 0;) {
                     set.add(attributes[i]);
                 }
@@ -94,11 +96,14 @@
          * 
          * @see java.lang.Cloneable
          */
+        @Override
+        @SuppressWarnings("unchecked")
         public Object clone() {
             try {
                 AttributedIterator clone = (AttributedIterator) super.clone();
                 if (attributesAllowed != null) {
-                    clone.attributesAllowed = (HashSet<Attribute>) attributesAllowed.clone();
+                    clone.attributesAllowed = (HashSet<Attribute>) attributesAllowed
+                            .clone();
                 }
                 return clone;
             } catch (CloneNotSupportedException e) {
@@ -164,8 +169,8 @@
             if (!(range.value instanceof Annotation)) {
                 return true;
             }
-            return range.start >= begin && range.start < end && range.end > begin
-                    && range.end <= end;
+            return range.start >= begin && range.start < end
+                    && range.end > begin && range.end <= end;
         }
 
         private boolean inRange(List<Range> ranges) {
@@ -184,16 +189,19 @@
         }
 
         public Set<AttributedIterator.Attribute> getAllAttributeKeys() {
-            if (begin == 0 && end == attrString.text.length() && attributesAllowed == null) {
+            if (begin == 0 && end == attrString.text.length()
+                    && attributesAllowed == null) {
                 return attrString.attributeMap.keySet();
             }
 
             Set<AttributedIterator.Attribute> result = new HashSet<Attribute>(
                     (attrString.attributeMap.size() * 4 / 3) + 1);
-            Iterator<Map.Entry<Attribute, List<Range>>> it = attrString.attributeMap.entrySet().iterator();
+            Iterator<Map.Entry<Attribute, List<Range>>> it = attrString.attributeMap
+                    .entrySet().iterator();
             while (it.hasNext()) {
                 Map.Entry<Attribute, List<Range>> entry = it.next();
-                if (attributesAllowed == null || attributesAllowed.contains(entry.getKey())) {
+                if (attributesAllowed == null
+                        || attributesAllowed.contains(entry.getKey())) {
                     List<Range> ranges = entry.getValue();
                     if (inRange(ranges)) {
                         result.add(entry.getKey());
@@ -214,11 +222,14 @@
             return null;
         }
 
-        public Object getAttribute(AttributedCharacterIterator.Attribute attribute) {
-            if (attributesAllowed != null && !attributesAllowed.contains(attribute)) {
+        public Object getAttribute(
+                AttributedCharacterIterator.Attribute attribute) {
+            if (attributesAllowed != null
+                    && !attributesAllowed.contains(attribute)) {
                 return null;
             }
-            ArrayList<Range> ranges = (ArrayList<Range>) attrString.attributeMap.get(attribute);
+            ArrayList<Range> ranges = (ArrayList<Range>) attrString.attributeMap
+                    .get(attribute);
             if (ranges == null) {
                 return null;
             }
@@ -228,11 +239,12 @@
         public Map<Attribute, Object> getAttributes() {
             Map<Attribute, Object> result = new HashMap<Attribute, Object>(
                     (attrString.attributeMap.size() * 4 / 3) + 1);
-            Iterator<Map.Entry<Attribute, List<Range>>> it = attrString.attributeMap.entrySet()
-                    .iterator();
+            Iterator<Map.Entry<Attribute, List<Range>>> it = attrString.attributeMap
+                    .entrySet().iterator();
             while (it.hasNext()) {
                 Map.Entry<Attribute, List<Range>> entry = it.next();
-                if (attributesAllowed == null || attributesAllowed.contains(entry.getKey())) {
+                if (attributesAllowed == null
+                        || attributesAllowed.contains(entry.getKey())) {
                     Object value = currentValue(entry.getValue());
                     if (value != null) {
                         result.put(entry.getKey(), value);
@@ -265,10 +277,12 @@
         }
 
         public int getRunLimit(AttributedCharacterIterator.Attribute attribute) {
-            if (attributesAllowed != null && !attributesAllowed.contains(attribute)) {
+            if (attributesAllowed != null
+                    && !attributesAllowed.contains(attribute)) {
                 return end;
             }
-            ArrayList<Range> ranges = (ArrayList<Range>) attrString.attributeMap.get(attribute);
+            ArrayList<Range> ranges = (ArrayList<Range>) attrString.attributeMap
+                    .get(attribute);
             if (ranges == null) {
                 return end;
             }
@@ -311,10 +325,12 @@
         }
 
         public int getRunStart(AttributedCharacterIterator.Attribute attribute) {
-            if (attributesAllowed != null && !attributesAllowed.contains(attribute)) {
+            if (attributesAllowed != null
+                    && !attributesAllowed.contains(attribute)) {
                 return begin;
             }
-            ArrayList<Range> ranges = (ArrayList<Range>) attrString.attributeMap.get(attribute);
+            ArrayList<Range> ranges = (ArrayList<Range>) attrString.attributeMap
+                    .get(attribute);
             if (ranges == null) {
                 return begin;
             }
@@ -383,8 +399,9 @@
          * @return the character at the new index, or DONE if the index is past
          *         the end
          * 
-         * @exception IllegalArgumentException when the new index is less than
-         *            the begin index or greater than the end index
+         * @exception IllegalArgumentException
+         *                when the new index is less than the begin index or
+         *                greater than the end index
          */
         public char setIndex(int location) {
             if (location < begin || location > end) {
@@ -401,19 +418,21 @@
     public AttributedString(AttributedCharacterIterator iterator) {
         if (iterator.getBeginIndex() > iterator.getEndIndex()) {
             // text.0A=Invalid substring range
-        	throw new IllegalArgumentException(Messages.getString("text.0A")); //$NON-NLS-1$
+            throw new IllegalArgumentException(Messages.getString("text.0A")); //$NON-NLS-1$
         }
         StringBuffer buffer = new StringBuffer();
-        for (int i = iterator.getBeginIndex(); i < iterator.getEndIndex(); i++) { 
+        for (int i = iterator.getBeginIndex(); i < iterator.getEndIndex(); i++) {
             buffer.append(iterator.current());
             iterator.next();
         }
         text = buffer.toString();
-        Set<AttributedCharacterIterator.Attribute> attributes = iterator.getAllAttributeKeys();
+        Set<AttributedCharacterIterator.Attribute> attributes = iterator
+                .getAllAttributeKeys();
         if (attributes == null) {
-        	return;
+            return;
         }
-        attributeMap = new HashMap<Attribute, List<Range>>((attributes.size() * 4 / 3) + 1);
+        attributeMap = new HashMap<Attribute, List<Range>>(
+                (attributes.size() * 4 / 3) + 1);
 
         Iterator<Attribute> it = attributes.iterator();
         while (it.hasNext()) {
@@ -431,13 +450,14 @@
         }
     }
 
-    private AttributedString(AttributedCharacterIterator iterator, int start, int end,
-            Set<Attribute> attributes) {
-        if (start < iterator.getBeginIndex() || end > iterator.getEndIndex() || start > end) {
+    private AttributedString(AttributedCharacterIterator iterator, int start,
+            int end, Set<Attribute> attributes) {
+        if (start < iterator.getBeginIndex() || end > iterator.getEndIndex()
+                || start > end) {
             throw new IllegalArgumentException();
         }
-        
-        if(attributes == null){
+
+        if (attributes == null) {
             return;
         }
 
@@ -448,7 +468,8 @@
             iterator.next();
         }
         text = buffer.toString();
-        attributeMap = new HashMap<Attribute, List<Range>>((attributes.size() * 4 / 3) + 1);
+        attributeMap = new HashMap<Attribute, List<Range>>(
+                (attributes.size() * 4 / 3) + 1);
 
         Iterator<Attribute> it = attributes.iterator();
         while (it.hasNext()) {
@@ -460,7 +481,8 @@
                 int limit = iterator.getRunLimit(attribute);
                 if ((value instanceof Annotation && runStart >= start && limit <= end)
                         || (value != null && !(value instanceof Annotation))) {
-                    addAttribute(attribute, value, (runStart < start ? start : runStart)
+                    addAttribute(attribute, value, (runStart < start ? start
+                            : runStart)
                             - start, (limit > end ? end : limit) - start);
                 }
                 iterator.setIndex(limit);
@@ -468,13 +490,15 @@
         }
     }
 
-    public AttributedString(AttributedCharacterIterator iterator, int start, int end) {
+    public AttributedString(AttributedCharacterIterator iterator, int start,
+            int end) {
         this(iterator, start, end, iterator.getAllAttributeKeys());
     }
 
-    public AttributedString(AttributedCharacterIterator iterator, int start, int end,
-            AttributedCharacterIterator.Attribute[] attributes) {
-        this(iterator, start, end, new HashSet<Attribute>(Arrays.asList(attributes)));
+    public AttributedString(AttributedCharacterIterator iterator, int start,
+            int end, AttributedCharacterIterator.Attribute[] attributes) {
+        this(iterator, start, end, new HashSet<Attribute>(Arrays
+                .asList(attributes)));
     }
 
     public AttributedString(String value) {
@@ -495,18 +519,21 @@
             throw new IllegalArgumentException(Messages.getString("text.0B")); //$NON-NLS-1$
         }
         text = value;
-        attributeMap = new HashMap<Attribute, List<Range>>((attributes.size() * 4 / 3) + 1);
+        attributeMap = new HashMap<Attribute, List<Range>>(
+                (attributes.size() * 4 / 3) + 1);
         Iterator<?> it = attributes.entrySet().iterator();
         while (it.hasNext()) {
             Map.Entry<?, ?> entry = (Map.Entry<?, ?>) it.next();
             ArrayList<Range> ranges = new ArrayList<Range>(1);
             ranges.add(new Range(0, text.length(), entry.getValue()));
-            attributeMap.put((AttributedCharacterIterator.Attribute) entry.getKey(), ranges);
+            attributeMap.put((AttributedCharacterIterator.Attribute) entry
+                    .getKey(), ranges);
         }
     }
 
-    public void addAttribute(AttributedCharacterIterator.Attribute attribute, Object value) {
-        if(null == attribute){
+    public void addAttribute(AttributedCharacterIterator.Attribute attribute,
+            Object value) {
+        if (null == attribute) {
             throw new NullPointerException();
         }
         if (text.length() == 0) {
@@ -523,9 +550,9 @@
         ranges.add(new Range(0, text.length(), value));
     }
 
-    public void addAttribute(AttributedCharacterIterator.Attribute attribute, Object value,
-            int start, int end) {
-        if(null == attribute){
+    public void addAttribute(AttributedCharacterIterator.Attribute attribute,
+            Object value, int start, int end) {
+        if (null == attribute) {
             throw new NullPointerException();
         }
         if (start < 0 || end > text.length() || start >= end) {
@@ -550,8 +577,8 @@
                 it.previous();
                 break;
             } else if (start < range.end
-                    || (start == range.end && (value == null ? range.value == null : value
-                            .equals(range.value)))) {
+                    || (start == range.end && (value == null ? range.value == null
+                            : value.equals(range.value)))) {
                 Range r1 = null, r3;
                 it.remove();
                 r1 = new Range(range.start, start, range.value);
@@ -573,21 +600,25 @@
                 }
 
                 if (value == null ? r1.value == null : value.equals(r1.value)) {
-                    if (value == null ? r3.value == null : value.equals(r3.value)) {
+                    if (value == null ? r3.value == null : value
+                            .equals(r3.value)) {
                         it.add(new Range(r1.start < start ? r1.start : start,
                                 r3.end > end ? r3.end : end, r1.value));
                     } else {
-                        it.add(new Range(r1.start < start ? r1.start : start, end, r1.value));
+                        it.add(new Range(r1.start < start ? r1.start : start,
+                                end, r1.value));
                         if (r3.start < r3.end) {
                             it.add(r3);
                         }
                     }
                 } else {
-                    if (value == null ? r3.value == null : value.equals(r3.value)) {
+                    if (value == null ? r3.value == null : value
+                            .equals(r3.value)) {
                         if (r1.start < r1.end) {
                             it.add(r1);
                         }
-                        it.add(new Range(start, r3.end > end ? r3.end : end, r3.value));
+                        it.add(new Range(start, r3.end > end ? r3.end : end,
+                                r3.value));
                     } else {
                         if (r1.start < r1.end) {
                             it.add(r1);
@@ -605,13 +636,14 @@
     }
 
     public void addAttributes(
-            Map<? extends AttributedCharacterIterator.Attribute, ?> attributes, int start,
-            int end) {
+            Map<? extends AttributedCharacterIterator.Attribute, ?> attributes,
+            int start, int end) {
         Iterator<?> it = attributes.entrySet().iterator();
         while (it.hasNext()) {
             Map.Entry<?, ?> entry = (Map.Entry<?, ?>) it.next();
-            addAttribute((AttributedCharacterIterator.Attribute) entry.getKey(), entry
-                    .getValue(), start, end);
+            addAttribute(
+                    (AttributedCharacterIterator.Attribute) entry.getKey(),
+                    entry.getValue(), start, end);
         }
     }
 
@@ -625,7 +657,8 @@
     }
 
     public AttributedCharacterIterator getIterator(
-            AttributedCharacterIterator.Attribute[] attributes, int start, int end) {
+            AttributedCharacterIterator.Attribute[] attributes, int start,
+            int end) {
         return new AttributedIterator(this, attributes, start, end);
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Bidi.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Bidi.java?view=diff&rev=462605&r1=462604&r2=462605
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Bidi.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Bidi.java Tue Oct 10 15:18:35 2006
@@ -17,17 +17,15 @@
 
 package java.text;
 
-
+import java.awt.font.NumericShaper;
+import java.awt.font.TextAttribute;
 import java.util.Arrays;
 import java.util.LinkedList;
-import java.awt.font.TextAttribute;
-import java.awt.font.NumericShaper;
 
 import org.apache.harmony.text.BidiRun;
 import org.apache.harmony.text.BidiWrapper;
 import org.apache.harmony.text.internal.nls.Messages;
 
-
 /**
  * Bidi is the class providing the bidirectional algorithm. The algorithm is
  * defined in the Unicode Standard Annex #9, version 13, also described in The
@@ -45,55 +43,55 @@
  * 
  */
 public final class Bidi {
-	/**
-	 * Constant that indicates the default base level. If there is no strong
-	 * character, then set the paragraph level to 0 (left-to-right).
-	 */
-	public static final int DIRECTION_DEFAULT_LEFT_TO_RIGHT = -2;
-
-	/**
-	 * Constant that indicates the default base level. If there is no strong
-	 * character, then set the paragraph level to 1 (right-to-left).
-	 */
-	public static final int DIRECTION_DEFAULT_RIGHT_TO_LEFT = -1;
-
-	/**
-	 * Constant that specifies the default base level as 0 (left-to-right).
-	 */
-	public static final int DIRECTION_LEFT_TO_RIGHT = 0;
-
-	/**
-	 * Constant that specifies the default base level as 1 (right-to-left).
-	 */
-	public static final int DIRECTION_RIGHT_TO_LEFT = 1;
-
-	/**
-	 * Create a Bidi object from the AttributedCharacterIterator of a paragraph
-	 * text.
-	 * 
-	 * The RUN_DIRECTION attribute determines the base direction of the
-	 * bidirectional text. If it's not specified explicitly, the algorithm uses
-	 * DIRECTION_DEFAULT_LEFT_TO_RIGHT by default.
-	 * 
-	 * The BIDI_EMBEDDING attribute specifies the level of embedding for each
-	 * character. Values between -1 and -62 denote overrides at the level's
-	 * absolute value, values from 1 to 62 indicate embeddings, and the
-	 * 0 value indicates the level is calculated by the algorithm automatically.
-	 * For the character with no BIDI_EMBEDDING attribute or with a improper
-	 * attribute value, such as a null value, the algorithm treats its embedding
-	 * level as 0.
-	 * 
-	 * The NUMERIC_SHAPING attribute specifies the instance of NumericShaper
-	 * used to convert European digits to other decimal digits before performing
-	 * the bidi algorithm.
-	 * 
-	 * @param paragraph
-	 * 
-	 * @see TextAttribute.BIDI_EMBEDDING
-	 * @see TextAttribute.NUMERIC_SHAPING
-	 * @see TextAttribute.RUN_DIRECTION
-	 */
-	public Bidi(AttributedCharacterIterator paragraph) {
+    /**
+     * Constant that indicates the default base level. If there is no strong
+     * character, then set the paragraph level to 0 (left-to-right).
+     */
+    public static final int DIRECTION_DEFAULT_LEFT_TO_RIGHT = -2;
+
+    /**
+     * Constant that indicates the default base level. If there is no strong
+     * character, then set the paragraph level to 1 (right-to-left).
+     */
+    public static final int DIRECTION_DEFAULT_RIGHT_TO_LEFT = -1;
+
+    /**
+     * Constant that specifies the default base level as 0 (left-to-right).
+     */
+    public static final int DIRECTION_LEFT_TO_RIGHT = 0;
+
+    /**
+     * Constant that specifies the default base level as 1 (right-to-left).
+     */
+    public static final int DIRECTION_RIGHT_TO_LEFT = 1;
+
+    /**
+     * Create a Bidi object from the AttributedCharacterIterator of a paragraph
+     * text.
+     * 
+     * The RUN_DIRECTION attribute determines the base direction of the
+     * bidirectional text. If it's not specified explicitly, the algorithm uses
+     * DIRECTION_DEFAULT_LEFT_TO_RIGHT by default.
+     * 
+     * The BIDI_EMBEDDING attribute specifies the level of embedding for each
+     * character. Values between -1 and -62 denote overrides at the level's
+     * absolute value, values from 1 to 62 indicate embeddings, and the 0 value
+     * indicates the level is calculated by the algorithm automatically. For the
+     * character with no BIDI_EMBEDDING attribute or with a improper attribute
+     * value, such as a null value, the algorithm treats its embedding level as
+     * 0.
+     * 
+     * The NUMERIC_SHAPING attribute specifies the instance of NumericShaper
+     * used to convert European digits to other decimal digits before performing
+     * the bidi algorithm.
+     * 
+     * @param paragraph
+     * 
+     * @see TextAttribute.BIDI_EMBEDDING
+     * @see TextAttribute.NUMERIC_SHAPING
+     * @see TextAttribute.RUN_DIRECTION
+     */
+    public Bidi(AttributedCharacterIterator paragraph) {
         if (paragraph == null) {
             // text.14=paragraph is null
             throw new IllegalArgumentException(Messages.getString("text.14")); //$NON-NLS-1$
@@ -102,7 +100,8 @@
         int begin = paragraph.getBeginIndex();
         int end = paragraph.getEndIndex();
         int length = end - begin;
-        char text[] = new char[length+1]; // One more char for AttributedCharacterIterator.DONE
+        char text[] = new char[length + 1]; // One more char for
+        // AttributedCharacterIterator.DONE
 
         if (length != 0) {
             text[0] = paragraph.first();
@@ -123,12 +122,11 @@
 
         // Retrieve the text and gather BIDI_EMBEDDINGS
         byte embeddings[] = null;
-        for (
-                int textLimit = 1, i = 1;
-                i < length;
-                textLimit = paragraph.getRunLimit(TextAttribute.BIDI_EMBEDDING) - begin + 1
-        ) {
-            Object embedding = paragraph.getAttribute(TextAttribute.BIDI_EMBEDDING);
+        for (int textLimit = 1, i = 1; i < length; textLimit = paragraph
+                .getRunLimit(TextAttribute.BIDI_EMBEDDING)
+                - begin + 1) {
+            Object embedding = paragraph
+                    .getAttribute(TextAttribute.BIDI_EMBEDDING);
             if (embedding != null && embedding instanceof Integer) {
                 int embLevel = ((Integer) embedding).intValue();
 
@@ -138,7 +136,7 @@
 
                 for (; i < textLimit; i++) {
                     text[i] = paragraph.next();
-                    embeddings[i-1] = (byte) embLevel;
+                    embeddings[i - 1] = (byte) embLevel;
                 }
             } else {
                 for (; i < textLimit; i++) {
@@ -148,7 +146,8 @@
         }
 
         // Apply NumericShaper to the text
-        Object numericShaper = paragraph.getAttribute(TextAttribute.NUMERIC_SHAPING);
+        Object numericShaper = paragraph
+                .getAttribute(TextAttribute.NUMERIC_SHAPING);
         if (numericShaper != null && numericShaper instanceof NumericShaper) {
             ((NumericShaper) numericShaper).shape(text, 0, length);
         }
@@ -158,344 +157,349 @@
         BidiWrapper.ubidi_close(pBidi);
     }
 
-	/**
-	 * Create a Bidi object.
-	 * 
-	 * @param text
-	 *            the char array of the paragraph text.
-	 * @param textStart
-	 *            the start offset of the text array to perform the algorithm.
-	 * @param embeddings
-	 *            the embedding level array of the paragraph text, specifying
-	 *            the embedding level information for each character. Values
-	 *            between -1 and -62 denote overrides at the level's absolute
-	 *            value, values from 1 to 62 indicate embeddings, and the 0
-	 *            value indicates the level is calculated by the algorithm
-	 *            automatically.
-	 * @param embStart
-	 *            the start offset of the embeddings array to perform the
-	 *            algorithm.
-	 * @param paragraphLength
-	 *            the length of the text to perform the algorithm. It must be
-	 *            text.length >= textStart + paragraphLength, and
-	 *            embeddings.length >= embStart + paragraphLength.
-	 * @param flags
-	 *            indicates the base direction of the bidirectional text. It is
-	 *            expected that this will be one of the direction constant
-	 *            values defined in this class. An unknown value is treated as
-	 *            DIRECTION_DEFAULT_LEFT_TO_RIGHT.
-	 * 
-	 * @see #DIRECTION_LEFT_TO_RIGHT
-	 * @see #DIRECTION_RIGHT_TO_LEFT
-	 * @see #DIRECTION_DEFAULT_RIGHT_TO_LEFT
-	 * @see #DIRECTION_DEFAULT_LEFT_TO_RIGHT
-	 */
-	public Bidi(char[] text, int textStart, byte[] embeddings, int embStart,
-			int paragraphLength, int flags) {
-		if (textStart < 0) {
+    /**
+     * Create a Bidi object.
+     * 
+     * @param text
+     *            the char array of the paragraph text.
+     * @param textStart
+     *            the start offset of the text array to perform the algorithm.
+     * @param embeddings
+     *            the embedding level array of the paragraph text, specifying
+     *            the embedding level information for each character. Values
+     *            between -1 and -62 denote overrides at the level's absolute
+     *            value, values from 1 to 62 indicate embeddings, and the 0
+     *            value indicates the level is calculated by the algorithm
+     *            automatically.
+     * @param embStart
+     *            the start offset of the embeddings array to perform the
+     *            algorithm.
+     * @param paragraphLength
+     *            the length of the text to perform the algorithm. It must be
+     *            text.length >= textStart + paragraphLength, and
+     *            embeddings.length >= embStart + paragraphLength.
+     * @param flags
+     *            indicates the base direction of the bidirectional text. It is
+     *            expected that this will be one of the direction constant
+     *            values defined in this class. An unknown value is treated as
+     *            DIRECTION_DEFAULT_LEFT_TO_RIGHT.
+     * 
+     * @see #DIRECTION_LEFT_TO_RIGHT
+     * @see #DIRECTION_RIGHT_TO_LEFT
+     * @see #DIRECTION_DEFAULT_RIGHT_TO_LEFT
+     * @see #DIRECTION_DEFAULT_LEFT_TO_RIGHT
+     */
+    public Bidi(char[] text, int textStart, byte[] embeddings, int embStart,
+            int paragraphLength, int flags) {
+        if (textStart < 0) {
             // text.0D=Negative textStart value {0}
-			throw new IllegalArgumentException(Messages.getString("text.0D", textStart));   //$NON-NLS-1$
-		}
-		if (embStart < 0) {
+            throw new IllegalArgumentException(Messages.getString(
+                    "text.0D", textStart)); //$NON-NLS-1$
+        }
+        if (embStart < 0) {
             // text.10=Negative embStart value {0}
-			throw new IllegalArgumentException(Messages.getString("text.10", embStart));   //$NON-NLS-1$
-		}
-		if (paragraphLength < 0) {
+            throw new IllegalArgumentException(Messages.getString(
+                    "text.10", embStart)); //$NON-NLS-1$
+        }
+        if (paragraphLength < 0) {
             // text.11=Negative paragraph length {0}
-			throw new IllegalArgumentException(Messages.getString("text.11", paragraphLength));   //$NON-NLS-1$
-		}
-		long pBidi = createUBiDi(text, textStart, embeddings, embStart,
-				paragraphLength, flags);
-		readBidiInfo(pBidi);
-		BidiWrapper.ubidi_close(pBidi);
-	}
-
-	/**
-	 * Create a Bidi object.
-	 * 
-	 * @param paragraph
-	 *            the String containing the paragraph text to perform the
-	 *            algorithm.
-	 * @param flags
-	 *            indicates the base direction of the bidirectional text. It is
-	 *            expected that this will be one of the direction constant
-	 *            values defined in this class. An unknown value is treated as
-	 *            DIRECTION_DEFAULT_LEFT_TO_RIGHT.
-	 * 
-	 * @see #DIRECTION_LEFT_TO_RIGHT
-	 * @see #DIRECTION_RIGHT_TO_LEFT
-	 * @see #DIRECTION_DEFAULT_RIGHT_TO_LEFT
-	 * @see #DIRECTION_DEFAULT_LEFT_TO_RIGHT
-	 */
-	public Bidi(String paragraph, int flags) {
-		this((paragraph == null ? null : paragraph.toCharArray()), 0, null, 0,
-				(paragraph == null ? 0 : paragraph.length()), flags);
-	}
-
-	// create the native UBiDi struct, need to be closed with ubidi_close().
-	private static long createUBiDi(char[] text, int textStart,
-			byte[] embeddings, int embStart, int paragraphLength, int flags) {
-		char[] realText = null;
-
-		byte[] realEmbeddings = null;
-
-		if (text == null || text.length - textStart< paragraphLength) {
-			throw new IllegalArgumentException();
-		}
-		realText = new char[paragraphLength];
-		System.arraycopy(text, textStart, realText, 0, paragraphLength);
-
-		if (embeddings != null) {
-			if (embeddings.length - embStart < paragraphLength) {
-				throw new IllegalArgumentException();
-			}
-			if (paragraphLength > 0) {
-				Bidi temp = new Bidi(text, textStart, null, 0, paragraphLength,
-						flags);
-				realEmbeddings = new byte[paragraphLength];
-				System.arraycopy(temp.offsetLevel, 0, realEmbeddings, 0,
-						paragraphLength);
-				for (int i = 0; i < paragraphLength; i++) {
-					byte e = embeddings[i];
-					if (e < 0) {
-						realEmbeddings[i] = (byte) (BidiWrapper.UBIDI_LEVEL_OVERRIDE - e);
-					} else if (e > 0) {
-						realEmbeddings[i] = e;
-					} else {
-						realEmbeddings[i] |= (byte) BidiWrapper.UBIDI_LEVEL_OVERRIDE;
-					}
-				}
-			}
-		}
-
-		if (flags > 1 || flags < -2) {
-			flags = 0;
-		}
-
-		long bidi = BidiWrapper.ubidi_open();
-		BidiWrapper.ubidi_setPara(bidi, realText, paragraphLength,
-				(byte) flags, realEmbeddings);
-		return bidi;
-	}
-
-	// private constructor, used by createLineBidi()
-	private Bidi(long pBidi) {
-		readBidiInfo(pBidi);
-	}
-
-	// read info from the native UBiDi struct
-	private void readBidiInfo(long pBidi) {
+            throw new IllegalArgumentException(Messages.getString(
+                    "text.11", paragraphLength)); //$NON-NLS-1$
+        }
+        long pBidi = createUBiDi(text, textStart, embeddings, embStart,
+                paragraphLength, flags);
+        readBidiInfo(pBidi);
+        BidiWrapper.ubidi_close(pBidi);
+    }
+
+    /**
+     * Create a Bidi object.
+     * 
+     * @param paragraph
+     *            the String containing the paragraph text to perform the
+     *            algorithm.
+     * @param flags
+     *            indicates the base direction of the bidirectional text. It is
+     *            expected that this will be one of the direction constant
+     *            values defined in this class. An unknown value is treated as
+     *            DIRECTION_DEFAULT_LEFT_TO_RIGHT.
+     * 
+     * @see #DIRECTION_LEFT_TO_RIGHT
+     * @see #DIRECTION_RIGHT_TO_LEFT
+     * @see #DIRECTION_DEFAULT_RIGHT_TO_LEFT
+     * @see #DIRECTION_DEFAULT_LEFT_TO_RIGHT
+     */
+    public Bidi(String paragraph, int flags) {
+        this((paragraph == null ? null : paragraph.toCharArray()), 0, null, 0,
+                (paragraph == null ? 0 : paragraph.length()), flags);
+    }
+
+    // create the native UBiDi struct, need to be closed with ubidi_close().
+    private static long createUBiDi(char[] text, int textStart,
+            byte[] embeddings, int embStart, int paragraphLength, int flags) {
+        char[] realText = null;
 
-		length = BidiWrapper.ubidi_getLength(pBidi);
+        byte[] realEmbeddings = null;
 
-		offsetLevel = (length == 0) ? null : BidiWrapper.ubidi_getLevels(pBidi);
+        if (text == null || text.length - textStart < paragraphLength) {
+            throw new IllegalArgumentException();
+        }
+        realText = new char[paragraphLength];
+        System.arraycopy(text, textStart, realText, 0, paragraphLength);
+
+        if (embeddings != null) {
+            if (embeddings.length - embStart < paragraphLength) {
+                throw new IllegalArgumentException();
+            }
+            if (paragraphLength > 0) {
+                Bidi temp = new Bidi(text, textStart, null, 0, paragraphLength,
+                        flags);
+                realEmbeddings = new byte[paragraphLength];
+                System.arraycopy(temp.offsetLevel, 0, realEmbeddings, 0,
+                        paragraphLength);
+                for (int i = 0; i < paragraphLength; i++) {
+                    byte e = embeddings[i];
+                    if (e < 0) {
+                        realEmbeddings[i] = (byte) (BidiWrapper.UBIDI_LEVEL_OVERRIDE - e);
+                    } else if (e > 0) {
+                        realEmbeddings[i] = e;
+                    } else {
+                        realEmbeddings[i] |= (byte) BidiWrapper.UBIDI_LEVEL_OVERRIDE;
+                    }
+                }
+            }
+        }
+
+        if (flags > 1 || flags < -2) {
+            flags = 0;
+        }
 
-		baseLevel = BidiWrapper.ubidi_getParaLevel(pBidi);
+        long bidi = BidiWrapper.ubidi_open();
+        BidiWrapper.ubidi_setPara(bidi, realText, paragraphLength,
+                (byte) flags, realEmbeddings);
+        return bidi;
+    }
+
+    // private constructor, used by createLineBidi()
+    private Bidi(long pBidi) {
+        readBidiInfo(pBidi);
+    }
+
+    // read info from the native UBiDi struct
+    private void readBidiInfo(long pBidi) {
 
-		int runCount = BidiWrapper.ubidi_countRuns(pBidi);
-		if (runCount == 0) {
+        length = BidiWrapper.ubidi_getLength(pBidi);
+
+        offsetLevel = (length == 0) ? null : BidiWrapper.ubidi_getLevels(pBidi);
+
+        baseLevel = BidiWrapper.ubidi_getParaLevel(pBidi);
+
+        int runCount = BidiWrapper.ubidi_countRuns(pBidi);
+        if (runCount == 0) {
             unidirectional = true;
             runs = null;
-		} else if (runCount < 0) {
-			runs = null;
-		} else {
-			runs = BidiWrapper.ubidi_getRuns(pBidi);
+        } else if (runCount < 0) {
+            runs = null;
+        } else {
+            runs = BidiWrapper.ubidi_getRuns(pBidi);
 
             // Simplified case for one run which has the base level
             if (runCount == 1 && runs[0].getLevel() == baseLevel) {
                 unidirectional = true;
                 runs = null;
             }
-		}
+        }
 
-		direction = BidiWrapper.ubidi_getDirection(pBidi);
-	}
+        direction = BidiWrapper.ubidi_getDirection(pBidi);
+    }
 
-	private int baseLevel;
+    private int baseLevel;
 
-	private int length;
+    private int length;
 
-	private byte[] offsetLevel;
+    private byte[] offsetLevel;
 
-	private BidiRun[] runs;
+    private BidiRun[] runs;
 
-	private int direction;
+    private int direction;
 
     private boolean unidirectional;
 
-	/**
-	 * Return whether the base level is from left to right.
-	 * 
-	 * @return true if the base level is from left to right.
-	 */
-	public boolean baseIsLeftToRight() {
-		return baseLevel % 2 == 0 ? true : false;
-	}
-
-	/**
-	 * Create a new Bidi object containing the infomation of one line from this
-	 * object.
-	 * 
-	 * @param lineStart
-	 *            the start offset of the line.
-	 * @param lineLimit
-	 *            the limit of the line.
-	 * @return the new line Bidi object. In this new object, the indices will
-	 *         range from 0 to (limit - start - 1).
-	 */
-	public Bidi createLineBidi(int lineStart, int lineLimit) {
-		if (lineStart < 0 || lineLimit < 0 || lineLimit > length || lineStart > lineLimit) {
-			// text.12=Invalid ranges (start={0}, limit={1}, length={2})
+    /**
+     * Return whether the base level is from left to right.
+     * 
+     * @return true if the base level is from left to right.
+     */
+    public boolean baseIsLeftToRight() {
+        return baseLevel % 2 == 0 ? true : false;
+    }
+
+    /**
+     * Create a new Bidi object containing the infomation of one line from this
+     * object.
+     * 
+     * @param lineStart
+     *            the start offset of the line.
+     * @param lineLimit
+     *            the limit of the line.
+     * @return the new line Bidi object. In this new object, the indices will
+     *         range from 0 to (limit - start - 1).
+     */
+    public Bidi createLineBidi(int lineStart, int lineLimit) {
+        if (lineStart < 0 || lineLimit < 0 || lineLimit > length
+                || lineStart > lineLimit) {
+            // text.12=Invalid ranges (start={0}, limit={1}, length={2})
             throw new IllegalArgumentException(Messages.getString(
                     "text.12", new Object[] { lineStart, lineLimit, length })); //$NON-NLS-1$
-		}
-		char[] text = new char[this.length];
-		Arrays.fill(text, 'a');
-		byte[] embeddings = new byte[this.length];
-		for (int i = 0; i < embeddings.length; i++) {
-			embeddings[i] = (byte) -this.offsetLevel[i];
-		}
-
-		int dir = this.baseIsLeftToRight() ? Bidi.DIRECTION_LEFT_TO_RIGHT
-				: Bidi.DIRECTION_RIGHT_TO_LEFT;
-
-		long parent = createUBiDi(text, 0, embeddings, 0, this.length, dir);
-
-		long line = BidiWrapper.ubidi_setLine(parent, lineStart, lineLimit);
-		Bidi result = new Bidi(line);
-		BidiWrapper.ubidi_close(line);
-		BidiWrapper.ubidi_close(parent);
-		return result;
-	}
-
-	/**
-	 * Return the base level.
-	 * 
-	 * @return the int value of the base level.
-	 */
-	public int getBaseLevel() {
-		return baseLevel;
-	}
-
-	/**
-	 * Return the length of the text in the Bidi object.
-	 * 
-	 * @return the int value of the length.
-	 */
-	public int getLength() {
-		return length;
-	}
-
-	/**
-	 * Return the level of a specified character.
-	 * 
-	 * @param offset
-	 *            the offset of the character.
-	 * @return the int value of the level.
-	 */
-	public int getLevelAt(int offset) {
-		try {
-			return offsetLevel[offset] & ~BidiWrapper.UBIDI_LEVEL_OVERRIDE;
-		} catch (RuntimeException e) {
-			return baseLevel;
-		}
-	}
-
-	/**
-	 * Return the number of runs in the bidirectional text.
-	 * 
-	 * @return the int value of runs, at least 1.
-	 */
-	public int getRunCount() {
-		return unidirectional ? 1 : runs.length;
-	}
-
-	/**
-	 * Return the level of a specified run.
-	 * 
-	 * @param run
-	 *            the index of the run.
-	 * @return the level of the run.
-	 */
-	public int getRunLevel(int run) {
-		return unidirectional ? baseLevel : runs[run].getLevel();
-	}
-
-	/**
-	 * Return the limit offset of a specified run.
-	 * 
-	 * @param run
-	 *            the index of the run.
-	 * @return the limit offset of the run.
-	 */
-	public int getRunLimit(int run) {
-		return unidirectional ? length : runs[run].getLimit();
-	}
-
-	/**
-	 * Return the start offset of a specified run.
-	 * 
-	 * @param run
-	 *            the index of the run.
-	 * @return the start offset of the run.
-	 */
-	public int getRunStart(int run) {
-		return unidirectional ? 0 : runs[run].getStart();
-	}
-
-	/**
-	 * Return whether the text is from left to right, that is, both the base
-	 * direction and the text direction is from left to right.
-	 * 
-	 * @return true if the text is from left to right.
-	 */
-	public boolean isLeftToRight() {
-		return direction == BidiWrapper.UBiDiDirection_UBIDI_LTR;
-	}
-
-	/**
-	 * Return whether the text direction is mixed.
-	 * 
-	 * @return true if the text direction is mixed.
-	 */
-	public boolean isMixed() {
-		return direction == BidiWrapper.UBiDiDirection_UBIDI_MIXED;
-	}
-
-	/**
-	 * Return whether the text is from right to left, that is, both the base
-	 * direction and the text direction is from right to left.
-	 * 
-	 * @return true if the text is from right to left.
-	 */
-	public boolean isRightToLeft() {
-		return direction == BidiWrapper.UBiDiDirection_UBIDI_RTL;
-	}
-
-	/**
-	 * Reorder a range of objects according to their spefied levels. This is a
-	 * convenience function that does not use a Bidi object. The range of
-	 * objects at index from objectStart to objectStart + count will be
-	 * reordered according to the range of levels at index from levelStart to
-	 * levelStart + count.
-	 * 
-	 * @param levels
-	 *            the level array, which is already determined.
-	 * @param levelStart
-	 *            the start offset of the range of the levels.
-	 * @param objects
-	 *            the object array to reoeder.
-	 * @param objectStart
-	 *            the start offset of the range of objects.
-	 * @param count
-	 *            the count of the range of objects to reorder.
-	 */
-	public static void reorderVisually(byte[] levels, int levelStart,
-			Object[] objects, int objectStart, int count) {
+        }
+        char[] text = new char[this.length];
+        Arrays.fill(text, 'a');
+        byte[] embeddings = new byte[this.length];
+        for (int i = 0; i < embeddings.length; i++) {
+            embeddings[i] = (byte) -this.offsetLevel[i];
+        }
+
+        int dir = this.baseIsLeftToRight() ? Bidi.DIRECTION_LEFT_TO_RIGHT
+                : Bidi.DIRECTION_RIGHT_TO_LEFT;
+
+        long parent = createUBiDi(text, 0, embeddings, 0, this.length, dir);
+
+        long line = BidiWrapper.ubidi_setLine(parent, lineStart, lineLimit);
+        Bidi result = new Bidi(line);
+        BidiWrapper.ubidi_close(line);
+        BidiWrapper.ubidi_close(parent);
+        return result;
+    }
+
+    /**
+     * Return the base level.
+     * 
+     * @return the int value of the base level.
+     */
+    public int getBaseLevel() {
+        return baseLevel;
+    }
+
+    /**
+     * Return the length of the text in the Bidi object.
+     * 
+     * @return the int value of the length.
+     */
+    public int getLength() {
+        return length;
+    }
+
+    /**
+     * Return the level of a specified character.
+     * 
+     * @param offset
+     *            the offset of the character.
+     * @return the int value of the level.
+     */
+    public int getLevelAt(int offset) {
+        try {
+            return offsetLevel[offset] & ~BidiWrapper.UBIDI_LEVEL_OVERRIDE;
+        } catch (RuntimeException e) {
+            return baseLevel;
+        }
+    }
+
+    /**
+     * Return the number of runs in the bidirectional text.
+     * 
+     * @return the int value of runs, at least 1.
+     */
+    public int getRunCount() {
+        return unidirectional ? 1 : runs.length;
+    }
+
+    /**
+     * Return the level of a specified run.
+     * 
+     * @param run
+     *            the index of the run.
+     * @return the level of the run.
+     */
+    public int getRunLevel(int run) {
+        return unidirectional ? baseLevel : runs[run].getLevel();
+    }
+
+    /**
+     * Return the limit offset of a specified run.
+     * 
+     * @param run
+     *            the index of the run.
+     * @return the limit offset of the run.
+     */
+    public int getRunLimit(int run) {
+        return unidirectional ? length : runs[run].getLimit();
+    }
+
+    /**
+     * Return the start offset of a specified run.
+     * 
+     * @param run
+     *            the index of the run.
+     * @return the start offset of the run.
+     */
+    public int getRunStart(int run) {
+        return unidirectional ? 0 : runs[run].getStart();
+    }
+
+    /**
+     * Return whether the text is from left to right, that is, both the base
+     * direction and the text direction is from left to right.
+     * 
+     * @return true if the text is from left to right.
+     */
+    public boolean isLeftToRight() {
+        return direction == BidiWrapper.UBiDiDirection_UBIDI_LTR;
+    }
+
+    /**
+     * Return whether the text direction is mixed.
+     * 
+     * @return true if the text direction is mixed.
+     */
+    public boolean isMixed() {
+        return direction == BidiWrapper.UBiDiDirection_UBIDI_MIXED;
+    }
+
+    /**
+     * Return whether the text is from right to left, that is, both the base
+     * direction and the text direction is from right to left.
+     * 
+     * @return true if the text is from right to left.
+     */
+    public boolean isRightToLeft() {
+        return direction == BidiWrapper.UBiDiDirection_UBIDI_RTL;
+    }
+
+    /**
+     * Reorder a range of objects according to their spefied levels. This is a
+     * convenience function that does not use a Bidi object. The range of
+     * objects at index from objectStart to objectStart + count will be
+     * reordered according to the range of levels at index from levelStart to
+     * levelStart + count.
+     * 
+     * @param levels
+     *            the level array, which is already determined.
+     * @param levelStart
+     *            the start offset of the range of the levels.
+     * @param objects
+     *            the object array to reoeder.
+     * @param objectStart
+     *            the start offset of the range of objects.
+     * @param count
+     *            the count of the range of objects to reorder.
+     */
+    public static void reorderVisually(byte[] levels, int levelStart,
+            Object[] objects, int objectStart, int count) {
         if (count < 0 || levelStart < 0 || objectStart < 0
                 || count > levels.length - levelStart
                 || count > objects.length - objectStart) {
-            // text.13=Invalid ranges (levels={0}, levelStart={1}, objects={2}, objectStart={3}, count={4})
+            // text.13=Invalid ranges (levels={0}, levelStart={1}, objects={2},
+            // objectStart={3}, count={4})
             throw new IllegalArgumentException(Messages.getString("text.13", //$NON-NLS-1$
                     new Object[] { levels.length, levelStart, objects.length,
                             objectStart, count }));
@@ -511,36 +515,38 @@
         }
 
         System.arraycopy(result.toArray(), 0, objects, objectStart, count);
-	}
+    }
 
-	/**
-	 * Return whether a range of characters of a text requires a Bidi object to
-	 * display properly.
-	 * 
-	 * @param text
-	 *            the char array of the text.
-	 * @param start
-	 *            the start offset of the range of characters.
-	 * @param limit
-	 *            the limit offset of the range of characters.
-	 * @return true if the range of characters requires a Bidi object.
-	 */
-	public static boolean requiresBidi(char[] text, int start, int limit) {
+    /**
+     * Return whether a range of characters of a text requires a Bidi object to
+     * display properly.
+     * 
+     * @param text
+     *            the char array of the text.
+     * @param start
+     *            the start offset of the range of characters.
+     * @param limit
+     *            the limit offset of the range of characters.
+     * @return true if the range of characters requires a Bidi object.
+     */
+    public static boolean requiresBidi(char[] text, int start, int limit) {
         int length = text.length;
-        if(limit < 0 || start < 0 || start > limit || limit > length){
+        if (limit < 0 || start < 0 || start > limit || limit > length) {
             throw new IllegalArgumentException();
         }
         Bidi bidi = new Bidi(text, start, null, 0, limit - start, 0);
-		return !bidi.isLeftToRight();
-	}
+        return !bidi.isLeftToRight();
+    }
 
-	/**
-	 * Return the internal message of the Bidi object, used in debugging.
-	 * 
-	 * @return a string containing the internal message.
-	 */
-	public String toString() {
-		return super.toString() + "[direction: " + direction + " baselevel: " + baseLevel //$NON-NLS-1$ //$NON-NLS-2$
-			 + " length: " + length + " runs: " + (unidirectional ? "null" : runs.toString()) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-	}
+    /**
+     * Return the internal message of the Bidi object, used in debugging.
+     * 
+     * @return a string containing the internal message.
+     */
+    @Override
+    public String toString() {
+        return super.toString()
+                + "[direction: " + direction + " baselevel: " + baseLevel //$NON-NLS-1$ //$NON-NLS-2$
+                + " length: " + length + " runs: " + (unidirectional ? "null" : runs.toString()) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/BreakIterator.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/BreakIterator.java?view=diff&rev=462605&r1=462604&r2=462605
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/BreakIterator.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/BreakIterator.java Tue Oct 10 15:18:35 2006
@@ -50,400 +50,409 @@
  */
 public abstract class BreakIterator implements Cloneable {
 
-	/*
-	 * -----------------------------------------------------------------------
-	 * constants
-	 * -----------------------------------------------------------------------
-	 */
-	/**
-	 * This constant is returned by iterate methods like previous() or next() if
-	 * they have returned all valid boundaries.
-	 */
-	public static final int DONE = -1;
-
-	private static final int LONG_LENGTH = 8;
-	private static final int INT_LENGTH = 4;
-	private static final int SHORT_LENGTH = 2;
-
-	/*
-	 * -----------------------------------------------------------------------
-	 * variables
-	 * -----------------------------------------------------------------------
-	 */
-	// the wrapped ICU implementation
-	com.ibm.icu.text.BreakIterator wrapped;
-
-	/*
-	 * -----------------------------------------------------------------------
-	 * constructors
-	 * -----------------------------------------------------------------------
-	 */
-	/**
-	 * Default constructor, just for invocation by subclass.
-	 */
-	protected BreakIterator() {
-		super();
-	}
-
-	/*
-	 * wrapping constructor
-	 */
-	BreakIterator(com.ibm.icu.text.BreakIterator iterator) {
-		wrapped = iterator;
-	}
-
-	/*
-	 * -----------------------------------------------------------------------
-	 * methods
-	 * -----------------------------------------------------------------------
-	 */
-	/**
-	 * Return all supported locales.
-	 * 
-	 * @return all supported locales
-	 */
-	public static Locale[] getAvailableLocales() {
-		return com.ibm.icu.text.BreakIterator.getAvailableLocales();
-	}
-
-	/**
-	 * Return a new instance of BreakIterator used to iterate characters using
-	 * default locale.
-	 * 
-	 * @return a new instance of BreakIterator used to iterate characters using
-	 *         default locale.
-	 */
-	public static BreakIterator getCharacterInstance() {
-		return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
-				.getCharacterInstance());
-	}
-
-	/**
-	 * Return a new instance of BreakIterator used to iterate characters using
-	 * given locale.
-	 * 
-	 * @param where
-	 *            the given locale
-	 * @return a new instance of BreakIterator used to iterate characters using
-	 *         given locale.
-	 */
-	public static BreakIterator getCharacterInstance(Locale where) {
-	    if (where == null) {
+    /*
+     * -----------------------------------------------------------------------
+     * constants
+     * -----------------------------------------------------------------------
+     */
+    /**
+     * This constant is returned by iterate methods like previous() or next() if
+     * they have returned all valid boundaries.
+     */
+    public static final int DONE = -1;
+
+    private static final int LONG_LENGTH = 8;
+
+    private static final int INT_LENGTH = 4;
+
+    private static final int SHORT_LENGTH = 2;
+
+    /*
+     * -----------------------------------------------------------------------
+     * variables
+     * -----------------------------------------------------------------------
+     */
+    // the wrapped ICU implementation
+    com.ibm.icu.text.BreakIterator wrapped;
+
+    /*
+     * -----------------------------------------------------------------------
+     * constructors
+     * -----------------------------------------------------------------------
+     */
+    /**
+     * Default constructor, just for invocation by subclass.
+     */
+    protected BreakIterator() {
+        super();
+    }
+
+    /*
+     * wrapping constructor
+     */
+    BreakIterator(com.ibm.icu.text.BreakIterator iterator) {
+        wrapped = iterator;
+    }
+
+    /*
+     * -----------------------------------------------------------------------
+     * methods
+     * -----------------------------------------------------------------------
+     */
+    /**
+     * Return all supported locales.
+     * 
+     * @return all supported locales
+     */
+    public static Locale[] getAvailableLocales() {
+        return com.ibm.icu.text.BreakIterator.getAvailableLocales();
+    }
+
+    /**
+     * Return a new instance of BreakIterator used to iterate characters using
+     * default locale.
+     * 
+     * @return a new instance of BreakIterator used to iterate characters using
+     *         default locale.
+     */
+    public static BreakIterator getCharacterInstance() {
+        return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
+                .getCharacterInstance());
+    }
+
+    /**
+     * Return a new instance of BreakIterator used to iterate characters using
+     * given locale.
+     * 
+     * @param where
+     *            the given locale
+     * @return a new instance of BreakIterator used to iterate characters using
+     *         given locale.
+     */
+    public static BreakIterator getCharacterInstance(Locale where) {
+        if (where == null) {
             throw new NullPointerException();
         }
 
-	    return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
-	            .getCharacterInstance(where));
-	}
-
-	/**
-	 * Return a new instance of BreakIterator used to iterate line-breaks using
-	 * default locale.
-	 * 
-	 * @return a new instance of BreakIterator used to iterate line-breaks using
-	 *         default locale.
-	 */
-	public static BreakIterator getLineInstance() {
-		return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
-				.getLineInstance());
-	}
-
-	/**
-	 * Return a new instance of BreakIterator used to iterate line-breaks using
-	 * given locale.
-	 * 
-	 * @param where
-	 *            the given locale
-	 * @return a new instance of BreakIterator used to iterate line-breaks using
-	 *         given locale.
-	 */
-	public static BreakIterator getLineInstance(Locale where) {
-	    if (where == null) {
+        return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
+                .getCharacterInstance(where));
+    }
+
+    /**
+     * Return a new instance of BreakIterator used to iterate line-breaks using
+     * default locale.
+     * 
+     * @return a new instance of BreakIterator used to iterate line-breaks using
+     *         default locale.
+     */
+    public static BreakIterator getLineInstance() {
+        return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
+                .getLineInstance());
+    }
+
+    /**
+     * Return a new instance of BreakIterator used to iterate line-breaks using
+     * given locale.
+     * 
+     * @param where
+     *            the given locale
+     * @return a new instance of BreakIterator used to iterate line-breaks using
+     *         given locale.
+     */
+    public static BreakIterator getLineInstance(Locale where) {
+        if (where == null) {
             throw new NullPointerException();
         }
 
-	    return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
-	            .getLineInstance(where));
-	}
-
-	/**
-	 * Return a new instance of BreakIterator used to iterate sentence-breaks
-	 * using default locale.
-	 * 
-	 * @return a new instance of BreakIterator used to iterate sentence-breaks
-	 *         using default locale.
-	 */
-	public static BreakIterator getSentenceInstance() {
-		return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
-				.getSentenceInstance());
-	}
-
-	/**
-	 * Return a new instance of BreakIterator used to iterate sentence-breaks
-	 * using given locale.
-	 * 
-	 * @param where
-	 *            the given locale
-	 * @return a new instance of BreakIterator used to iterate sentence-breaks
-	 *         using given locale.
-	 */
-	public static BreakIterator getSentenceInstance(Locale where) {
-	    if (where == null) {
+        return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
+                .getLineInstance(where));
+    }
+
+    /**
+     * Return a new instance of BreakIterator used to iterate sentence-breaks
+     * using default locale.
+     * 
+     * @return a new instance of BreakIterator used to iterate sentence-breaks
+     *         using default locale.
+     */
+    public static BreakIterator getSentenceInstance() {
+        return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
+                .getSentenceInstance());
+    }
+
+    /**
+     * Return a new instance of BreakIterator used to iterate sentence-breaks
+     * using given locale.
+     * 
+     * @param where
+     *            the given locale
+     * @return a new instance of BreakIterator used to iterate sentence-breaks
+     *         using given locale.
+     */
+    public static BreakIterator getSentenceInstance(Locale where) {
+        if (where == null) {
             throw new NullPointerException();
         }
 
-	    return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
-	            .getSentenceInstance(where));
-	}
-
-	/**
-	 * Return a new instance of BreakIterator used to iterate word-breaks using
-	 * default locale.
-	 * 
-	 * @return a new instance of BreakIterator used to iterate word-breaks using
-	 *         default locale.
-	 */
-	public static BreakIterator getWordInstance() {
-		return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
-				.getWordInstance());
-	}
-
-	/**
-	 * Return a new instance of BreakIterator used to iterate word-breaks using
-	 * given locale.
-	 * 
-	 * @param where
-	 *            the given locale
-	 * @return a new instance of BreakIterator used to iterate word-breaks using
-	 *         given locale.
-	 */
-	public static BreakIterator getWordInstance(Locale where) {
-	    if (where == null) {
+        return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
+                .getSentenceInstance(where));
+    }
+
+    /**
+     * Return a new instance of BreakIterator used to iterate word-breaks using
+     * default locale.
+     * 
+     * @return a new instance of BreakIterator used to iterate word-breaks using
+     *         default locale.
+     */
+    public static BreakIterator getWordInstance() {
+        return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
+                .getWordInstance());
+    }
+
+    /**
+     * Return a new instance of BreakIterator used to iterate word-breaks using
+     * given locale.
+     * 
+     * @param where
+     *            the given locale
+     * @return a new instance of BreakIterator used to iterate word-breaks using
+     *         given locale.
+     */
+    public static BreakIterator getWordInstance(Locale where) {
+        if (where == null) {
             throw new NullPointerException();
         }
 
-	    return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
-	            .getWordInstance(where));
-	}
-
-	/**
-	 * Return true if the given offset is a boundary position. If this method
-	 * returns true, the current iteration position is set to the given
-	 * position; if the function returns false, the current iteration position
-	 * is set as though following() had been called.
-	 * 
-	 * @param offset
-	 *            the given offset to check
-	 * @return true if the given offset is a boundary position
-	 */
-	public boolean isBoundary(int offset) {
-		return wrapped.isBoundary(offset);
-	}
-
-	/**
-	 * Return the position of last boundary precede the given offset, and set
-	 * current position to returned value, or <code>DONE</code> if the given
-	 * offset specifies the starting position.
-	 * <p>
-	 * <code>IllegalArgumentException</code> will be thrown if given offset is
-	 * invalid.
-	 * </p>
-	 * 
-	 * @param offset
-	 *            the given start position to be searched for
-	 * @return the position of last boundary precede the given offset
-	 */
-	public int preceding(int offset) {
-		return wrapped.preceding(offset);
-	}
-
-	/**
-	 * Set the new text string to be analyzed, the current position will be
-	 * reset to beginning of this new string, and the old string will lost.
-	 * 
-	 * @param newText
-	 *            the new text string to be analyzed
-	 */
-	public void setText(String newText) {
-		wrapped.setText(newText);
-	}
-
-	/*
-	 * -----------------------------------------------------------------------
-	 * abstract methods
-	 * -----------------------------------------------------------------------
-	 */
-	/**
-	 * Return this iterator's current position.
-	 * 
-	 * @return this iterator's current position
-	 */
-	public abstract int current();
-
-	/**
-	 * Set this iterator's current position to the first boundary, and return
-	 * this position.
-	 * 
-	 * @return the position of first boundary
-	 */
-	public abstract int first();
-
-	/**
-	 * Set the position of the first boundary following the given offset, and
-	 * return this position. If there is no boundary after the given offset,
-	 * return DONE.
-	 * <p>
-	 * <code>IllegalArgumentException</code> will be thrown if given offset is
-	 * invalid.
-	 * </p>
-	 * 
-	 * @param offset
-	 *            the given position to be searched for
-	 * @return the position of the first boundary following the given offset
-	 */
-	public abstract int following(int offset);
-
-	/**
-	 * Return a <code>CharacterIterator</code> which represents the text being
-	 * analyzed. Please note that the returned value is probably the internal
-	 * iterator used by this object, so that if the invoker want to modify the
-	 * status of the returned iterator, a clone operation at first is
-	 * recommended.
-	 * 
-	 * @return a <code>CharacterIterator</code> which represents the text
-	 *         being analyzed.
-	 */
-	public abstract CharacterIterator getText();
-
-	/**
-	 * Set this iterator's current position to the last boundary, and return
-	 * this position.
-	 * 
-	 * @return the position of last boundary
-	 */
-	public abstract int last();
-
-	/**
-	 * Set this iterator's current position to the next boundary after current
-	 * position, and return this position. Return <code>DONE</code> if no
-	 * boundary found after current position.
-	 * 
-	 * @return the position of last boundary
-	 */
-	public abstract int next();
-
-	/**
-	 * Set this iterator's current position to the next boundary after the given
-	 * position, and return this position. Return <code>DONE</code> if no
-	 * boundary found after the given position.
-	 * 
-	 * @param n
-	 *            the given position.
-	 * @return the position of last boundary
-	 */
-	public abstract int next(int n);
-
-	/**
-	 * Set this iterator's current position to the previous boundary before
-	 * current position, and return this position. Return <code>DONE</code> if
-	 * no boundary found before current position.
-	 * 
-	 * @return the position of last boundary
-	 */
-	public abstract int previous();
-
-	/**
-	 * Set new text to be analyzed by given <code>CharacterIterator</code>.
-	 * The position will be reset to the beginning of the new text, and other
-	 * status of this iterator will be kept.
-	 * 
-	 * @param newText
-	 *            the given <code>CharacterIterator</code> refer to the text
-	 *            to be analyzed
-	 */
-	public abstract void setText(CharacterIterator newText);
-
-	/*
-	 * -----------------------------------------------------------------------
-	 * methods override Object
-	 * -----------------------------------------------------------------------
-	 */
-	/**
-	 * Create copy of this iterator, all status including current position is
-	 * kept.
-	 * 
-	 * @return copy of this iterator
-	 */
-	public Object clone() {
-		try {
-			BreakIterator cloned = (BreakIterator) super.clone();
-			cloned.wrapped = (com.ibm.icu.text.BreakIterator) wrapped.clone();
-			return cloned;
-		} catch (CloneNotSupportedException e) {
-			throw new InternalError(e.getMessage());
-		}
-	}
-
-	/**
-	 * Get a long value from the given byte array, start from given offset.
-	 * 
-	 * @param buf	the bytes to be converted
-	 * @param offset	the start position of conversion
-	 * @return	the converted long value
-	 */
-	protected static long getLong(byte[] buf, int offset) {
-		if(null == buf){
-			throw new NullPointerException();
-		}
-		if(offset < 0 || buf.length - offset < LONG_LENGTH){
-			throw new ArrayIndexOutOfBoundsException();
-		}
-		long result = 0;
-		for (int i = offset; i < offset + LONG_LENGTH; i++) {
-			result = (result << 8) | (buf[i] & 0xff);
-		}
-		return result;
-	}
-
-	/**
-	 * Get an int value from the given byte array, start from given offset.
-	 * 
-	 * @param buf	the bytes to be converted
-	 * @param offset	the start position of conversion
-	 * @return	the converted int value
-	 */	
-	protected static int getInt(byte[] buf, int offset) {
-		if(null == buf){
-			throw new NullPointerException();
-		}
-		if(offset < 0 || buf.length - INT_LENGTH < offset){
-			throw new ArrayIndexOutOfBoundsException();
-		}
-		int result = 0;
-		for (int i = offset; i < offset + INT_LENGTH; i++) {
-			result = (result << 8) | (buf[i] & 0xff);
-		}
-		return result;
-	}
-
-	/**
-	 * Get a short value from the given byte array, start from given offset.
-	 * 
-	 * @param buf	the bytes to be converted
-	 * @param offset	the start position of conversion
-	 * @return	the converted short value
-	 */
-	protected static short getShort(byte[] buf, int offset) {        
-		if(null == buf){
-			throw new NullPointerException();
-		}
-		if(offset < 0 || buf.length - SHORT_LENGTH < offset){
-			throw new ArrayIndexOutOfBoundsException();
-		}
-		short result = 0;
-		for (int i = offset; i < offset + SHORT_LENGTH; i++) {
-			result = (short)((result << 8) | (buf[i] & 0xff));
-		}
-		return result;
-	}
+        return new RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator
+                .getWordInstance(where));
+    }
+
+    /**
+     * Return true if the given offset is a boundary position. If this method
+     * returns true, the current iteration position is set to the given
+     * position; if the function returns false, the current iteration position
+     * is set as though following() had been called.
+     * 
+     * @param offset
+     *            the given offset to check
+     * @return true if the given offset is a boundary position
+     */
+    public boolean isBoundary(int offset) {
+        return wrapped.isBoundary(offset);
+    }
+
+    /**
+     * Return the position of last boundary precede the given offset, and set
+     * current position to returned value, or <code>DONE</code> if the given
+     * offset specifies the starting position.
+     * <p>
+     * <code>IllegalArgumentException</code> will be thrown if given offset is
+     * invalid.
+     * </p>
+     * 
+     * @param offset
+     *            the given start position to be searched for
+     * @return the position of last boundary precede the given offset
+     */
+    public int preceding(int offset) {
+        return wrapped.preceding(offset);
+    }
+
+    /**
+     * Set the new text string to be analyzed, the current position will be
+     * reset to beginning of this new string, and the old string will lost.
+     * 
+     * @param newText
+     *            the new text string to be analyzed
+     */
+    public void setText(String newText) {
+        wrapped.setText(newText);
+    }
+
+    /*
+     * -----------------------------------------------------------------------
+     * abstract methods
+     * -----------------------------------------------------------------------
+     */
+    /**
+     * Return this iterator's current position.
+     * 
+     * @return this iterator's current position
+     */
+    public abstract int current();
+
+    /**
+     * Set this iterator's current position to the first boundary, and return
+     * this position.
+     * 
+     * @return the position of first boundary
+     */
+    public abstract int first();
+
+    /**
+     * Set the position of the first boundary following the given offset, and
+     * return this position. If there is no boundary after the given offset,
+     * return DONE.
+     * <p>
+     * <code>IllegalArgumentException</code> will be thrown if given offset is
+     * invalid.
+     * </p>
+     * 
+     * @param offset
+     *            the given position to be searched for
+     * @return the position of the first boundary following the given offset
+     */
+    public abstract int following(int offset);
+
+    /**
+     * Return a <code>CharacterIterator</code> which represents the text being
+     * analyzed. Please note that the returned value is probably the internal
+     * iterator used by this object, so that if the invoker want to modify the
+     * status of the returned iterator, a clone operation at first is
+     * recommended.
+     * 
+     * @return a <code>CharacterIterator</code> which represents the text
+     *         being analyzed.
+     */
+    public abstract CharacterIterator getText();
+
+    /**
+     * Set this iterator's current position to the last boundary, and return
+     * this position.
+     * 
+     * @return the position of last boundary
+     */
+    public abstract int last();
+
+    /**
+     * Set this iterator's current position to the next boundary after current
+     * position, and return this position. Return <code>DONE</code> if no
+     * boundary found after current position.
+     * 
+     * @return the position of last boundary
+     */
+    public abstract int next();
+
+    /**
+     * Set this iterator's current position to the next boundary after the given
+     * position, and return this position. Return <code>DONE</code> if no
+     * boundary found after the given position.
+     * 
+     * @param n
+     *            the given position.
+     * @return the position of last boundary
+     */
+    public abstract int next(int n);
+
+    /**
+     * Set this iterator's current position to the previous boundary before
+     * current position, and return this position. Return <code>DONE</code> if
+     * no boundary found before current position.
+     * 
+     * @return the position of last boundary
+     */
+    public abstract int previous();
+
+    /**
+     * Set new text to be analyzed by given <code>CharacterIterator</code>.
+     * The position will be reset to the beginning of the new text, and other
+     * status of this iterator will be kept.
+     * 
+     * @param newText
+     *            the given <code>CharacterIterator</code> refer to the text
+     *            to be analyzed
+     */
+    public abstract void setText(CharacterIterator newText);
+
+    /*
+     * -----------------------------------------------------------------------
+     * methods override Object
+     * -----------------------------------------------------------------------
+     */
+    /**
+     * Create copy of this iterator, all status including current position is
+     * kept.
+     * 
+     * @return copy of this iterator
+     */
+    @Override
+    public Object clone() {
+        try {
+            BreakIterator cloned = (BreakIterator) super.clone();
+            cloned.wrapped = (com.ibm.icu.text.BreakIterator) wrapped.clone();
+            return cloned;
+        } catch (CloneNotSupportedException e) {
+            throw new InternalError(e.getMessage());
+        }
+    }
+
+    /**
+     * Get a long value from the given byte array, start from given offset.
+     * 
+     * @param buf
+     *            the bytes to be converted
+     * @param offset
+     *            the start position of conversion
+     * @return the converted long value
+     */
+    protected static long getLong(byte[] buf, int offset) {
+        if (null == buf) {
+            throw new NullPointerException();
+        }
+        if (offset < 0 || buf.length - offset < LONG_LENGTH) {
+            throw new ArrayIndexOutOfBoundsException();
+        }
+        long result = 0;
+        for (int i = offset; i < offset + LONG_LENGTH; i++) {
+            result = (result << 8) | (buf[i] & 0xff);
+        }
+        return result;
+    }
+
+    /**
+     * Get an int value from the given byte array, start from given offset.
+     * 
+     * @param buf
+     *            the bytes to be converted
+     * @param offset
+     *            the start position of conversion
+     * @return the converted int value
+     */
+    protected static int getInt(byte[] buf, int offset) {
+        if (null == buf) {
+            throw new NullPointerException();
+        }
+        if (offset < 0 || buf.length - INT_LENGTH < offset) {
+            throw new ArrayIndexOutOfBoundsException();
+        }
+        int result = 0;
+        for (int i = offset; i < offset + INT_LENGTH; i++) {
+            result = (result << 8) | (buf[i] & 0xff);
+        }
+        return result;
+    }
+
+    /**
+     * Get a short value from the given byte array, start from given offset.
+     * 
+     * @param buf
+     *            the bytes to be converted
+     * @param offset
+     *            the start position of conversion
+     * @return the converted short value
+     */
+    protected static short getShort(byte[] buf, int offset) {
+        if (null == buf) {
+            throw new NullPointerException();
+        }
+        if (offset < 0 || buf.length - SHORT_LENGTH < offset) {
+            throw new ArrayIndexOutOfBoundsException();
+        }
+        short result = 0;
+        for (int i = offset; i < offset + SHORT_LENGTH; i++) {
+            result = (short) ((result << 8) | (buf[i] & 0xff));
+        }
+        return result;
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/CharacterIterator.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/CharacterIterator.java?view=diff&rev=462605&r1=462604&r2=462605
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/CharacterIterator.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/CharacterIterator.java Tue Oct 10 15:18:35 2006
@@ -17,7 +17,6 @@
 
 package java.text;
 
-
 /**
  * CharacterIterator is used to sequence over a group of characters. The
  * iteration starts at the begin index in the group of character and continues
@@ -25,90 +24,90 @@
  */
 public interface CharacterIterator extends Cloneable {
 
-	/**
-	 * A constant which indicates there is no character.
-	 */
-	public static char DONE = '\uffff';
-
-	/**
-	 * Answers a new CharacterIterator with the same properties.
-	 * 
-	 * @return a shallow copy of this CharacterIterator
-	 * 
-	 * @see java.lang.Cloneable
-	 */
-	public Object clone();
-
-	/**
-	 * Answers the character at the current index.
-	 * 
-	 * @return the current character, or DONE if the current index is past the
-	 *         end
-	 */
-	public char current();
-
-	/**
-	 * Sets the current position to the begin index and answers the character at
-	 * the begin index.
-	 * 
-	 * @return the character at the begin index
-	 */
-	public char first();
-
-	/**
-	 * Answers the begin index.
-	 * 
-	 * @return the index of the first character to iterate
-	 */
-	public int getBeginIndex();
-
-	/**
-	 * Answers the end index.
-	 * 
-	 * @return the index one past the last character to iterate
-	 */
-	public int getEndIndex();
-
-	/**
-	 * Answers the current index.
-	 * 
-	 * @return the current index
-	 */
-	public int getIndex();
-
-	/**
-	 * Sets the current position to the end index - 1 and answers the character
-	 * at the current position.
-	 * 
-	 * @return the character before the end index
-	 */
-	public char last();
-
-	/**
-	 * Increments the current index and returns the character at the new index.
-	 * 
-	 * @return the character at the next index, or DONE if the next index is
-	 *         past the end
-	 */
-	public char next();
-
-	/**
-	 * Decrements the current index and returns the character at the new index.
-	 * 
-	 * @return the character at the previous index, or DONE if the previous
-	 *         index is past the beginning
-	 */
-	public char previous();
-
-	/**
-	 * Sets the current index.
-	 * 
-	 * @return the character at the new index, or DONE if the index is past the
-	 *         end
-	 * 
-	 * @exception IllegalArgumentException
-	 *                when the new index is less than the begin index or greater
-	 *                than the end index
-	 */
-	public char setIndex(int location);
+    /**
+     * A constant which indicates there is no character.
+     */
+    public static char DONE = '\uffff';
+
+    /**
+     * Answers a new CharacterIterator with the same properties.
+     * 
+     * @return a shallow copy of this CharacterIterator
+     * 
+     * @see java.lang.Cloneable
+     */
+    public Object clone();
+
+    /**
+     * Answers the character at the current index.
+     * 
+     * @return the current character, or DONE if the current index is past the
+     *         end
+     */
+    public char current();
+
+    /**
+     * Sets the current position to the begin index and answers the character at
+     * the begin index.
+     * 
+     * @return the character at the begin index
+     */
+    public char first();
+
+    /**
+     * Answers the begin index.
+     * 
+     * @return the index of the first character to iterate
+     */
+    public int getBeginIndex();
+
+    /**
+     * Answers the end index.
+     * 
+     * @return the index one past the last character to iterate
+     */
+    public int getEndIndex();
+
+    /**
+     * Answers the current index.
+     * 
+     * @return the current index
+     */
+    public int getIndex();
+
+    /**
+     * Sets the current position to the end index - 1 and answers the character
+     * at the current position.
+     * 
+     * @return the character before the end index
+     */
+    public char last();
+
+    /**
+     * Increments the current index and returns the character at the new index.
+     * 
+     * @return the character at the next index, or DONE if the next index is
+     *         past the end
+     */
+    public char next();
+
+    /**
+     * Decrements the current index and returns the character at the new index.
+     * 
+     * @return the character at the previous index, or DONE if the previous
+     *         index is past the beginning
+     */
+    public char previous();
+
+    /**
+     * Sets the current index.
+     * 
+     * @return the character at the new index, or DONE if the index is past the
+     *         end
+     * 
+     * @exception IllegalArgumentException
+     *                when the new index is less than the begin index or greater
+     *                than the end index
+     */
+    public char setIndex(int location);
 }



Mime
View raw message