patterns) {
+ if (patterns != null && Iterables.size(patterns) > 0) {
+ map.put("pattern", ImmutableSet.copyOf(patterns));
+ } else
+ map.remove("pattern");
+ return this;
+ }
+
+ public Builder minInclusive(Object min) {
+ if (min != null)
+ map.put("minInclusive", min);
+ else
+ map.remove("minInclusive");
+ return this;
+ }
+
+ public Builder minExclusive(Object min) {
+ if (min != null)
+ map.put("minExclusive", min);
+ else
+ map.remove("minExclusive");
+ return this;
+ }
+
+ public Builder maxInclusive(Object max) {
+ if (max != null)
+ map.put("maxInclusive", max);
+ else
+ map.remove("maxInclusive");
+ return this;
+ }
+
+ public Builder maxExclusive(Object max) {
+ if (max != null)
+ map.put("maxExclusive", max);
+ else
+ map.remove("maxExclusive");
+ return this;
+ }
+
+ public Builder bound(Range> range) {
+ if (range != null) {
+ if (range.hasLowerBound()) {
+ switch(range.lowerBoundType()) {
+ case CLOSED:
+ minInclusive(range.lowerEndpoint());
+ break;
+ case OPEN:
+ minExclusive(range.lowerEndpoint());
+ break;
+ default:
+ break;
+ }
+ } else {
+ minInclusive(null);
+ minExclusive(null);
+ }
+ if (range.hasUpperBound()) {
+ switch(range.upperBoundType()) {
+ case CLOSED:
+ maxInclusive(range.upperEndpoint());
+ break;
+ case OPEN:
+ maxExclusive(range.upperEndpoint());
+ break;
+ default:
+ break;
+ }
+ } else {
+ maxInclusive(null);
+ maxExclusive(null);
+ }
+ }
+ return this;
+ }
+
+ public Builder step(Number step) {
+ if (step != null)
+ map.put("step", step);
+ else
+ map.remove("step");
+ return this;
+ }
+
+ public Builder enumeration(Object... vals) {
+ if (vals != null && vals.length > 0)
+ map.put("enumeration", ImmutableList.copyOf(vals));
+ else
+ map.remove("enumeration");
+ return this;
+ }
+
+ public Builder maxLength(int length) {
+ if (length > -1)
+ map.put("maxLength", length);
+ else
+ map.remove("maxLength");
+ return this;
+ }
+
+ public Builder minLength(int length) {
+ if (length > -1)
+ map.put("minLength", length);
+ else
+ map.remove("minLength");
+ return this;
+ }
+
+ public Builder totalDigits(int num) {
+ if (num > -1)
+ map.put("totalDigits", num);
+ else
+ map.remove("totalDigits");
+ return this;
+ }
+
+ public Builder fractionDigits(int num) {
+ if (num > -1)
+ map.put("fractionDigits", num);
+ else
+ map.remove("fractionDigits");
+ return this;
+ }
+
public Parameter get() {
return new Parameter(this);
}
-
+
}
- /**
- */
- public static abstract class AbstractBuilder>
- extends ASObject.AbstractBuilder
{
-
- protected AbstractBuilder() {
- objectType("parameter");
- }
-
- /**
- * Method placeholder.
- * @param val String
- * @return B
- */
- public B placeholder(String val) {
- return this._nlv("placeholder", val);
- }
-
- /**
- * Method placeholder.
- * @param nlv NLV
- * @return B
- */
- public B placeholder(NLV nlv) {
- return this._nlv("placeholder", nlv);
- }
-
- /**
- * Method placeholder.
- * @param nlv Supplier extends NLV>
- * @return B
- */
- public B placeholder(Supplier extends NLV> nlv) {
- return this._nlv("placeholder", nlv);
- }
-
- /**
- * Method placeholder.
- * @param lang String
- * @param val String
- * @return B
- */
- public B placeholder(String lang, String val) {
- return this._nlv("placeholder", lang, val);
- }
-
- /**
- * Method type.
- * @param iri String
- * @return B
- */
- public B type(String iri) {
- return type(TypeValue.SimpleTypeValue.make(iri));
- }
-
- /**
- * Method type.
- * @param tv TypeValue
- * @return B
- */
- public B type(TypeValue tv) {
- return set("type", tv);
- }
-
- /**
- * Method type.
- * @param tv Supplier extends TypeValue>
- * @return B
- */
- public B type(Supplier extends TypeValue> tv) {
- return type(tv.get());
- }
-
- /**
- * Method required.
- * @param on boolean
- * @return B
- */
- public B required(boolean on) {
- return set("required", on);
- }
-
- /**
- * Method repeated.
- * @param on boolean
- * @return B
- */
- public B repeated(boolean on) {
- return set("repeated", on);
- }
-
- /**
- * Method required.
- * @return B
- */
- public B required() {
- return required(true);
- }
-
- /**
- * Method repeated.
- * @return B
- */
- public B repeated() {
- return repeated(true);
- }
-
- /**
- * Method value.
- * @param value Object
- * @return B
- */
- public B value(Object value) {
- return set("value", value);
- }
-
- /**
- * Method defaultValue.
- * @param value Object
- * @return B
- */
- public B defaultValue(Object value) {
- return set("default", value);
- }
-
- /**
- * Method format.
- * @param format Format
- * @return B
- */
- @SuppressWarnings("unchecked")
- public B format(Format format) {
- if (format == Format.OTHER)
- return (B)this;
- return format(format.label);
- }
-
- /**
- * Method formatInt32.
- * @return B
- */
- public B formatInt32() {
- return format(Format.INT32);
- }
-
- /**
- * Method formatInt64.
- * @return B
- */
- public B formatInt64() {
- return format(Format.INT64);
- }
-
- /**
- * Method formatUint32.
- * @return B
- */
- public B formatUint32() {
- return format(Format.UINT32);
- }
-
- /**
- * Method formatUint64.
- * @return B
- */
- public B formatUint64() {
- return format(Format.UINT64);
- }
-
- /**
- * Method formatDouble.
- * @return B
- */
- public B formatDouble() {
- return format(Format.DOUBLE);
- }
-
- /**
- * Method formatFloat.
- * @return B
- */
- public B formatFloat() {
- return format(Format.FLOAT);
- }
-
- /**
- * Method formatByte.
- * @return B
- */
- public B formatByte() {
- return format(Format.BYTE);
- }
-
- /**
- * Method formatDate.
- * @return B
- */
- public B formatDate() {
- return format(Format.DATE);
- }
-
- /**
- * Method formatDateTime.
- * @return B
- */
- public B formatDateTime() {
- return format(Format.DATETIME);
- }
-
- /**
- * Method formatDuration.
- * @return B
- */
- public B formatDuration() {
- return format(Format.DURATION);
- }
-
- /**
- * Method formatLang.
- * @return B
- */
- public B formatLang() {
- return format(Format.LANG);
- }
-
- /**
- * Method formatUri.
- * @return B
- */
- public B formatUri() {
- return format(Format.URI);
- }
-
- /**
- * Method formatIri.
- * @return B
- */
- public B formatIri() {
- return format(Format.IRI);
- }
-
- /**
- * Method format.
- * @param format String
- * @return B
- */
- public B format(String format) {
- return set("format", format);
- }
-
- /**
- * Method pattern.
- * @param pattern Pattern
- * @return B
- */
- public B pattern(Pattern pattern) {
- return pattern(pattern.pattern());
- }
-
- /**
- * Method pattern.
- * @param pattern String
- * @return B
- */
- public B pattern(String pattern) {
- return set("pattern", pattern);
- }
-
- /**
- * Method minimum.
- * @param min String
- * @return B
- */
- public B minimum(String min) {
- return set("minimum", min);
- }
-
- /**
- * Method maximum.
- * @param max String
- * @return B
- */
- public B maximum(String max) {
- return set("maximum", max);
- }
-
- /**
- * Method minimum.
- * @param min int
- * @return B
- */
- public B minimum(int min) {
- return set("minimum", min);
- }
-
- /**
- * Method maximum.
- * @param max int
- * @return B
- */
- public B maximum(int max) {
- return set("maximum", max);
- }
-
- /**
- * Method minimum.
- * @param min long
- * @return B
- */
- public B minimum(long min) {
- return set("minimum", min);
- }
-
- /**
- * Method maximum.
- * @param max long
- * @return B
- */
- public B maximum(long max) {
- return set("maximum", max);
- }
-
- /**
- * Method minimum.
- * @param min short
- * @return B
- */
- public B minimum(short min) {
- return set("minimum", min);
- }
-
- /**
- * Method maximum.
- * @param max short
- * @return B
- */
- public B maximum(short max) {
- return set("maximum", max);
- }
-
- /**
- * Method minimum.
- * @param min double
- * @return B
- */
- public B minimum(double min) {
- return set("minimum", min);
- }
-
- /**
- * Method maximum.
- * @param max double
- * @return B
- */
- public B maximum(double max) {
- return set("maximum", max);
- }
-
- /**
- * Method minimum.
- * @param min float
- * @return B
- */
- public B minimum(float min) {
- return set("minimum", min);
- }
-
- /**
- * Method maximum.
- * @param max float
- * @return B
- */
- public B maximum(float max) {
- return set("maximum", max);
- }
-
- /**
- * Method step.
- * @param step int
- * @return B
- */
- public B step(int step) {
- return set("step", step);
- }
-
- /**
- * Method step.
- * @param step long
- * @return B
- */
- public B step(long step) {
- return set("step", step);
- }
-
- /**
- * Method step.
- * @param step short
- * @return B
- */
- public B step(short step) {
- return set("step", step);
- }
-
- /**
- * Method step.
- * @param step double
- * @return B
- */
- public B step(double step) {
- return set("step", step);
- }
-
- /**
- * Method step.
- * @param step float
- * @return B
- */
- public B step(float step) {
- return set("step", step);
- }
-
- /**
- * Method enumVals.
- * @param vals Object[]
- * @return B
- */
- public B enumVals(Object... vals) {
- return set("enum", ImmutableList.copyOf(vals));
- }
-
- }
+ private final ImmutableMap map;
/**
* Constructor for Parameter.
@@ -544,6 +380,7 @@ public class Parameter
*/
protected Parameter(Builder builder) {
super(builder);
+ this.map = ImmutableMap.copyOf(builder.map);
}
/**
@@ -551,7 +388,8 @@ public class Parameter
* @return boolean
*/
public boolean required() {
- return getBoolean("required");
+ return !has("required") ?
+ true : (Boolean)map.get("required");
}
/**
@@ -559,7 +397,8 @@ public class Parameter
* @return boolean
*/
public boolean repeated() {
- return getBoolean("repeated");
+ return !has("repeated") ?
+ false : (Boolean)map.get("repeated");
}
/**
@@ -567,7 +406,7 @@ public class Parameter
* @return O
*/
public O value() {
- return this.get("value");
+ return (O)map.get("value");
}
/**
@@ -576,7 +415,8 @@ public class Parameter
* @return O
*/
public O value(O defaultValue) {
- return this.get("value", defaultValue);
+ O val = value();
+ return val != null ? val : defaultValue;
}
/**
@@ -584,7 +424,7 @@ public class Parameter
* @return O
*/
public O defaultValue() {
- return this.get("default");
+ return (O)map.get("default");
}
/**
@@ -593,235 +433,84 @@ public class Parameter
* @return O
*/
public O defaultValue(O defaultValue) {
- return this.get("default", defaultValue);
+ O val = defaultValue();
+ return val != null ? val : defaultValue;
}
- /**
- * Method formatString.
- * @return String
- */
- public String formatString() {
- return getString("format");
- }
-
- /**
- * Method format.
- * @return Format
- */
- public Format format() {
- return Format.select(getString("format"));
+ public String type() {
+ return (String)map.get("type");
}
/**
* Method pattern.
* @return String
*/
- public String pattern() {
- return getString("pattern");
+ public Iterable pattern() {
+ return (Iterable)map.get("pattern");
}
- /**
- * Method maximum.
- * @return String
- */
- public String maximum() {
- return getString("maximum");
+ public O maxInclusive() {
+ return (O)map.get("maxInclusive");
}
- /**
- * Method minimum.
- * @return String
- */
- public String minimum() {
- return getString("minimum");
+ public O maxExclusive() {
+ return (O)map.get("maxExclusive");
}
- /**
- * Method maximumInt.
- * @return int
- */
- public int maximumInt() {
- return getInt("maximum");
+ public O minInclusive() {
+ return (O)map.get("minInclusive");
}
- /**
- * Method minimumInt.
- * @return int
- */
- public int minimumInt() {
- return getInt("minimum");
+ public O minExclusive() {
+ return (O)map.get("minExclusive");
}
- /**
- * Method maximumLong.
- * @return long
- */
- public long maximumLong() {
- return getLong("maximum");
+ public boolean has(String key) {
+ return map.containsKey(key);
}
- /**
- * Method minimumLong.
- * @return long
- */
- public long minimumLong() {
- return getLong("minimum");
+ public boolean hasUpperBound() {
+ return has("maxInclusive") || has("maxExclusive");
}
- /**
- * Method maximumShort.
- * @return short
- */
- public short maximumShort() {
- return getShort("maximum");
+ public >Range bounds() {
+ O mini = minInclusive();
+ O mine = minExclusive();
+ O maxi = maxInclusive();
+ O maxe = maxExclusive();
+ Ordering ordering = Ordering.natural();
+ O min = ordering.nullsLast().min(mini,mine);
+ O max = ordering.nullsFirst().max(maxi,maxe);
+ BoundType lower =
+ min == null ? null :
+ min == mini ? BoundType.CLOSED :
+ BoundType.OPEN;
+ BoundType upper =
+ max == null ? null :
+ max == maxi ? BoundType.CLOSED :
+ BoundType.OPEN;
+ if (lower == null && upper == null)
+ return Range.all();
+ else if (lower != null && upper == null)
+ return lower == BoundType.CLOSED ?
+ Range.atLeast(min) :
+ Range.greaterThan(min);
+ else if (lower == null && upper != null)
+ return upper == BoundType.CLOSED ?
+ Range.atMost(max) :
+ Range.lessThan(max);
+ else {
+ return Range.range(min, lower, max, upper);
+ }
}
- /**
- * Method minimumShort.
- * @return short
- */
- public short minimumShort() {
- return getShort("minimum");
+ public N step() {
+ return (N)map.get("step");
}
- /**
- * Method maximumDouble.
- * @return double
- */
- public double maximumDouble() {
- return getDouble("maximum");
- }
-
- /**
- * Method minimumDouble.
- * @return double
- */
- public double minimumDouble() {
- return getDouble("minimum");
- }
-
- /**
- * Method maximumFloat.
- * @return float
- */
- public float maximumFloat() {
- return getFloat("maximum");
- }
-
- /**
- * Method minimumFloat.
- * @return float
- */
- public float minimumFloat() {
- return getFloat("minimum");
- }
-
- /**
- * Method maximum.
- * @param defaultValue String
- * @return String
- */
- public String maximum(String defaultValue) {
- return getString("maximum", defaultValue);
- }
-
- /**
- * Method minimum.
- * @param defaultValue String
- * @return String
- */
- public String minimum(String defaultValue) {
- return getString("minimum", defaultValue);
- }
-
- /**
- * Method maximumInt.
- * @param defaultValue int
- * @return int
- */
- public int maximumInt(int defaultValue) {
- return getInt("maximum", defaultValue);
- }
-
- /**
- * Method minimumInt.
- * @param defaultValue int
- * @return int
- */
- public int minimumInt(int defaultValue) {
- return getInt("minimum", defaultValue);
- }
-
- /**
- * Method maximumLong.
- * @param defaultValue long
- * @return long
- */
- public long maximumLong(long defaultValue) {
- return getLong("maximum", defaultValue);
- }
-
- /**
- * Method minimumLong.
- * @param defaultValue long
- * @return long
- */
- public long minimumLong(long defaultValue) {
- return getLong("minimum", defaultValue);
- }
-
- /**
- * Method maximumShort.
- * @param defaultValue short
- * @return short
- */
- public short maximumShort(short defaultValue) {
- return getShort("maximum", defaultValue);
- }
-
- /**
- * Method minimumShort.
- * @param defaultValue short
- * @return short
- */
- public short minimumShort(short defaultValue) {
- return getShort("minimum", defaultValue);
- }
-
- /**
- * Method maximumDouble.
- * @param defaultValue double
- * @return double
- */
- public double maximumDouble(double defaultValue) {
- return getDouble("maximum", defaultValue);
- }
-
- /**
- * Method minimumDouble.
- * @param defaultValue double
- * @return double
- */
- public double minimumDouble(double defaultValue) {
- return getDouble("minimum", defaultValue);
- }
-
- /**
- * Method maximumFloat.
- * @param defaultValue float
- * @return float
- */
- public float maximumFloat(float defaultValue) {
- return getFloat("maximum", defaultValue);
- }
-
- /**
- * Method minimumFloat.
- * @param defaultValue float
- * @return float
- */
- public float minimumFloat(float defaultValue) {
- return getFloat("minimum", defaultValue);
+ public N step(N defaultValue) {
+ N n = (N)map.get("step");
+ return n != null ? n : defaultValue;
}
/**
@@ -829,7 +518,7 @@ public class Parameter
* @return int
*/
public int stepInt() {
- return getInt("step");
+ return step();
}
/**
@@ -838,7 +527,7 @@ public class Parameter
* @return int
*/
public int stepInt(int defaultValue) {
- return getInt("step", defaultValue);
+ return step(defaultValue);
}
/**
@@ -846,7 +535,7 @@ public class Parameter
* @return long
*/
public long stepLong() {
- return getLong("step");
+ return step();
}
/**
@@ -854,8 +543,8 @@ public class Parameter
* @param defaultValue long
* @return long
*/
- public long getLong(long defaultValue) {
- return getLong("step", defaultValue);
+ public long stepLong(long defaultValue) {
+ return step(defaultValue);
}
/**
@@ -863,7 +552,7 @@ public class Parameter
* @return short
*/
public short stepShort() {
- return getShort("step");
+ return step();
}
/**
@@ -872,7 +561,7 @@ public class Parameter
* @return short
*/
public short stepShort(short defaultValue) {
- return getShort("step", defaultValue);
+ return step(defaultValue);
}
/**
@@ -880,7 +569,7 @@ public class Parameter
* @return double
*/
public double stepDouble() {
- return getDouble("step");
+ return step();
}
/**
@@ -889,7 +578,7 @@ public class Parameter
* @return double
*/
public double stepDouble(double defaultValue) {
- return getDouble("step", defaultValue);
+ return step(defaultValue);
}
/**
@@ -897,7 +586,7 @@ public class Parameter
* @return float
*/
public float stepFloat() {
- return getFloat("step");
+ return step();
}
/**
@@ -906,23 +595,18 @@ public class Parameter
* @return float
*/
public float stepFloat(float defaultValue) {
- return getFloat("step", defaultValue);
+ return step(defaultValue);
}
/**
* Method enumVals.
* @return Iterable