src/main/java/de/unixwork/uwproj/Option.java

changeset 40
b42bfc9e9983
parent 0
38775db5fdf5
child 41
75ee588d5d9e
equal deleted inserted replaced
39:3ca85da78515 40:b42bfc9e9983
1 /*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6 package de.unixwork.uwproj; 1 package de.unixwork.uwproj;
7 2
8 import java.util.LinkedList;
9 import java.util.List;
10 import org.w3c.dom.Element; 3 import org.w3c.dom.Element;
11 import org.w3c.dom.Node; 4 import org.w3c.dom.Node;
12 import org.w3c.dom.NodeList; 5 import org.w3c.dom.NodeList;
13 6
14 /** 7 import java.util.LinkedList;
15 * 8 import java.util.List;
16 * @author olaf 9
17 */
18 public class Option { 10 public class Option {
19 private String arg; 11 private String arg;
20 12
21 LinkedList<OptionValue> values = new LinkedList<>(); 13 LinkedList<OptionValue> values = new LinkedList<>();
22 LinkedList<OptionDefault> defaults = new LinkedList<>(); 14 LinkedList<OptionDefault> defaults = new LinkedList<>();
23 15
24 public static Option parse(Project project, Element element) throws Exception { 16 public static Option parse(Project project, Element element) throws Exception {
25 Option opt = new Option(); 17 Option opt = new Option();
26 String arg = element.getAttribute("arg"); 18 String arg = element.getAttribute("arg");
27 if(arg.length() == 0) { 19 if(arg.isEmpty()) {
28 throw new Exception("Option has no argument string"); 20 throw new Exception("Option has no argument string");
29 } 21 }
30 opt.setArgument(arg); 22 opt.setArgument(arg);
31 23
32 NodeList nodes = element.getChildNodes(); 24 NodeList nodes = element.getChildNodes();
43 } else if(n.equals("default")) { 35 } else if(n.equals("default")) {
44 String defValue = elm.getAttribute("value"); 36 String defValue = elm.getAttribute("value");
45 String defPlatform = elm.getAttribute(("platform")); 37 String defPlatform = elm.getAttribute(("platform"));
46 OptionDefault def = new OptionDefault(opt); 38 OptionDefault def = new OptionDefault(opt);
47 def.setValueName(defValue); 39 def.setValueName(defValue);
48 if(defPlatform.length() > 0) { 40 if(!defPlatform.isEmpty()) {
49 def.setPlatform(defPlatform); 41 def.setPlatform(defPlatform);
50 } 42 }
51 opt.defaults.add(def); 43 opt.defaults.add(def);
52 } 44 }
53 } 45 }
83 public String getValueFunc(String value) { 75 public String getValueFunc(String value) {
84 return "checkopt_"+arg+"_"+value; 76 return "checkopt_"+arg+"_"+value;
85 } 77 }
86 78
87 public String getValuesString() { 79 public String getValuesString() {
88 if(values.size() == 0) { 80 if(values.isEmpty()) {
89 return "()"; 81 return "()";
90 } else if(values.size() == 1) { 82 } else if(values.size() == 1) {
91 return values.get(0).getValue(); 83 return values.get(0).getValue();
92 } else { 84 } else {
93 StringBuilder vs = new StringBuilder(); 85 StringBuilder vs = new StringBuilder();

mercurial