Data-ArrayList

 view release on metacpan or  search on metacpan

lib/Data/ArrayList.pm  view on Meta::CPAN


    my $copy = $dal->clone;

Returns a shallow copy of this instance.
The elements themselves are not copied.

=head2 toArray

    my @elements = $dal->toArray;

Returns an array containing all of the elements in this list in proper
sequence (from first to last element).

The returned array will be "safe" in that no references to it are maintained
by this list. (In other words, this method must allocate a new array). The
caller is thus free to modify the returned array.

B<Note:> The I<safeness> of the copy is provided by L<Data::Clone>. Please make
sure that all blessed objects implement C<clone> to support deep cloning.

=head2 set

    $dal->set( $index, $value );

Replaces the element at the specified position in this list with the specified
element.

Returns the element previously at the specified position.

=head2 ensureCapacity

    $dal->ensureCapacity( $minCapacity );

Increases the capacity of this instance, if necessary, to ensure that it can
hold at least the number of elements specified by the minimum capacity
argument.

B<Note:> This method is not supported by objects returned by L<"subList">.

=head2 remove

    $dal->remove( $index );

Removes the element at the specified position in this list. Shifts any
subsequent elements to the left (subtracts one from their indices).

Returns the element that was removed from the list.

=head2 listIterator

    my $li = $dal->listIterator( $initialPosition );

Returns a list iterator (L<Data::ArrayList::ListIterator>) of the elements in
this list (in proper sequence), starting at the specified position
(I<default is 0>) in this list. The specified index indicates the first element
that would be returned by an initial call to next. An initial call to previous
would return the element with the specified index minus one.

Iterator will die with C<ConcurrentModification> if the parent list has been
I<structurally modified>. Structural modifications are those that change the
size of the list, or otherwise perturb it in such a fashion that iterations in
progress may yield incorrect results.

=head2 subList

    my $sl = $dal->subList( $rangeFrom, $rangeTo );

Returns a view of the portion of this list between the specified C<rangeFrom>,
inclusive, and C<rangeTo>, exclusive. (If C<rangeFrom> and C<rangeTo> are
equal, the returned list is empty.) The returned list is backed by this list,
so non-structural changes in the returned list are reflected in this list, and
vice-versa. The returned list supports all of the optional list operations
supported by this list.

This method eliminates the need for explicit range operations (of the sort that
commonly exist for arrays). Any operation that expects a list can be used as a
range operation by passing a subList view instead of a whole list. For example,
the following idiom removes a range of elements from a list:

    $dal->subList($from, $to)->clear();

Returned sublist is a subclass of L<Data::ArrayList> and supports all of its
methods (except the L<"ensureCapacity">).

Sublists could be nested, as in:

    $dal->subList( 1, 100 )->subList( 20, 20 );

=for Pod::Coverage     BUILD

=head1 SEE ALSO

=over 4

=item *

L<perlfunc>

=item *

L<List::MoreUtils>

=item *

L<Data::Clone>

=item *

L<http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html>

=back

=head1 AUTHOR

Alex J. G. Burzyński <ajgb@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Alex J. G. Burzyński <ajgb@cpan.org>.

This is free software; you can redistribute it and/or modify it under



( run in 1.916 second using v1.01-cache-2.11-cpan-71847e10f99 )