001: /*******************************************************************************
002: * Copyright (c) 2000, 2004 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM - Initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.build;
011:
012: public class Config {
013:
014: public static String ANY = "*"; //$NON-NLS-1$
015: private String ws;
016: private String os;
017: private String arch;
018:
019: private static Config genericConfig; //singleton
020:
021: public Config(String os, String ws, String arch) {
022: this .ws = ws;
023: this .os = os;
024: this .arch = arch;
025: }
026:
027: public Config(String[] config) {
028: this (config[0], config[1], config[2]);
029: }
030:
031: public Config(String config) {
032: this (Utils.getArrayFromStringWithBlank(config, ",")); //$NON-NLS-1$
033: }
034:
035: public String getArch() {
036: return arch;
037: }
038:
039: public String getOs() {
040: return os;
041: }
042:
043: public String getWs() {
044: return ws;
045: }
046:
047: public boolean equals(Object config) {
048: if (this == config)
049: return true;
050:
051: if (!(config instanceof Config))
052: return false;
053:
054: Config aConfig = (Config) config;
055: if (!os.equalsIgnoreCase(aConfig.os))
056: return false;
057:
058: if (!ws.equalsIgnoreCase(aConfig.ws))
059: return false;
060:
061: if (!arch.equalsIgnoreCase(aConfig.arch))
062: return false;
063:
064: return true;
065: }
066:
067: public int hashCode() {
068: return os.hashCode() + ws.hashCode() + arch.hashCode();
069: }
070:
071: public String toString() {
072: return toString("_"); //$NON-NLS-1$
073: }
074:
075: public String toString(String separator) {
076: return os + separator + ws + separator + arch;
077: }
078:
079: public String toStringReplacingAny(String separator, String value) {
080: if (value == null) {
081: return ""; //$NON-NLS-1$
082: }
083:
084: String newOs = os;
085: String newWs = ws;
086: String newArch = arch;
087:
088: if (os == ANY)
089: newOs = value;
090: if (ws == ANY)
091: newWs = value;
092: if (arch == ANY)
093: newArch = value;
094:
095: return newOs + separator + newWs + separator + newArch;
096: }
097:
098: public static Config genericConfig() {
099: if (genericConfig == null)
100: genericConfig = new Config(ANY, ANY, ANY);
101:
102: return genericConfig;
103: }
104:
105: }
|