001/** 002 * Copyright 2010-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.common.util.properties.rice; 017 018import static com.google.common.base.Preconditions.checkNotNull; 019 020import javax.xml.bind.annotation.XmlAccessType; 021import javax.xml.bind.annotation.XmlAccessorType; 022import javax.xml.bind.annotation.XmlAttribute; 023import javax.xml.bind.annotation.XmlValue; 024 025@XmlAccessorType(XmlAccessType.FIELD) 026public class Param implements Comparable<Param> { 027 028 @XmlAttribute(required = true) 029 private final String name; 030 031 @XmlAttribute 032 private final boolean override; 033 034 @XmlAttribute 035 private final boolean random; 036 037 @XmlAttribute 038 private final boolean system; 039 040 @XmlValue 041 private final String value; 042 043 public String getName() { 044 return name; 045 } 046 047 public boolean isOverride() { 048 return override; 049 } 050 051 public boolean isRandom() { 052 return random; 053 } 054 055 public boolean isSystem() { 056 return system; 057 } 058 059 public String getValue() { 060 return value; 061 } 062 063 public static Param create(String name, String value) { 064 return builder(name, value).build(); 065 } 066 067 public static Builder builder(String name, String value) { 068 return new Builder(name, value); 069 } 070 071 public static class Builder { 072 073 // Required 074 private final String name; 075 private final String value; 076 077 // Optional 078 private boolean override = false; 079 private boolean random = false; 080 private boolean system = false; 081 082 public Builder(String name, String value) { 083 this.name = name; 084 this.value = value; 085 } 086 087 public Builder override(boolean override) { 088 this.override = override; 089 return this; 090 } 091 092 public Builder random(boolean random) { 093 this.random = random; 094 return this; 095 } 096 097 public Builder system(boolean system) { 098 this.system = system; 099 return this; 100 } 101 102 private Builder initialized() { 103 return this; 104 } 105 106 public Param build() { 107 Param instance = new Param(this); 108 validate(instance); 109 return instance; 110 } 111 112 private static void validate(Param instance) { 113 checkNotNull(instance.name, "'name' cannot be null"); 114 checkNotNull(instance.value, "'value' cannot be null"); 115 } 116 117 } 118 119 private Param() { 120 this(new Builder(null, null).initialized()); 121 } 122 123 private Param(Builder builder) { 124 this.name = builder.name; 125 this.value = builder.value; 126 this.override = builder.override; 127 this.random = builder.random; 128 this.system = builder.system; 129 } 130 131 @Override 132 public int compareTo(Param param) { 133 return this.name.compareTo(param.getName()); 134 } 135 136}