harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ivanov, Alexey A" <alexey.a.iva...@intel.com>
Subject RE: [classlib][swing] compatibility: j.s.text.GapContent.replace() behaviour
Date Fri, 03 Nov 2006 07:48:05 GMT
>-----Original Message-----
>From: Stepan Mishura [mailto:stepan.mishura@gmail.com]
>Sent: Friday, November 03, 2006 9:43 AM
>To: harmony-dev@incubator.apache.org
>Subject: Re: [classlib][swing] compatibility:
>On 11/2/06, Ivanov, Alexey A wrote:
>> Hi all,
>> I've started fixing HARMONY-1809. To remove throws clause from the
>> declaration of replace method, as it was proposed by Oleg in
>> HARMONY-1975, I placed removeItems() and insertItems() calls into
>> try-catch block. This would work OK for any valid arguments.
>> Any objections, comments, opinions?
>Hi Alexey,

Hi Stepan,

>I'm not quite convinced by your evaluation (I'm not an expert in Swing
>so I may be wrong). My experiments with GapContent showed that Harmony

Let me give a quick introduction what GapContent is then. This class
serves as the default storage for all Document implementations within
javax.swing.text. It stores text in char[] array... but with a gap in
Using the default constructor the array will have length 10. And one
character will be placed into the buffer; the other 9 characters in the
array will be the gap, and they are not considered to be portion of the
content. This prevents frequent re-allocations of the underlying storage
array where text is inserted or removed. Moving the gap is cheaper than
re-allocating the array.

When an insert or remove occurs, the gap is moved so that it starts at
the position of insert or remove.

>initially created different object then RI, for example, if you create
>object with GapContent() constructor, Harmony will return start==0 and
>end==9 while RI will return start==1 and end==10. The next point that

It doesn't really matter where the gap is. This difference shows only
that the gap in the text buffer is located at different location. Using
content.shiftGap(0) on RI, you'll get start = 0, end = 9. Accordingly
using content.shiftGap(1) on Harmony, you'll get start = 1, end = 10.

What matters is that content.length() = 1 in both cases, and
content.getString(0, content.length()) returns "\n".

Actually, setting the gap to be at 0 is more efficient because the next
(or first) insert is likely to happen at position 0 rather than 1.
Therefore to insert text at position 0, the gap will be moved to 0 on RI
(which involves array copying and some other operations). This won't be
the case with Harmony because the gap is already at 0.

>confuses me that the spec. says about position as "logical position in
>storage"...and... "This is not the location in the underlying storage
>array". So negative value for position may be considered as valid.

It's all about how the text is stored in GapContent. Because there's a
gap modeled "the location in the underlying storage array" differs from
"the logical position in storage". If you look at the spec of any
methods which throw BadLocationException, you'll see that position (it's
called 'where') is to be >= 0. Since this method is used to perform
operations of insertString() and remove() in RI, negative positions are
invalid. I believe they put no checks here because validation of
parameters is performed in those methods which call replace().

Another point is that replace() in never used in Harmony implementation
- it's called from tests only.


>> Alexey.
>> P.S. The related JIRA issues:
>> https://issues.apache.org/jira/browse/HARMONY-1809
>> https://issues.apache.org/jira/browse/HARMONY-1975
>> GapContent Javadoc:
>> Description of GapContent.replace:
>> #replace(int,%20int,%20java.lang.Object,%20int)
>> --
>> Alexey A. Ivanov
>> Intel Middleware Product Division
>Stepan Mishura
>Intel Middleware Products Division
>Terms of use : http://incubator.apache.org/harmony/mailing.html
>To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
>For additional commands, e-mail: harmony-dev-help@incubator.apache.org

Alexey A. Ivanov
Intel Middleware Product Division

View raw message