use of org.codice.ddf.libs.klv.data.numerical.KlvInt in project alliance by codice.
the class KlvUtilities method createTestFloat.
/**
* value should be between -180 and 180
*
* @param name name of the klv data element
* @param value value of the klv data element
* @return klv data element
* @throws KlvDecodingException
*/
public static KlvIntegerEncodedFloatingPoint createTestFloat(String name, double value) throws KlvDecodingException {
long encodedMin = -180;
long encodedMax = 180;
double actualRange = encodedMax - encodedMin;
double scaledValue = (value - encodedMin) / actualRange;
long encodedRangeMin = ((long) Integer.MIN_VALUE) + 1;
long encodedRange = ((long) Integer.MAX_VALUE) - encodedRangeMin;
long encodedValue = (long) (scaledValue * encodedRange + encodedRangeMin);
byte byte1 = (byte) ((encodedValue & 0xFF000000) >> 24);
byte byte2 = (byte) ((encodedValue & 0xFF0000) >> 16);
byte byte3 = (byte) ((encodedValue & 0xFF00) >> 8);
byte byte4 = (byte) (encodedValue & 0xFF);
final byte[] klvBytes = { -8, 4, byte1, byte2, byte3, byte4 };
final KlvInt klvInt = new KlvInt(new byte[] { -8 }, name);
final KlvIntegerEncodedFloatingPoint sensorRelativeElevationAngle = new KlvIntegerEncodedFloatingPoint(klvInt, // Short.MIN_VALUE is an "out of range" indicator, so it is not included in the range.
Integer.MIN_VALUE + 1, Integer.MAX_VALUE, encodedMin, encodedMax);
final KlvContext decodedKlvContext = decodeKLV(Klv.KeyLength.OneByte, Klv.LengthEncoding.OneByte, sensorRelativeElevationAngle, klvBytes);
return (KlvIntegerEncodedFloatingPoint) decodedKlvContext.getDataElementByName(name);
}
use of org.codice.ddf.libs.klv.data.numerical.KlvInt in project alliance by codice.
the class LatitudeLongitudeHandlerTest method testAcceptWrongType.
@Test
public void testAcceptWrongType() {
KlvInt klvInt = mock(KlvInt.class);
klvHandler.accept(klvInt);
assertThat(klvHandler.asAttribute().isPresent(), is(false));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvInt in project alliance by codice.
the class ListOfBasicKlvDataTypesHandlerTest method testAcceptWrongType.
@Test
public void testAcceptWrongType() {
KlvInt klvInt = mock(KlvInt.class);
handler.accept(klvInt);
assertThat(handler.asAttribute().isPresent(), is(false));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvInt in project alliance by codice.
the class ListOfDatesHandlerTest method testAcceptWrongType.
@Test
public void testAcceptWrongType() {
KlvInt klvInt = mock(KlvInt.class);
klvHandler.accept(klvInt);
assertThat(klvHandler.asAttribute().isPresent(), is(false));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvInt in project alliance by codice.
the class GeoBoxHandlerTest method testAcceptWrongType.
@Test
public void testAcceptWrongType() {
KlvInt klvInt = mock(KlvInt.class);
geoBoxHandler.accept(klvInt);
assertThat(geoBoxHandler.asAttribute().isPresent(), is(false));
}
Aggregations