Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2042 / extensions / org.gvsig.installer / org.gvsig.installer.lib / org.gvsig.installer.lib.impl / src / main / java / org / gvsig / installer / lib / impl / DefaultDependencies.java @ 37479

History | View | Annotate | Download (2.12 KB)

1
package org.gvsig.installer.lib.impl;
2

    
3
import java.util.ArrayList;
4
import java.util.Iterator;
5

    
6
import org.gvsig.installer.lib.api.Dependencies;
7
import org.gvsig.installer.lib.api.Dependency;
8
import org.gvsig.installer.lib.api.PackageInfo;
9
import org.gvsig.installer.lib.api.Version;
10

    
11
public class DefaultDependencies extends ArrayList<Dependency> implements Dependencies {
12

    
13
        /**
14
         * 
15
         */
16
        private static final long serialVersionUID = -6743931124069465522L;
17

    
18
        private Dependency createDependency() {
19
//                InstallerManager manager = InstallerLocator.getInstallerManager();
20
//                return manager.createDependency();
21
                return new DefaultDependency();
22
        }
23
        
24
        public Dependencies parse(String dependecies) {
25
                if( dependecies == null ) {
26
                        this.clear();
27
                        return this;
28
                }
29
                dependecies = dependecies.trim();
30
                if( dependecies.equals("") ) {
31
                        this.clear();
32
                        return this;
33
                }
34
                
35
                String[] x = dependecies.split(",");
36
                for( int i=0; i<x.length ; i++ ) {
37
                        this.add( createDependency().parse(x[i]) );
38
                }
39
                return this;
40
        }
41

    
42
        public String toString() {
43
                StringBuffer s = null;
44
                Iterator<Dependency> it = this.iterator();
45
                while( it.hasNext() ) {
46
                        if( s == null ) {
47
                                s = new StringBuffer();
48
                        } else {
49
                                s.append(", ");
50
                        }
51
                        s.append( it.next().toString() );
52
                }
53
                if( s == null ) {
54
                        return "";
55
                }
56
                return s.toString();
57
        }
58
        
59
        public boolean contains(Object o) {
60
                if( !(o instanceof Dependency) ) {
61
                        return false;
62
                }
63
                Iterator<Dependency> it = this.iterator();
64
                while( it.hasNext() ) {
65
                        Dependency dep = it.next();
66
                        if( dep.equals((Dependency)o) ) {
67
                                return true;
68
                        }
69
                }
70
                return false;
71
        }
72
        
73
        public boolean match(String type, String code, Version version) {
74
                Iterator<Dependency> it = this.iterator();
75
                while( it.hasNext() ) {
76
                        Dependency dependency = it.next();
77
                        if( dependency.match(type, code, version)) {
78
                                return true;
79
                        }
80
                }
81
                return false;
82
        }
83

    
84
        public Dependency find(String type, String code, Version version) {
85
                Iterator<Dependency> it = this.iterator();
86
                while( it.hasNext() ) {
87
                        Dependency dependency = it.next();
88
                        if( dependency.match(type, code, version)) {
89
                                return dependency;
90
                        }
91
                }
92
                return null;
93
        }
94

    
95
}