use of org.n52.shetland.ogc.swe.simpleType.SweQuantityRange in project arctic-sea by 52North.
the class SweCommonEncoderv20 method createQuality.
private QualityPropertyType[] createQuality(final Collection<SweQuality> quality) throws EncodingException {
if (!quality.isEmpty()) {
final ArrayList<QualityPropertyType> xbQualities = Lists.newArrayListWithCapacity(quality.size());
for (final SweQuality sweQuality : quality) {
final QualityPropertyType xbQuality = QualityPropertyType.Factory.newInstance();
if (sweQuality instanceof SweText) {
xbQuality.addNewText().set(((SweText) sweQuality).accept(new SweDataComponentVisitorImpl()));
} else if (sweQuality instanceof SweCategory) {
xbQuality.addNewCategory().set(((SweCategory) sweQuality).accept(new SweDataComponentVisitorImpl()));
} else if (sweQuality instanceof SweQuantity) {
xbQuality.addNewQuantity().set(((SweQuantity) sweQuality).accept(new SweDataComponentVisitorImpl()));
} else if (sweQuality instanceof SweQuantityRange) {
xbQuality.addNewQuantityRange().set(((SweQuantityRange) sweQuality).accept(new SweDataComponentVisitorImpl()));
}
xbQualities.add(xbQuality);
}
return xbQualities.toArray(new QualityPropertyType[xbQualities.size()]);
}
final QualityPropertyType[] result = { QualityPropertyType.Factory.newInstance() };
return result;
}
use of org.n52.shetland.ogc.swe.simpleType.SweQuantityRange in project arctic-sea by 52North.
the class SweCommonDecoderV101Test method should_decode_Category_with_Quality_QuantityRange.
@Test
public void should_decode_Category_with_Quality_QuantityRange() throws DecodingException {
final CategoryDocument xbQuantity = CategoryDocument.Factory.newInstance();
final BigDecimal rangeStart = BigDecimal.valueOf(1.0);
final BigDecimal rangeEnd = BigDecimal.valueOf(2.0);
final ArrayList<BigDecimal> categoryValue = Lists.newArrayList(rangeStart, rangeEnd);
xbQuantity.addNewCategory().addNewQuality().addNewQuantityRange().setValue(categoryValue);
final Object decodedObject = new SweCommonDecoderV101().decode(xbQuantity);
assertThat(decodedObject, is(instanceOf(SweCategory.class)));
final SweCategory sweCategory = (SweCategory) decodedObject;
assertThat(sweCategory.isSetQuality(), is(true));
assertThat(sweCategory.getQuality().size(), is(1));
assertThat(sweCategory.getQuality().iterator().next(), is(instanceOf(SweQuantityRange.class)));
assertThat(((SweQuantityRange) sweCategory.getQuality().iterator().next()).getValue(), is(new RangeValue<BigDecimal>(rangeStart, rangeEnd)));
}
use of org.n52.shetland.ogc.swe.simpleType.SweQuantityRange in project arctic-sea by 52North.
the class FieldDecoderTest method testQuantityRange.
@Test
public void testQuantityRange() throws DecodingException {
ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.QUANTITY_RANGE_TYPE).put(JSONConstants.UOM, UOM);
SweField field = checkCommon(json, false);
assertThat(field.getElement(), is(instanceOf(SweQuantityRange.class)));
SweQuantityRange swe = (SweQuantityRange) field.getElement();
errors.checkThat(swe.getUom(), is(UOM));
errors.checkThat(swe.getValue(), is(nullValue()));
}
use of org.n52.shetland.ogc.swe.simpleType.SweQuantityRange in project arctic-sea by 52North.
the class FieldEncoder method encodeSweQuantityRangeField.
private ObjectNode encodeSweQuantityRangeField(SweField field) {
ObjectNode jfield = createField(field);
jfield.put(JSONConstants.TYPE, JSONConstants.QUANTITY_RANGE_TYPE);
SweQuantityRange sweQuantityRange = (SweQuantityRange) field.getElement();
jfield.put(JSONConstants.UOM, sweQuantityRange.getUom());
if (sweQuantityRange.isSetValue()) {
ArrayNode av = jfield.putArray(JSONConstants.VALUE);
av.add(sweQuantityRange.getValue().getRangeStart());
av.add(sweQuantityRange.getValue().getRangeEnd());
}
return jfield;
}
use of org.n52.shetland.ogc.swe.simpleType.SweQuantityRange in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_count_with_quality_QuantityRange.
@Test
public void should_encode_count_with_quality_QuantityRange() throws EncodingException {
final RangeValue<BigDecimal> qualityQuantityRangeValue = new RangeValue<>(BigDecimal.valueOf(1.0), BigDecimal.valueOf(2.0));
final SweCount sosCount = (SweCount) new SweCount().setQuality(Lists.newArrayList((SweQuality) new SweQuantityRange().setValue(qualityQuantityRangeValue)));
final XmlObject encode = sweCommonEncoderv101.encode(sosCount);
assertThat(encode, instanceOf(Count.class));
final Count xbCount = (Count) encode;
assertThat(xbCount.getQualityArray(), is(not(nullValue())));
assertThat(xbCount.getQualityArray().length, is(1));
assertThat(xbCount.getQualityArray(0).isSetQuantityRange(), is(true));
assertThat(BigDecimal.valueOf((Double) xbCount.getQualityArray(0).getQuantityRange().getValue().get(0)), is(qualityQuantityRangeValue.getRangeStart()));
assertThat(BigDecimal.valueOf((Double) xbCount.getQualityArray(0).getQuantityRange().getValue().get(1)), is(qualityQuantityRangeValue.getRangeEnd()));
}
Aggregations