Search in sources :

Example 1 with KlvInt

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);
}
Also used : KlvContext(org.codice.ddf.libs.klv.KlvContext) KlvIntegerEncodedFloatingPoint(org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint) KlvInt(org.codice.ddf.libs.klv.data.numerical.KlvInt)

Example 2 with KlvInt

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));
}
Also used : KlvInt(org.codice.ddf.libs.klv.data.numerical.KlvInt) Test(org.junit.Test)

Example 3 with KlvInt

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));
}
Also used : KlvInt(org.codice.ddf.libs.klv.data.numerical.KlvInt) Test(org.junit.Test)

Example 4 with KlvInt

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));
}
Also used : KlvInt(org.codice.ddf.libs.klv.data.numerical.KlvInt) Test(org.junit.Test)

Example 5 with KlvInt

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));
}
Also used : KlvInt(org.codice.ddf.libs.klv.data.numerical.KlvInt) Test(org.junit.Test)

Aggregations

KlvInt (org.codice.ddf.libs.klv.data.numerical.KlvInt)13 Test (org.junit.Test)9 KlvIntegerEncodedFloatingPoint (org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint)4 HashSet (java.util.HashSet)1 KlvContext (org.codice.ddf.libs.klv.KlvContext)1 KlvByte (org.codice.ddf.libs.klv.data.numerical.KlvByte)1 KlvDouble (org.codice.ddf.libs.klv.data.numerical.KlvDouble)1 KlvLong (org.codice.ddf.libs.klv.data.numerical.KlvLong)1 KlvShort (org.codice.ddf.libs.klv.data.numerical.KlvShort)1 KlvUnsignedByte (org.codice.ddf.libs.klv.data.numerical.KlvUnsignedByte)1 KlvUnsignedShort (org.codice.ddf.libs.klv.data.numerical.KlvUnsignedShort)1 KlvString (org.codice.ddf.libs.klv.data.text.KlvString)1 BeforeClass (org.junit.BeforeClass)1