View Javadoc
1   package org.kuali.common.util.properties.model.rice;
2   
3   import static com.google.common.base.Preconditions.checkNotNull;
4   
5   import javax.xml.bind.annotation.XmlAccessType;
6   import javax.xml.bind.annotation.XmlAccessorType;
7   import javax.xml.bind.annotation.XmlAttribute;
8   import javax.xml.bind.annotation.XmlValue;
9   
10  @XmlAccessorType(XmlAccessType.FIELD)
11  public class Param implements Comparable<Param> {
12  
13  	@XmlAttribute(required = true)
14  	private final String name;
15  
16  	@XmlAttribute
17  	private final boolean override;
18  
19  	@XmlAttribute
20  	private final boolean random;
21  
22  	@XmlAttribute
23  	private final boolean system;
24  
25  	@XmlValue
26  	private final String value;
27  
28  	public String getName() {
29  		return name;
30  	}
31  
32  	public boolean isOverride() {
33  		return override;
34  	}
35  
36  	public boolean isRandom() {
37  		return random;
38  	}
39  
40  	public boolean isSystem() {
41  		return system;
42  	}
43  
44  	public String getValue() {
45  		return value;
46  	}
47  
48  	public static Param create(String name, String value) {
49  		return builder(name, value).build();
50  	}
51  
52  	public static Builder builder(String name, String value) {
53  		return new Builder(name, value);
54  	}
55  
56  	public static class Builder {
57  
58  		// Required
59  		private final String name;
60  		private final String value;
61  
62  		// Optional
63  		private boolean override = false;
64  		private boolean random = false;
65  		private boolean system = false;
66  
67  		public Builder(String name, String value) {
68  			this.name = name;
69  			this.value = value;
70  		}
71  
72  		public Builder override(boolean override) {
73  			this.override = override;
74  			return this;
75  		}
76  
77  		public Builder random(boolean random) {
78  			this.random = random;
79  			return this;
80  		}
81  
82  		public Builder system(boolean system) {
83  			this.system = system;
84  			return this;
85  		}
86  
87  		private Builder initialized() {
88  			return this;
89  		}
90  
91  		public Param build() {
92  			Param instance = new Param(this);
93  			validate(instance);
94  			return instance;
95  		}
96  
97  		private static void validate(Param instance) {
98  			checkNotNull(instance.name, "'name' cannot be null");
99  			checkNotNull(instance.value, "'value' cannot be null");
100 		}
101 
102 	}
103 
104 	private Param() {
105 		this(new Builder(null, null).initialized());
106 	}
107 
108 	private Param(Builder builder) {
109 		this.name = builder.name;
110 		this.value = builder.value;
111 		this.override = builder.override;
112 		this.random = builder.random;
113 		this.system = builder.system;
114 	}
115 
116 	@Override
117 	public int compareTo(Param param) {
118 		return this.name.compareTo(param.getName());
119 	}
120 
121 }