KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > Config


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.build;
12
13 public class Config {
14
15     public static String JavaDoc ANY = "*"; //$NON-NLS-1$
16
private String JavaDoc ws;
17     private String JavaDoc os;
18     private String JavaDoc arch;
19
20     private static Config genericConfig; //singleton
21

22     public Config(String JavaDoc os, String JavaDoc ws, String JavaDoc arch) {
23         this.ws = ws;
24         this.os = os;
25         this.arch = arch;
26     }
27
28     public Config(String JavaDoc[] config) {
29         this(config[0], config[1], config[2]);
30     }
31
32     public Config(String JavaDoc config) {
33         this(Utils.getArrayFromStringWithBlank(config, ",")); //$NON-NLS-1$
34
}
35
36     public String JavaDoc getArch() {
37         return arch;
38     }
39
40     public String JavaDoc getOs() {
41         return os;
42     }
43
44     public String JavaDoc getWs() {
45         return ws;
46     }
47
48     public boolean equals(Object JavaDoc config) {
49         if (this == config)
50             return true;
51
52         if (!(config instanceof Config))
53             return false;
54
55         Config aConfig = (Config) config;
56         if (!os.equalsIgnoreCase(aConfig.os))
57             return false;
58
59         if (!ws.equalsIgnoreCase(aConfig.ws))
60             return false;
61
62         if (!arch.equalsIgnoreCase(aConfig.arch))
63             return false;
64
65         return true;
66     }
67
68     public int hashCode() {
69         return os.hashCode() + ws.hashCode() + arch.hashCode();
70     }
71
72     public String JavaDoc toString() {
73         return toString("_"); //$NON-NLS-1$
74
}
75
76     public String JavaDoc toString(String JavaDoc separator) {
77         return os + separator + ws + separator + arch;
78     }
79
80     public String JavaDoc toStringReplacingAny(String JavaDoc separator, String JavaDoc value) {
81         if (value == null) {
82             return ""; //$NON-NLS-1$
83
}
84
85         String JavaDoc newOs = os;
86         String JavaDoc newWs = ws;
87         String JavaDoc newArch = arch;
88
89         if (os == ANY)
90             newOs = value;
91         if (ws == ANY)
92             newWs = value;
93         if (arch == ANY)
94             newArch = value;
95
96         return newOs + separator + newWs + separator + newArch;
97     }
98
99     public static Config genericConfig() {
100         if (genericConfig == null)
101             genericConfig = new Config(ANY, ANY, ANY);
102
103         return genericConfig;
104     }
105
106 }
107
Popular Tags