2
|
1 package IMPL::Object::List;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
|
5 use base qw(IMPL::Object::ArrayObject);
|
3
|
6 use IMPL::Exception;
|
2
|
7
|
|
8 sub as_list {
|
4
|
9 return wantarray ? @{$_[0]} : $_[0];
|
2
|
10 }
|
|
11
|
3
|
12 sub CTOR {
|
|
13 my ($this,$data) = @_;
|
|
14
|
|
15 if ($data) {
|
|
16 die new IMPL::InvalidArgumentException("The parameter should be a reference to an array") unless UNIVERSAL::isa($data,"ARRAY");
|
|
17 @$this = @$data;
|
|
18 }
|
|
19 }
|
|
20
|
2
|
21 sub Append {
|
18
|
22 push @{$_[0]}, @_[1 .. $#_];
|
2
|
23 }
|
|
24
|
|
25 sub RemoveLast {
|
|
26 return pop @{$_[0]};
|
|
27 }
|
|
28
|
|
29 sub AddFirst {
|
|
30 return unshift @{$_[0]}, $_[1];
|
|
31 }
|
|
32
|
|
33 sub RemoveFirst {
|
|
34 return shift @{$_[0]};
|
|
35 }
|
|
36
|
|
37 sub Count {
|
|
38 return scalar @{$_[0]};
|
|
39 }
|
|
40
|
|
41 sub InsertAt {
|
|
42 my ($this,$index,@val) = @_;
|
|
43
|
11
|
44 splice @$this,($index||0),0,@val;
|
2
|
45 }
|
|
46
|
|
47 sub RemoveAt {
|
|
48 my ($this,$index,$count) = @_;
|
|
49
|
|
50 $count ||= 1;
|
|
51
|
|
52 return splice @$this,$index,$count;
|
|
53 }
|
|
54
|
4
|
55 sub RemoveItem {
|
|
56 my ($this,$item) = @_;
|
|
57
|
|
58 @$this = grep $_ != $item, @$this;
|
|
59
|
|
60 return $this;
|
|
61 }
|
|
62
|
|
63 sub RemoveItemStr {
|
|
64 my ($this,$item) = @_;
|
|
65
|
|
66 @$this = grep $_ ne $item, @$this;
|
|
67
|
|
68 return $this;
|
|
69 }
|
|
70
|
|
71
|
2
|
72 1;
|