commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claude Warren (JIRA)" <>
Subject [jira] [Commented] (LANG-1387) Add Span classes to handle checks for overlaps, containment, equality, etc.
Date Tue, 20 Mar 2018 08:04:00 GMT


Claude Warren commented on LANG-1387:

I think that fundamentally they address different issues and use wildly different approaches.

Range is a class, Span is an interface.  Span is intended to  be used to extend classes.

I see that Range indeed could be implemented with Integer and Long to make something like
the IntSpan and LongSpan interfaces and that Range has use outside the realm of Span as it
can handle any object that can be/is ordered.

Span however, lets you extend existing objects so that the object knows its place but is still
the object.

Consider a collection of buffers, Range would require that the range be somehow bound to the
buffer while Span can be added to the buffer either by implementing a new buffer with the
Span interface added or by dynamic proxy.  With range this is much more complicated.

In all cases I think it is possible to implement things that Span allows with extra work and
exposed code complexity using Range, just as I am certain it is possible to implement all
the things that Range allows with additional code and complexity for Span.

Span is intended to be used in situation where you have a known object and simply want to
be able to add positional information to it without the overhead of programmatically associating
the object with a position object. It does not handle the case were you are going to do things
like assign objects to an enumeration (except that an enumeration can be converted into positional
Int) nor other objects that have specific order. 

Span also shines when you have collections of things and you want to reposition them while
retaining their original positional information.  If you have a buffer of text and create
spaned buffers that point into the original buffer and delineate the paragraphs, you can then
rearrange the paragraph buffers by wrapping them in a spanned buffer but assigning them different
starting positions, this is rather handy for some types of edits.

Long and short of it is they are much the same as character array and String are much the
same, you can do many of the same operations with both but they really serve two different


As for putting Span in commons numbers, I have no opinion on the matter.  If you think it
works well there I would be happy to try to move the code into that project instead.






> Add Span classes to handle checks for overlaps, containment, equality, etc.
> ---------------------------------------------------------------------------
>                 Key: LANG-1387
>                 URL:
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*, lang.math.*
>    Affects Versions: 3.7
>            Reporter: Claude Warren
>            Priority: Minor
> This is a contribution of a span class as discussed on the mailing list.
> The classes are int and long based and can:
>  # determine if points are within the span.
>  # determine if one span contains another span
>  # determine if two spans overlap
>  # do not have to have 0 (zero) as the index origin.
>  # determine the length of the span
>  # determine the last position in the span.
>  # determine the first position in the span.
> Changes to Number Utils required to detect underflow and overflow calculations.

This message was sent by Atlassian JIRA

View raw message