line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: SynonymTypeDefSet.pm 2014-10-07 erick.antezana $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Module : SynonymTypeDefSet.pm |
4
|
|
|
|
|
|
|
# Purpose : Synonym Type Definition Set. |
5
|
|
|
|
|
|
|
# License : Copyright (c) 2006-2014 by Erick Antezana. All rights reserved. |
6
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
7
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
# Contact : Erick Antezana |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
package OBO::Util::SynonymTypeDefSet; |
11
|
|
|
|
|
|
|
# TODO This class is identical to OBO::Util::IDspaceSet |
12
|
|
|
|
|
|
|
# TODO This class is identical to OBO::Util::SubsetDefSet, which is not implemented... |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @ISA = qw(OBO::Util::Set); |
15
|
8
|
|
|
8
|
|
5611
|
use OBO::Util::Set; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
183
|
|
16
|
|
|
|
|
|
|
|
17
|
8
|
|
|
8
|
|
31
|
use strict; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
200
|
|
18
|
8
|
|
|
8
|
|
28
|
use warnings; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
2695
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head2 contains |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Usage - $set->contains() |
23
|
|
|
|
|
|
|
Returns - true if this set contains the given element |
24
|
|
|
|
|
|
|
Args - the element (OBO::Core::SynonymTypeDef) to be checked |
25
|
|
|
|
|
|
|
Function - checks if this set constains the given element |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
sub contains { |
29
|
54
|
|
|
54
|
1
|
147
|
my $self = shift; |
30
|
54
|
|
|
|
|
49
|
my $result = 0; |
31
|
54
|
50
|
|
|
|
98
|
if (@_){ |
32
|
54
|
|
|
|
|
45
|
my $target = shift; |
33
|
|
|
|
|
|
|
|
34
|
54
|
|
|
|
|
49
|
foreach my $ele (@{$self->{SET}}){ |
|
54
|
|
|
|
|
102
|
|
35
|
89
|
100
|
|
|
|
183
|
if ($target->equals($ele)) { |
36
|
20
|
|
|
|
|
19
|
$result = 1; |
37
|
20
|
|
|
|
|
27
|
last; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
54
|
|
|
|
|
142
|
return $result; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 equals |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Usage - $set->equals() |
47
|
|
|
|
|
|
|
Returns - true or false |
48
|
|
|
|
|
|
|
Args - the set (OBO::Util::SynonymTypeDefSet) to compare with |
49
|
|
|
|
|
|
|
Function - tells whether this set is equal to the given one |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
sub equals { |
53
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
54
|
1
|
|
|
|
|
1
|
my $result = 0; # I guess they'are NOT identical |
55
|
1
|
50
|
|
|
|
3
|
if (@_) { |
56
|
1
|
|
|
|
|
2
|
my $other_set = shift; |
57
|
|
|
|
|
|
|
|
58
|
1
|
|
|
|
|
2
|
my %count = (); |
59
|
1
|
|
|
|
|
1
|
my @this = map ({scalar $_;} @{$self->{SET}}); |
|
4
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
3
|
|
60
|
1
|
|
|
|
|
4
|
my @that = map ({scalar $_;} $other_set->get_set()); |
|
0
|
|
|
|
|
0
|
|
61
|
|
|
|
|
|
|
|
62
|
1
|
50
|
|
|
|
5
|
if ($#this == $#that) { |
63
|
0
|
|
|
|
|
0
|
foreach (@this, @that) { |
64
|
0
|
|
|
|
|
0
|
$count{$_}++; |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
0
|
foreach my $count (sort values %count) { |
67
|
0
|
0
|
|
|
|
0
|
if ($count != 2) { |
68
|
0
|
|
|
|
|
0
|
$result = 0; |
69
|
0
|
|
|
|
|
0
|
last; |
70
|
|
|
|
|
|
|
} else { |
71
|
0
|
|
|
|
|
0
|
$result = 1; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
1
|
|
|
|
|
2
|
return $result; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 remove |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Usage - $set->remove($element) |
82
|
|
|
|
|
|
|
Returns - the removed element |
83
|
|
|
|
|
|
|
Args - the element (OBO::Core::SynonymTypeDef) to be removed |
84
|
|
|
|
|
|
|
Function - removes an element from this set |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
sub remove { |
88
|
3
|
|
|
3
|
1
|
8
|
my $self = shift; |
89
|
3
|
|
|
|
|
3
|
my $result = undef; |
90
|
3
|
50
|
|
|
|
7
|
if (@_) { |
91
|
3
|
|
|
|
|
4
|
my $ele = shift; |
92
|
3
|
100
|
|
|
|
42
|
if ($self->size() > 0) { |
93
|
2
|
|
|
|
|
499
|
for (my $i = 0; $i < scalar(@{$self->{SET}}); $i++){ |
|
5
|
|
|
|
|
17
|
|
94
|
5
|
|
|
|
|
5
|
my $e = ${$self->{SET}}[$i]; |
|
5
|
|
|
|
|
46
|
|
95
|
5
|
100
|
|
|
|
13
|
if ($ele->equals($e)) { |
96
|
2
|
100
|
|
|
|
6
|
if ($self->size() > 1) { |
|
|
50
|
|
|
|
|
|
97
|
1
|
|
|
|
|
1
|
my $first_elem = shift (@{$self->{SET}}); |
|
1
|
|
|
|
|
3
|
|
98
|
1
|
|
|
|
|
2
|
${$self->{SET}}[$i-1] = $first_elem; |
|
1
|
|
|
|
|
1
|
|
99
|
|
|
|
|
|
|
} elsif ($self->size() == 1) { |
100
|
1
|
|
|
|
|
2
|
shift (@{$self->{SET}}); |
|
1
|
|
|
|
|
3
|
|
101
|
|
|
|
|
|
|
} |
102
|
2
|
|
|
|
|
3
|
$result = $ele; |
103
|
2
|
|
|
|
|
4
|
last; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
3
|
|
|
|
|
9
|
return $result; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |