[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:
parent
476bd0f728
commit
ffca077419
|
@ -53,6 +53,7 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
|
|||
return this.value.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Boolean getValue() {
|
||||
return this.value;
|
||||
|
|
|
@ -55,6 +55,7 @@ public class DateParameter extends AbstractParameter<Date> {
|
|||
return ISO8601FormatFactory.getInstance().formatDate(this.value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Date getValue() {
|
||||
return this.value;
|
||||
|
|
|
@ -53,6 +53,7 @@ public class DurationParameter extends AbstractParameter<Long> {
|
|||
return ISO8601FormatFactory.getInstance().formatDuration(this.value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Long getValue() {
|
||||
return this.value;
|
||||
|
|
|
@ -75,6 +75,7 @@ public class FloatListParameter extends AbstractParameter<List<Double>> implemen
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Double> getValue() {
|
||||
return new ArrayList<>(this.value);
|
||||
|
|
|
@ -54,6 +54,7 @@ public class FloatParameter extends AbstractParameter<Double> {
|
|||
return Double.toString(this.value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Double getValue() {
|
||||
return this.value;
|
||||
|
|
|
@ -75,6 +75,7 @@ public class IntegerListParameter extends AbstractParameter<List<Integer>> imple
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Integer> getValue() {
|
||||
return new ArrayList<>(this.value);
|
||||
|
|
|
@ -58,6 +58,7 @@ public class IntegerParameter extends AbstractParameter<Integer> {
|
|||
return Integer.toString(this.value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return this.value;
|
||||
|
|
|
@ -75,6 +75,7 @@ public class LongListParameter extends AbstractParameter<List<Long>> implements
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Long> getValue() {
|
||||
return new ArrayList<>(this.value);
|
||||
|
|
|
@ -53,6 +53,7 @@ public class LongParameter extends AbstractParameter<Long> {
|
|||
return this.value.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Long getValue() {
|
||||
return this.value;
|
||||
|
|
|
@ -45,7 +45,7 @@ public interface Parameter<T> extends StrolchElement, Comparable<Parameter<?>> {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
public T getValue();
|
||||
public <U extends T> U getValue();
|
||||
|
||||
/**
|
||||
* the value of the parameter
|
||||
|
|
|
@ -75,6 +75,7 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<String> getValue() {
|
||||
return new ArrayList<>(this.value);
|
||||
|
|
|
@ -54,6 +54,7 @@ public class StringParameter extends AbstractParameter<String> {
|
|||
return StrolchValueType.STRING.getType();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
|
|
Loading…
Reference in New Issue