svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.installer / org.gvsig.installer.lib / org.gvsig.installer.lib.impl / src / main / java / org / gvsig / installer / lib / impl / DefaultDependencies.java @ 40560
History | View | Annotate | Download (4.68 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.installer.lib.impl; |
25 |
|
26 |
import java.util.ArrayList; |
27 |
import java.util.Iterator; |
28 |
import java.util.List; |
29 |
|
30 |
import org.gvsig.installer.lib.api.Dependencies; |
31 |
import org.gvsig.installer.lib.api.Dependency; |
32 |
import org.gvsig.installer.lib.api.Version; |
33 |
import org.gvsig.tools.packageutils.StringWithAlias; |
34 |
|
35 |
public class DefaultDependencies extends ArrayList implements |
36 |
Dependencies { |
37 |
|
38 |
/**
|
39 |
*
|
40 |
*/
|
41 |
private static final long serialVersionUID = -6743931124069465522L; |
42 |
|
43 |
private Dependency createDependency() {
|
44 |
// InstallerManager manager = InstallerLocator.getInstallerManager();
|
45 |
// return manager.createDependency();
|
46 |
return new DefaultDependency(); |
47 |
} |
48 |
|
49 |
public Dependencies parse(String dependecies) { |
50 |
if (dependecies == null) { |
51 |
this.clear();
|
52 |
return this; |
53 |
} |
54 |
dependecies = dependecies.trim(); |
55 |
if (dependecies.equals("")) { |
56 |
this.clear();
|
57 |
return this; |
58 |
} |
59 |
|
60 |
String[] x = dependecies.split(","); |
61 |
for (int i = 0; i < x.length; i++) { |
62 |
this.add(createDependency().parse(x[i]));
|
63 |
} |
64 |
return this; |
65 |
} |
66 |
|
67 |
@Override
|
68 |
public String toString() { |
69 |
StringBuffer s = null; |
70 |
Iterator<Dependency> it = this.iterator(); |
71 |
while (it.hasNext()) {
|
72 |
if (s == null) { |
73 |
s = new StringBuffer(); |
74 |
} else {
|
75 |
s.append(", ");
|
76 |
} |
77 |
s.append(it.next().toString()); |
78 |
} |
79 |
if (s == null) { |
80 |
return ""; |
81 |
} |
82 |
return s.toString();
|
83 |
} |
84 |
|
85 |
@Override
|
86 |
public boolean contains(Object o) { |
87 |
if (!(o instanceof Dependency)) { |
88 |
return false; |
89 |
} |
90 |
Iterator<Dependency> it = this.iterator(); |
91 |
while (it.hasNext()) {
|
92 |
Dependency dep = it.next(); |
93 |
if (dep.equals(o)) {
|
94 |
return true; |
95 |
} |
96 |
} |
97 |
return false; |
98 |
} |
99 |
|
100 |
public boolean match(String type, String code, Version version) { |
101 |
Iterator<Dependency> it = this.iterator(); |
102 |
while (it.hasNext()) {
|
103 |
Dependency dependency = it.next(); |
104 |
if (dependency.match(type, code, version)) {
|
105 |
return true; |
106 |
} |
107 |
} |
108 |
return false; |
109 |
} |
110 |
|
111 |
public Dependency find(String type, String code, Version version) { |
112 |
Iterator<Dependency> it = this.iterator(); |
113 |
while (it.hasNext()) {
|
114 |
Dependency dependency = it.next(); |
115 |
if (dependency.match(type, code, version)) {
|
116 |
return dependency;
|
117 |
} |
118 |
} |
119 |
return null; |
120 |
} |
121 |
|
122 |
public List findAll(String type, String code, Version version) { |
123 |
|
124 |
List<Dependency> resp = null; |
125 |
Iterator<Dependency> it = this.iterator(); |
126 |
while (it.hasNext()) {
|
127 |
Dependency dependency = it.next(); |
128 |
if (dependency.match(type, code, version)) {
|
129 |
if (resp == null) { |
130 |
resp = new ArrayList<Dependency>(); |
131 |
} |
132 |
resp.add(dependency); |
133 |
} |
134 |
} |
135 |
return resp;
|
136 |
} |
137 |
|
138 |
public boolean match(String type, StringWithAlias code, Version version) { |
139 |
Iterator<Dependency> it = this.iterator(); |
140 |
while (it.hasNext()) {
|
141 |
Dependency dependency = it.next(); |
142 |
if (dependency.match(type, code, version)) {
|
143 |
return true; |
144 |
} |
145 |
} |
146 |
return false; |
147 |
} |
148 |
|
149 |
public Dependency find(String type, StringWithAlias code, Version version) { |
150 |
Iterator<Dependency> it = this.iterator(); |
151 |
while (it.hasNext()) {
|
152 |
Dependency dependency = it.next(); |
153 |
if (dependency.match(type, code, version)) {
|
154 |
return dependency;
|
155 |
} |
156 |
} |
157 |
return null; |
158 |
} |
159 |
|
160 |
public List findAll(String type, StringWithAlias code, Version version) { |
161 |
|
162 |
List<Dependency> resp = null; |
163 |
Iterator<Dependency> it = this.iterator(); |
164 |
while (it.hasNext()) {
|
165 |
Dependency dependency = it.next(); |
166 |
if (dependency.match(type, code, version)) {
|
167 |
if (resp == null) { |
168 |
resp = new ArrayList<Dependency>(); |
169 |
} |
170 |
resp.add(dependency); |
171 |
} |
172 |
} |
173 |
return resp;
|
174 |
} |
175 |
|
176 |
|
177 |
|
178 |
|
179 |
} |