diff options
author | David Gilbert <david.gilbert@object-refinery.com> | 2006-01-24 14:06:11 +0000 |
---|---|---|
committer | David Gilbert <david.gilbert@object-refinery.com> | 2006-01-24 14:06:11 +0000 |
commit | f677476caa8aafa7b7eacd7fc0b005b814ebdb56 (patch) | |
tree | 91689bd75139eb36e9b78d845356fd184c5259ee | |
parent | f33869bcd190b3ce21af064da2ef4c2a7f03ece8 (diff) | |
download | classpath-f677476caa8aafa7b7eacd7fc0b005b814ebdb56.tar.gz |
2006-01-24 David Gilbert <david.gilbert@object-refinery.com>
* javax/swing/text/StringContent.java
(remove): Modified argument check to prevent removal of last character,
(getChars): Removed null argument check to allow NullPointerException,
added API docs,
(checkLocation): Added API docs and white space.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | javax/swing/text/StringContent.java | 42 |
2 files changed, 39 insertions, 11 deletions
@@ -1,3 +1,11 @@ +2006-01-24 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/text/StringContent.java + (remove): Modified argument check to prevent removal of last character, + (getChars): Removed null argument check to allow NullPointerException, + added API docs, + (checkLocation): Added API docs and white space. + 2006-01-23 Lillian Angel <langel@redhat.com> * javax/swing/text/DefaultStyledDocument.java diff --git a/javax/swing/text/StringContent.java b/javax/swing/text/StringContent.java index 7db377a1c..28c6f1020 100644 --- a/javax/swing/text/StringContent.java +++ b/javax/swing/text/StringContent.java @@ -1,5 +1,5 @@ /* StringContent.java -- - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -254,7 +254,7 @@ public final class StringContent implements AbstractDocument.Content, Serializab public UndoableEdit remove(int where, int nitems) throws BadLocationException { - checkLocation(where, nitems); + checkLocation(where, nitems + 1); char[] temp = new char[(this.content.length - nitems)]; this.count = this.count - nitems; RemoveUndo rundo = new RemoveUndo(where, new String(this.content, where, nitems)); @@ -284,25 +284,45 @@ public final class StringContent implements AbstractDocument.Content, Serializab return new String (this.content, where, len); } - public void getChars(int where, int len, Segment txt) throws BadLocationException + /** + * Updates <code>txt</code> to contain a direct reference to the underlying + * character array. + * + * @param where the index of the first character. + * @param len the number of characters. + * @param txt a carrier for the return result (<code>null</code> not + * permitted). + * + * @throws BadLocationException if the requested character range is not + * within the bounds of the content. + * @throws NullPointerException if <code>txt</code> is <code>null</code>. + */ + public void getChars(int where, int len, Segment txt) + throws BadLocationException { checkLocation(where, len); - if (txt != null) - { - txt.array = this.content; - txt.offset = where; - txt.count = len; - } + txt.array = this.content; + txt.offset = where; + txt.count = len; } - // This is package-private to avoid an accessor method. + /** + * A utility method that checks the validity of the specified character + * range. + * + * @param where the first character in the range. + * @param len the number of characters in the range. + * + * @throws BadLocationException if the specified range is not within the + * bounds of the content. + */ void checkLocation(int where, int len) throws BadLocationException { if (where < 0) throw new BadLocationException("Invalid location", 1); else if (where > this.count) throw new BadLocationException("Invalid location", this.count); - else if ((where + len)>this.count) + else if ((where + len) > this.count) throw new BadLocationException("Invalid range", this.count); } |