[New] Changed Parameter.getValue() for implicit cast to type

Now you can simplify:
StringParameter valueS = resource.getParameter("bagId", "paramId");
String value = valueS.getValue();

to:
String value = resource.getParameter("bagId", "paramId").getValue();

Casting is done implicitly, thus this can lead to runtime exceptions
when the parameter is not of the relevant type, but otherwise it reduces
the code by one line.

Setting the value in this manor is not supported due to the
ListParameters requiring a type of List<T>.
This commit is contained in:
Robert von Burg 2017-04-12 17:34:23 +02:00
parent 476bd0f728
commit ffca077419
12 changed files with 12 additions and 1 deletions

View File

@ -53,6 +53,7 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
return this.value.toString(); return this.value.toString();
} }
@SuppressWarnings("unchecked")
@Override @Override
public Boolean getValue() { public Boolean getValue() {
return this.value; return this.value;

View File

@ -55,6 +55,7 @@ public class DateParameter extends AbstractParameter<Date> {
return ISO8601FormatFactory.getInstance().formatDate(this.value); return ISO8601FormatFactory.getInstance().formatDate(this.value);
} }
@SuppressWarnings("unchecked")
@Override @Override
public Date getValue() { public Date getValue() {
return this.value; return this.value;

View File

@ -53,6 +53,7 @@ public class DurationParameter extends AbstractParameter<Long> {
return ISO8601FormatFactory.getInstance().formatDuration(this.value); return ISO8601FormatFactory.getInstance().formatDuration(this.value);
} }
@SuppressWarnings("unchecked")
@Override @Override
public Long getValue() { public Long getValue() {
return this.value; return this.value;

View File

@ -75,6 +75,7 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
return sb.toString(); return sb.toString();
} }
@SuppressWarnings("unchecked")
@Override @Override
public List<Double> getValue() { public List<Double> getValue() {
return new ArrayList<>(this.value); return new ArrayList<>(this.value);

View File

@ -54,6 +54,7 @@ public class FloatParameter extends AbstractParameter<Double> {
return Double.toString(this.value); return Double.toString(this.value);
} }
@SuppressWarnings("unchecked")
@Override @Override
public Double getValue() { public Double getValue() {
return this.value; return this.value;

View File

@ -75,6 +75,7 @@ public class IntegerListParameter extends AbstractParameter<List<Integer>> imple
return sb.toString(); return sb.toString();
} }
@SuppressWarnings("unchecked")
@Override @Override
public List<Integer> getValue() { public List<Integer> getValue() {
return new ArrayList<>(this.value); return new ArrayList<>(this.value);

View File

@ -58,6 +58,7 @@ public class IntegerParameter extends AbstractParameter<Integer> {
return Integer.toString(this.value); return Integer.toString(this.value);
} }
@SuppressWarnings("unchecked")
@Override @Override
public Integer getValue() { public Integer getValue() {
return this.value; return this.value;

View File

@ -75,6 +75,7 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
return sb.toString(); return sb.toString();
} }
@SuppressWarnings("unchecked")
@Override @Override
public List<Long> getValue() { public List<Long> getValue() {
return new ArrayList<>(this.value); return new ArrayList<>(this.value);

View File

@ -53,6 +53,7 @@ public class LongParameter extends AbstractParameter<Long> {
return this.value.toString(); return this.value.toString();
} }
@SuppressWarnings("unchecked")
@Override @Override
public Long getValue() { public Long getValue() {
return this.value; return this.value;

View File

@ -45,7 +45,7 @@ public interface Parameter<T> extends StrolchElement, Comparable<Parameter<?>> {
* *
* @return * @return
*/ */
public T getValue(); public <U extends T> U getValue();
/** /**
* the value of the parameter * the value of the parameter

View File

@ -75,6 +75,7 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
return sb.toString(); return sb.toString();
} }
@SuppressWarnings("unchecked")
@Override @Override
public List<String> getValue() { public List<String> getValue() {
return new ArrayList<>(this.value); return new ArrayList<>(this.value);

View File

@ -54,6 +54,7 @@ public class StringParameter extends AbstractParameter<String> {
return StrolchValueType.STRING.getType(); return StrolchValueType.STRING.getType();
} }
@SuppressWarnings("unchecked")
@Override @Override
public String getValue() { public String getValue() {
return this.value; return this.value;