1 11 package org.eclipse.test.internal.performance.db; 12 13 import java.util.Arrays ; 14 import java.util.Properties ; 15 import java.util.Set ; 16 import java.util.StringTokenizer ; 17 18 import org.eclipse.test.internal.performance.PerformanceTestPlugin; 19 20 25 public class Variations extends Properties { 26 27 private static final long serialVersionUID= 1L; 28 29 32 public Variations() { 33 } 35 36 42 public Variations(String configValue, String buildValue) { 43 if (configValue != null) 44 put(PerformanceTestPlugin.CONFIG, configValue); 45 if (buildValue != null) 46 put(PerformanceTestPlugin.BUILD, buildValue); 47 } 48 49 57 public Variations(String keyValuePairs) { 58 parsePairs(keyValuePairs); 59 } 60 61 public String toExactMatchString() { 62 return toDB(this, false); 63 } 64 65 public String toQueryPattern() { 66 return toDB(this, true); 67 } 68 69 public void parsePairs(String keyvaluepairs) { 70 parse(keyvaluepairs, ";"); } 72 73 public void parseDB(String keyvaluepairs) { 74 parse(keyvaluepairs, "|"); } 76 77 83 private void parse(String keyvaluepairs, String separator) { 84 StringTokenizer st= new StringTokenizer (keyvaluepairs, separator); while (st.hasMoreTokens()) { 86 String token= st.nextToken(); 87 int i= token.indexOf('='); 88 if (i < 1) 89 throw new IllegalArgumentException ("kev/value pair '" + token + "' is illformed"); String value= token.substring(i+1); 91 token= token.substring(0, i); 92 put(token, value); 94 } 95 } 96 97 100 private static String toDB(Properties keyValues, boolean asQuery) { 101 Set set= keyValues.keySet(); 102 String [] keys= (String []) set.toArray(new String [set.size()]); 103 Arrays.sort(keys); 104 StringBuffer sb= new StringBuffer (); 105 106 for (int i= 0; i < keys.length; i++) { 107 if (asQuery) 108 sb.append('%'); 109 String key= keys[i]; 110 String value= keyValues.getProperty(key); 111 sb.append('|'); 112 sb.append(key); 113 sb.append('='); 114 if (value != null) 115 sb.append(value); 116 sb.append('|'); 117 } 118 if (asQuery) 119 sb.append('%'); 120 return sb.toString(); 121 } 122 } 123 | Popular Tags |