You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2012/10/29 18:10:43 UTC
svn commit: r1403429 - in /sis/branches/JDK7/sis-utility/src:
main/java/org/apache/sis/io/ main/java/org/apache/sis/util/
test/java/org/apache/sis/util/
Author: desruisseaux
Date: Mon Oct 29 17:10:43 2012
New Revision: 1403429
URL: http://svn.apache.org/viewvc?rev=1403429&view=rev
Log:
Minor cleaning.
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/FilteredAppendable.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/X364.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Characters.java
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/FilteredAppendable.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/FilteredAppendable.java?rev=1403429&r1=1403428&r2=1403429&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/FilteredAppendable.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/FilteredAppendable.java Mon Oct 29 17:10:43 2012
@@ -21,8 +21,6 @@ import java.io.CharConversionException;
import org.apache.sis.util.Decorator;
import org.apache.sis.util.ArgumentChecks;
-import static org.apache.sis.util.Characters.LINE_SEPARATOR;
-import static org.apache.sis.util.Characters.PARAGRAPH_SEPARATOR;
import static org.apache.sis.util.Characters.isLineOrParagraphSeparator;
@@ -78,25 +76,6 @@ public abstract class FilteredAppendable
}
/**
- * Returns {@code true} if the given character is a line separator in the sense of
- * this {@code org.apache.sis.io} package. This method performs the same work than
- * {@link org.apache.sis.util.Characters#isLineOrParagraphSeparator(int)} without
- * using the code point API. This allows simpler and faster code in subclasses working
- * only in the {@linkplain Character#isBmpCodePoint(int) Basic Multilingual Plane (BMP)}.
- * However this method assumes that all line and paragraph separators are in the BMP.
- *
- * <p>This method provides a single item to search if we need to expand our definition of
- * line separator in this package. However if such extension is needed, then developers
- * shall also search for usages of {@code LINE_SEPARATOR} and {@code PARAGRAPH_SEPARATOR}
- * constants in this package since they are sometime used directly.</p>
- *
- * @see org.apache.sis.util.Characters#isLineOrParagraphSeparator(int)
- */
- static boolean isLineSeparator(final char c) {
- return (c == '\n') || (c == '\r') || (c == LINE_SEPARATOR) || (c == PARAGRAPH_SEPARATOR);
- }
-
- /**
* Finds the line separator used in the given character sequence portion, or returns
* {@code null} if unknown. This method is designed for invocation at the beginning
* of {@code append(CharSequence, ...), before the characters are effectively read.
Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java?rev=1403429&r1=1403428&r2=1403429&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java Mon Oct 29 17:10:43 2012
@@ -471,10 +471,11 @@ searchHyp: for (int i=buffer.length();
}
}
-
/**
* Writes a single character.
*
+ * @param c The character to append.
+ * @return A reference to this {@code Appendable}.
* @throws IOException If an I/O error occurs.
*/
@Override
@@ -492,6 +493,7 @@ searchHyp: for (int i=buffer.length();
* @param sequence The character sequence to be written.
* @param start Index from which to start reading characters.
* @param end Index of the character following the last character to read.
+ * @return A reference to this {@code Appendable}.
* @throws IOException If an I/O error occurs.
*/
@Override
Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/X364.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/X364.java?rev=1403429&r1=1403428&r2=1403429&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/X364.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/X364.java Mon Oct 29 17:10:43 2012
@@ -64,15 +64,16 @@ public enum X364 {
static final char AFTER_ESCAPE = '[';
/**
- * The beginning of escape sequences.
+ * The Control Sequence Introducer (CSI).
* Must be the concatenation of {@link #ESCAPE} with {@link #AFTER_ESCAPE}.
*/
private static final String START = "\u001B[";
/**
- * The end of escape sequences.
+ * The end of escape sequences. Fixed to {@code 'm'}Â for now, but a wider range
+ * of letters actually exists for different operations.
*/
- private static char END = 'm';
+ private static final char END = 'm';
/**
* The X3.64 code.
Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java?rev=1403429&r1=1403428&r2=1403429&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java Mon Oct 29 17:10:43 2012
@@ -60,14 +60,14 @@ public final class CharSequences extends
* index in the {@code spaces} array. For example, {@code spaces[4]} contains a string
* of length 4. Strings are constructed only when first needed.
*/
- private static final String[] SPACES = new String[21];
+ private static final String[] SPACES = new String[10];
static {
// Our 'spaces(int)' method will invoke 'substring' on the longuest string in an attempt
// to share the same char[] array. Note however that array sharing has been removed from
// JDK8, which copy every char[] arrays anyway. Consequently the JDK8 branch will abandon
// this strategy and build the char[] array on the fly.
final int last = SPACES.length - 1;
- final char[] spaces = new char[last];
+ final char[] spaces = new char[last+1];
fill(spaces, ' ');
SPACES[last] = new String(spaces).intern();
}
@@ -89,8 +89,7 @@ public final class CharSequences extends
}
/**
- * Returns a string of the specified length filled with white spaces.
- * This method tries to return a pre-allocated string if possible.
+ * Returns a character sequence of the specified length filled with white spaces.
*
* <p>This method is typically used for performing right-alignment of text on the
* {@linkplain java.io.Console console} or other device using monospaced font.
@@ -101,28 +100,45 @@ public final class CharSequences extends
* @param length The string length. Negative values are clamped to 0.
* @return A string of length {@code length} filled with white spaces.
*/
- public static String spaces(int length) {
+ public static CharSequence spaces(final int length) {
/*
* No need to synchronize. In the unlikely event of two threads calling this method
* at the same time and the two calls creating a new string, the String.intern() call
* will take care of canonicalizing the strings.
*/
- if (length < 0) {
- length = 0;
+ if (length <= 0) {
+ return "";
}
- String s;
if (length < SPACES.length) {
- s = SPACES[length];
+ String s = SPACES[length-1];
if (s == null) {
s = SPACES[SPACES.length - 1].substring(0, length).intern();
- SPACES[length] = s;
+ SPACES[length-1] = s;
}
- } else {
- final char[] spaces = new char[length];
- fill(spaces, ' ');
- s = new String(spaces);
+ return s;
}
- return s;
+ return new CharSequence() {
+ @Override public int length() {
+ return length;
+ }
+
+ @Override public char charAt(int index) {
+ ArgumentChecks.ensureValidIndex(length, index);
+ return ' ';
+ }
+
+ @Override public CharSequence subSequence(final int start, final int end) {
+ ArgumentChecks.ensureValidIndexRange(length, start, end);
+ final int n = end - start;
+ return (n == length) ? this : spaces(n);
+ }
+
+ @Override public String toString() {
+ final char[] array = new char[length];
+ fill(array, ' ');
+ return new String(array);
+ }
+ };
}
/**
Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Characters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Characters.java?rev=1403429&r1=1403428&r2=1403429&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Characters.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Characters.java Mon Oct 29 17:10:43 2012
@@ -31,7 +31,7 @@ package org.apache.sis.util;
public final class Characters extends Static {
/**
* Hyphen character ('\u2010', Unicode {@code 2010}).
- * This code tells to {@link org.apache.sis.io.LineWrapFormatter}
+ * This code tells to {@link org.apache.sis.io.LineFormatter}
* that a line break is allowed to be inserted after this character.
*
* <p>For non-breaking hyphen, use the Unicode {@code 2011} character.</p>
Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java?rev=1403429&r1=1403428&r2=1403429&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java Mon Oct 29 17:10:43 2012
@@ -44,10 +44,10 @@ public final strictfp class CharSequence
*/
@Test
public void testSpaces() {
- assertEquals("", spaces(0));
- assertEquals(" ", spaces(1));
- assertEquals(" ", spaces(8));
- assertEquals("", spaces(-2));
+ assertEquals("", spaces( 0).toString());
+ assertEquals(" ", spaces( 1).toString());
+ assertEquals(" ", spaces( 8).toString());
+ assertEquals("", spaces(-2).toString());
}
/**