Example usage for java.lang Short MIN_VALUE

List of usage examples for java.lang Short MIN_VALUE

Introduction

In this page you can find the example usage for java.lang Short MIN_VALUE.

Prototype

short MIN_VALUE

To view the source code for java.lang Short MIN_VALUE.

Click Source Link

Document

A constant holding the minimum value a short can have, -215.

Usage

From source file:edu.stanford.slac.archiverappliance.PB.data.BoundaryConditionsSimulationValueGenerator.java

public DBR getJCASampleValue(ArchDBRTypes type, int secondsIntoYear) {
    switch (type) {
    case DBR_SCALAR_STRING:
        DBR_TIME_String retvalss = new DBR_TIME_String(new String[] { Integer.toString(secondsIntoYear) });
        retvalss.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear));
        retvalss.setSeverity(1);/*from   w  w  w  .  jav a  2s .  c  o  m*/
        retvalss.setStatus(0);
        return retvalss;
    case DBR_SCALAR_SHORT:
        DBR_TIME_Short retvalsh;
        if (0 <= secondsIntoYear && secondsIntoYear < 1000) {
            // Check for some numbers around the minimum value
            retvalsh = new DBR_TIME_Short(new short[] { (short) (Short.MIN_VALUE + secondsIntoYear) });
        } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) {
            // Check for some numbers around the maximum value
            retvalsh = new DBR_TIME_Short(new short[] { (short) (Short.MAX_VALUE - (secondsIntoYear - 1000)) });
        } else {
            // Check for some numbers around 0
            retvalsh = new DBR_TIME_Short(new short[] { (short) (secondsIntoYear - 2000) });
        }
        retvalsh.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear));
        retvalsh.setSeverity(1);
        retvalsh.setStatus(0);
        return retvalsh;
    case DBR_SCALAR_FLOAT:
        DBR_TIME_Float retvalfl;
        if (0 <= secondsIntoYear && secondsIntoYear < 1000) {
            // Check for some numbers around the minimum value
            retvalfl = new DBR_TIME_Float(new float[] { Float.MIN_VALUE + secondsIntoYear });
        } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) {
            // Check for some numbers around the maximum value
            retvalfl = new DBR_TIME_Float(new float[] { Float.MAX_VALUE - (secondsIntoYear - 1000) });
        } else {
            // Check for some numbers around 0. Divide by a large number to make sure we cater to the number of precision digits
            retvalfl = new DBR_TIME_Float(new float[] { (secondsIntoYear - 2000.0f) / secondsIntoYear });
        }
        retvalfl.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear));
        retvalfl.setSeverity(1);
        retvalfl.setStatus(0);
        return retvalfl;
    case DBR_SCALAR_ENUM:
        DBR_TIME_Enum retvalen;
        retvalen = new DBR_TIME_Enum(new short[] { (short) (secondsIntoYear) });
        retvalen.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear));
        retvalen.setSeverity(1);
        retvalen.setStatus(0);
        return retvalen;
    case DBR_SCALAR_BYTE:
        DBR_TIME_Byte retvalby;
        retvalby = new DBR_TIME_Byte(new byte[] { ((byte) (secondsIntoYear % 255)) });
        retvalby.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear));
        retvalby.setSeverity(1);
        retvalby.setStatus(0);
        return retvalby;
    case DBR_SCALAR_INT:
        DBR_TIME_Int retvalint;
        if (0 <= secondsIntoYear && secondsIntoYear < 1000) {
            // Check for some numbers around the minimum value
            retvalint = new DBR_TIME_Int(new int[] { Integer.MIN_VALUE + secondsIntoYear });
        } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) {
            // Check for some numbers around the maximum value
            retvalint = new DBR_TIME_Int(new int[] { Integer.MAX_VALUE - (secondsIntoYear - 1000) });
        } else {
            // Check for some numbers around 0
            retvalint = new DBR_TIME_Int(new int[] { (secondsIntoYear - 2000) });
        }
        retvalint.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear));
        retvalint.setSeverity(1);
        retvalint.setStatus(0);
        return retvalint;
    case DBR_SCALAR_DOUBLE:
        DBR_TIME_Double retvaldb;
        if (0 <= secondsIntoYear && secondsIntoYear < 1000) {
            // Check for some numbers around the minimum value
            retvaldb = new DBR_TIME_Double(new double[] { (Double.MIN_VALUE + secondsIntoYear) });
        } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) {
            // Check for some numbers around the maximum value
            retvaldb = new DBR_TIME_Double(new double[] { (Double.MAX_VALUE - (secondsIntoYear - 1000)) });
        } else {
            // Check for some numbers around 0. Divide by a large number to make sure we cater to the number of precision digits
            retvaldb = new DBR_TIME_Double(
                    new double[] { ((secondsIntoYear - 2000.0) / (secondsIntoYear * 1000000)) });
        }
        retvaldb.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear));
        retvaldb.setSeverity(1);
        retvaldb.setStatus(0);
        return retvaldb;
    case DBR_WAVEFORM_STRING:
        DBR_TIME_String retvst;
        // Varying number of copies of a typical value
        retvst = new DBR_TIME_String(
                Collections.nCopies(secondsIntoYear, Integer.toString(secondsIntoYear)).toArray(new String[0]));
        retvst.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear));
        retvst.setSeverity(1);
        retvst.setStatus(0);
        return retvst;
    case DBR_WAVEFORM_SHORT:
        DBR_TIME_Short retvsh;
        retvsh = new DBR_TIME_Short(
                ArrayUtils.toPrimitive(Collections.nCopies(1, (short) secondsIntoYear).toArray(new Short[0])));
        retvsh.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear));
        retvsh.setSeverity(1);
        retvsh.setStatus(0);
        return retvsh;
    case DBR_WAVEFORM_FLOAT:
        DBR_TIME_Float retvf;
        // Varying number of copies of a typical value
        retvf = new DBR_TIME_Float(ArrayUtils.toPrimitive(
                Collections.nCopies(secondsIntoYear, (float) Math.cos(secondsIntoYear * Math.PI / 3600))
                        .toArray(new Float[0])));
        retvf.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear));
        retvf.setSeverity(1);
        retvf.setStatus(0);
        return retvf;
    case DBR_WAVEFORM_ENUM:
        DBR_TIME_Enum retven;
        retven = new DBR_TIME_Enum(ArrayUtils
                .toPrimitive(Collections.nCopies(1024, (short) secondsIntoYear).toArray(new Short[0])));
        retven.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear));
        retven.setSeverity(1);
        retven.setStatus(0);
        return retven;
    case DBR_WAVEFORM_BYTE:
        DBR_TIME_Byte retvb;
        // Large number of elements in the array
        retvb = new DBR_TIME_Byte(ArrayUtils.toPrimitive(Collections
                .nCopies(65536 * secondsIntoYear, ((byte) (secondsIntoYear % 255))).toArray(new Byte[0])));
        retvb.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear));
        retvb.setSeverity(1);
        retvb.setStatus(0);
        return retvb;
    case DBR_WAVEFORM_INT:
        DBR_TIME_Int retvint;
        // Varying number of copies of a typical value
        retvint = new DBR_TIME_Int(ArrayUtils.toPrimitive(Collections
                .nCopies(secondsIntoYear, secondsIntoYear * secondsIntoYear).toArray(new Integer[0])));
        retvint.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear));
        retvint.setSeverity(1);
        retvint.setStatus(0);
        return retvint;
    case DBR_WAVEFORM_DOUBLE:
        DBR_TIME_Double retvd;
        // Varying number of copies of a typical value
        retvd = new DBR_TIME_Double(ArrayUtils.toPrimitive(Collections
                .nCopies(secondsIntoYear, Math.sin(secondsIntoYear * Math.PI / 3600)).toArray(new Double[0])));
        retvd.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear));
        retvd.setSeverity(1);
        retvd.setStatus(0);
        return retvd;
    case DBR_V4_GENERIC_BYTES:
        throw new RuntimeException("Currently don't support " + type + " when generating sample data");
    default:
        throw new RuntimeException("We seemed to have missed a DBR type when generating sample data");
    }
}

From source file:com.eventsourcing.postgresql.PostgreSQLJournalTest.java

@Test
@SneakyThrows//from   w  w w  .j av a2  s  . c  o m
public void serializationValue() {
    assertEquals(serializationResult(TestClass.builder().pByte(Byte.MIN_VALUE).build()).pByte(),
            Byte.MIN_VALUE);
    assertEquals(serializationResult(TestClass.builder().pByte(Byte.MAX_VALUE).build()).pByte(),
            Byte.MAX_VALUE);

    assertEquals((byte) serializationResult(TestClass.builder().oByte(Byte.MIN_VALUE).build()).oByte(),
            Byte.MIN_VALUE);
    assertEquals((byte) serializationResult(TestClass.builder().oByte(Byte.MAX_VALUE).build()).oByte(),
            Byte.MAX_VALUE);

    assertEquals(
            serializationResult(TestClass.builder().pByteArr("Hello, world".getBytes()).build()).pByteArr(),
            "Hello, world".getBytes());
    assertEquals(
            serializationResult(TestClass.builder().oByteArr(toObject(("Hello, world").getBytes())).build())
                    .oByteArr(),
            "Hello, world".getBytes());

    assertEquals(serializationResult(TestClass.builder().pShort(Short.MIN_VALUE).build()).pShort(),
            Short.MIN_VALUE);
    assertEquals((short) serializationResult(TestClass.builder().oShort(Short.MAX_VALUE).build()).oShort(),
            Short.MAX_VALUE);

    assertEquals(serializationResult(TestClass.builder().pInt(Integer.MIN_VALUE).build()).pInt(),
            Integer.MIN_VALUE);
    assertEquals((int) serializationResult(TestClass.builder().oInt(Integer.MAX_VALUE).build()).oInt(),
            Integer.MAX_VALUE);

    assertEquals(serializationResult(TestClass.builder().pLong(Long.MIN_VALUE).build()).pLong(),
            Long.MIN_VALUE);
    assertEquals((long) serializationResult(TestClass.builder().oLong(Long.MAX_VALUE).build()).oLong(),
            Long.MAX_VALUE);

    assertEquals(serializationResult(TestClass.builder().pFloat(Float.MIN_VALUE).build()).pFloat(),
            Float.MIN_VALUE);
    assertEquals(serializationResult(TestClass.builder().oFloat(Float.MAX_VALUE).build()).oFloat(),
            Float.MAX_VALUE);

    assertEquals(serializationResult(TestClass.builder().pDouble(Double.MIN_VALUE).build()).pDouble(),
            Double.MIN_VALUE);
    assertEquals(serializationResult(TestClass.builder().oDouble(Double.MAX_VALUE).build()).oDouble(),
            Double.MAX_VALUE);

    assertEquals(serializationResult(TestClass.builder().pBoolean(true).build()).pBoolean(), true);
    assertEquals(serializationResult(TestClass.builder().pBoolean(false).build()).pBoolean(), false);

    assertEquals((boolean) serializationResult(TestClass.builder().oBoolean(true).build()).oBoolean(), true);
    assertEquals((boolean) serializationResult(TestClass.builder().oBoolean(false).build()).oBoolean(), false);

    assertEquals(serializationResult(TestClass.builder().str("Hello, world").build()).str(), "Hello, world");

    UUID uuid = UUID.randomUUID();
    assertEquals(serializationResult(TestClass.builder().uuid(uuid).build()).uuid(), uuid);

    assertEquals(serializationResult(TestClass.builder().e(TestClass.E.B).build()).e(), TestClass.E.B);

    assertEquals(serializationResult(TestClass.builder().value(new SomeValue("test")).build()).value().value(),
            "test");

    assertEquals(serializationResult(TestClass.builder()
            .value1(new SomeValue1(Collections.singletonList(new SomeValue2(new SomeValue("test"))))).build())
                    .value1().value().get(0).value().value(),
            "test");

    ArrayList<List<String>> l = new ArrayList<>();
    ArrayList<String> l1 = new ArrayList<>();
    l1.add("test");
    l.add(l1);
    assertEquals(serializationResult(TestClass.builder().list(l).build()).list().get(0).get(0), "test");

    Map<String, List<String>> map = new HashMap<>();
    LinkedList<String> list = new LinkedList<>(Arrays.asList("Hello"));
    map.put("test", list);
    map.put("anothertest", list);
    assertEquals(serializationResult(TestClass.builder().map(map).build()).map().get("test").get(0), "Hello");
    assertEquals(serializationResult(TestClass.builder().map(map).build()).map().get("anothertest").get(0),
            "Hello");

    assertFalse(
            serializationResult(TestClass.builder().optional(Optional.empty()).build()).optional().isPresent());
    assertTrue(serializationResult(TestClass.builder().optional(Optional.of("test")).build()).optional()
            .isPresent());
    assertEquals(
            serializationResult(TestClass.builder().optional(Optional.of("test")).build()).optional().get(),
            "test");

    BigDecimal bigDecimal = new BigDecimal("0.00000000000000000000000000001");
    assertEquals(serializationResult(TestClass.builder().bigDecimal(bigDecimal).build()).bigDecimal(),
            bigDecimal);

    BigInteger bigInteger = new BigInteger("100001");
    assertEquals(serializationResult(TestClass.builder().bigInteger(bigInteger).build()).bigInteger(),
            bigInteger);

    Date date = new Date();
    assertEquals(serializationResult(TestClass.builder().date(date).build()).date(), date);
}

From source file:org.apache.myfaces.shared_impl.renderkit.RendererUtils.java

/**
 * See JSF Spec. 8.5 Table 8-1/*w w w.  j  av  a 2  s.com*/
 *
 * @param value
 * @return boolean
 */
public static boolean isDefaultAttributeValue(Object value) {
    if (value == null) {
        return true;
    } else if (value instanceof Boolean) {
        return !((Boolean) value).booleanValue();
    } else if (value instanceof Number) {
        if (value instanceof Integer) {
            return ((Number) value).intValue() == Integer.MIN_VALUE;
        } else if (value instanceof Double) {
            return ((Number) value).doubleValue() == Double.MIN_VALUE;
        } else if (value instanceof Long) {
            return ((Number) value).longValue() == Long.MIN_VALUE;
        } else if (value instanceof Byte) {
            return ((Number) value).byteValue() == Byte.MIN_VALUE;
        } else if (value instanceof Float) {
            return ((Number) value).floatValue() == Float.MIN_VALUE;
        } else if (value instanceof Short) {
            return ((Number) value).shortValue() == Short.MIN_VALUE;
        }
    }
    return false;
}

From source file:org.apache.flink.table.codegen.SortCodeGeneratorTest.java

private Object value1(InternalType type, Random rnd) {
    if (type.equals(InternalTypes.BOOLEAN)) {
        return false;
    } else if (type.equals(InternalTypes.BYTE)) {
        return Byte.MIN_VALUE;
    } else if (type.equals(InternalTypes.SHORT)) {
        return Short.MIN_VALUE;
    } else if (type.equals(InternalTypes.INT)) {
        return Integer.MIN_VALUE;
    } else if (type.equals(InternalTypes.LONG)) {
        return Long.MIN_VALUE;
    } else if (type.equals(InternalTypes.FLOAT)) {
        return Float.MIN_VALUE;
    } else if (type.equals(InternalTypes.DOUBLE)) {
        return Double.MIN_VALUE;
    } else if (type.equals(InternalTypes.STRING)) {
        return BinaryString.fromString("");
    } else if (type instanceof DecimalType) {
        DecimalType decimalType = (DecimalType) type;
        return Decimal.fromBigDecimal(new BigDecimal(Integer.MIN_VALUE), decimalType.precision(),
                decimalType.scale());//from w  w  w.j av  a 2  s . com
    } else if (type instanceof ArrayType) {
        byte[] bytes = new byte[rnd.nextInt(7) + 1];
        rnd.nextBytes(bytes);
        BinaryArray array = BinaryArray.fromPrimitiveArray(bytes);
        for (int i = 0; i < bytes.length; i++) {
            array.setNullByte(i);
        }
        return array;
    } else if (type.equals(InternalTypes.BINARY)) {
        byte[] bytes = new byte[rnd.nextInt(7) + 1];
        rnd.nextBytes(bytes);
        return bytes;
    } else if (type instanceof RowType) {
        return GenericRow.of(new Object[] { null });
    } else if (type instanceof GenericType) {
        return new BinaryGeneric<>(rnd.nextInt(), IntSerializer.INSTANCE);
    } else {
        throw new RuntimeException("Not support!");
    }
}

From source file:com.examples.with.different.packagename.testcarver.NumberConverter.java

/**
 * Convert any Number object to the specified type for this
 * <i>Converter</i>./*w  w  w .  java2s.  c om*/
 * <p>
 * This method handles conversion to the following types:
 * <ul>
 *     <li><code>java.lang.Byte</code></li>
 *     <li><code>java.lang.Short</code></li>
 *     <li><code>java.lang.Integer</code></li>
 *     <li><code>java.lang.Long</code></li>
 *     <li><code>java.lang.Float</code></li>
 *     <li><code>java.lang.Double</code></li>
 *     <li><code>java.math.BigDecimal</code></li>
 *     <li><code>java.math.BigInteger</code></li>
 * </ul>
 * @param sourceType The type being converted from
 * @param targetType The Number type to convert to
 * @param value The Number to convert.
 *
 * @return The converted value.
 */
private Number toNumber(Class sourceType, Class targetType, Number value) {

    // Correct Number type already
    if (targetType.equals(value.getClass())) {
        return value;
    }

    // Byte
    if (targetType.equals(Byte.class)) {
        long longValue = value.longValue();
        if (longValue > Byte.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        if (longValue < Byte.MIN_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too small " + toString(targetType));
        }
        return new Byte(value.byteValue());
    }

    // Short
    if (targetType.equals(Short.class)) {
        long longValue = value.longValue();
        if (longValue > Short.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        if (longValue < Short.MIN_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too small " + toString(targetType));
        }
        return new Short(value.shortValue());
    }

    // Integer
    if (targetType.equals(Integer.class)) {
        long longValue = value.longValue();
        if (longValue > Integer.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        if (longValue < Integer.MIN_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too small " + toString(targetType));
        }
        return new Integer(value.intValue());
    }

    // Long
    if (targetType.equals(Long.class)) {
        return new Long(value.longValue());
    }

    // Float
    if (targetType.equals(Float.class)) {
        if (value.doubleValue() > Float.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        return new Float(value.floatValue());
    }

    // Double
    if (targetType.equals(Double.class)) {
        return new Double(value.doubleValue());
    }

    // BigDecimal
    if (targetType.equals(BigDecimal.class)) {
        if (value instanceof Float || value instanceof Double) {
            return new BigDecimal(value.toString());
        } else if (value instanceof BigInteger) {
            return new BigDecimal((BigInteger) value);
        } else {
            return BigDecimal.valueOf(value.longValue());
        }
    }

    // BigInteger
    if (targetType.equals(BigInteger.class)) {
        if (value instanceof BigDecimal) {
            return ((BigDecimal) value).toBigInteger();
        } else {
            return BigInteger.valueOf(value.longValue());
        }
    }

    String msg = toString(getClass()) + " cannot handle conversion to '" + toString(targetType) + "'";
    throw new ConversionException(msg);

}

From source file:org.metawidget.integrationtest.swing.allwidgets.SwingAllWidgetsTest.java

protected void runTest(AdvancedWidgetProcessor<JComponent, SwingMetawidget> processor) throws Exception {

    // Model/*from   w  w w .jav  a  2 s . c o  m*/

    AllWidgets allWidgets = new AllWidgets$$EnhancerByCGLIB$$1234();

    // App

    SwingMetawidget metawidget = new SwingMetawidget();
    metawidget.setConfig("org/metawidget/integrationtest/swing/allwidgets/metawidget.xml");
    metawidget.addWidgetProcessor(processor);
    metawidget.addWidgetProcessor(new ReflectionBindingProcessor());
    metawidget.setMetawidgetLayout(new SeparatorLayoutDecorator(new SeparatorLayoutDecoratorConfig().setLayout(
            new org.metawidget.swing.layout.GridBagLayout(new GridBagLayoutConfig().setNumberOfColumns(2)))));

    metawidget.setToInspect(allWidgets);

    metawidget.add(new Stub("mystery"));

    // Test missing components

    try {
        metawidget.getValue("no-such-component");
        fail();
    } catch (MetawidgetException e1) {
        assertEquals("No component named 'no-such-component'", e1.getMessage());

        try {
            metawidget.getValue("textbox", "no-such-component");
            fail();
        } catch (MetawidgetException e2) {
            assertEquals("No component named 'textbox', 'no-such-component'", e2.getMessage());

            try {
                metawidget.getValue("textbox", "no-such-component1", "no-such-component2");
                fail();
            } catch (MetawidgetException e3) {
                assertEquals(
                        "No such component 'no-such-component1' of 'textbox', 'no-such-component1', 'no-such-component2'",
                        e3.getMessage());
            }
        }
    }

    try {
        metawidget.setValue(null, "no-such-component");
        fail();
    } catch (MetawidgetException e1) {
        assertEquals("No component named 'no-such-component'", e1.getMessage());

        try {
            metawidget.setValue(null, "textbox", "no-such-component");
            fail();
        } catch (MetawidgetException e2) {
            assertEquals("No component named 'textbox', 'no-such-component'", e2.getMessage());

            try {
                metawidget.setValue(null, "textbox", "no-such-component1", "no-such-component2");
                fail();
            } catch (MetawidgetException e3) {
                assertEquals(
                        "No such component 'no-such-component1' of 'textbox', 'no-such-component1', 'no-such-component2'",
                        e3.getMessage());
            }
        }
    }

    // Check what created, and edit it

    assertEquals("Textbox*:", ((JLabel) metawidget.getComponent(0)).getText());
    assertTrue(metawidget.getComponent(1) instanceof JTextField);
    assertEquals("Textbox", metawidget.getValue("textbox"));
    ((JTextField) metawidget.getComponent(1)).setText("Textbox1");

    assertEquals("Limited Textbox:", ((JLabel) metawidget.getComponent(2)).getText());
    assertTrue(metawidget.getComponent(3) instanceof JTextField);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(3)).gridx);
    assertEquals("Limited Textbox", metawidget.getValue("limitedTextbox"));
    ((JTextField) metawidget.getComponent(3)).setText("Limited Textbox1");

    assertEquals("Textarea:", ((JLabel) metawidget.getComponent(4)).getText());
    assertTrue(metawidget.getComponent(5) instanceof JScrollPane);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(5)).gridx);
    assertEquals("Textarea", metawidget.getValue("textarea"));

    JTextArea textarea = (JTextArea) ((JScrollPane) metawidget.getComponent(5)).getViewport().getView();
    assertEquals(2, textarea.getRows());
    assertEquals(true, textarea.getLineWrap());
    assertEquals(true, textarea.getWrapStyleWord());
    textarea.setText("Textarea1");

    assertEquals("Password:", ((JLabel) metawidget.getComponent(6)).getText());
    assertTrue(metawidget.getComponent(7) instanceof JPasswordField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(7)).gridx);
    assertEquals("Password", metawidget.getValue("password"));
    ((JPasswordField) metawidget.getComponent(7)).setText("Password1");

    // Primitives

    assertEquals("Byte Primitive:", ((JLabel) metawidget.getComponent(8)).getText());
    assertTrue(metawidget.getComponent(9) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(9)).gridx);
    assertTrue(Byte.MAX_VALUE == (Byte) metawidget.getValue("bytePrimitive"));
    assertTrue(-5 == (Byte) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(9)).getModel())
            .getMinimum());
    assertTrue(
            Byte.MAX_VALUE == (Byte) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(9)).getModel())
                    .getMaximum());
    assertEquals(0, ((JSpinner.DefaultEditor) ((JSpinner) metawidget.getComponent(9)).getEditor())
            .getTextField().getColumns());
    JSpinner spinner = (JSpinner) metawidget.getComponent(9);
    spinner.setValue(spinner.getModel().getPreviousValue());

    assertEquals("Byte Object:", ((JLabel) metawidget.getComponent(10)).getText());
    assertTrue(metawidget.getComponent(11) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(11)).gridx);
    assertEquals(String.valueOf(Byte.MIN_VALUE), metawidget.getValue("byteObject"));
    ((JTextField) metawidget.getComponent(11)).setText(String.valueOf(Byte.MIN_VALUE + 1));

    assertEquals("Short Primitive:", ((JLabel) metawidget.getComponent(12)).getText());
    assertTrue(metawidget.getComponent(13) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(13)).gridx);
    assertTrue(Short.MAX_VALUE == (Short) metawidget.getValue("shortPrimitive"));
    assertTrue(-6 == (Short) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(13)).getModel())
            .getMinimum());
    assertTrue(Short.MAX_VALUE == (Short) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(13))
            .getModel()).getMaximum());
    spinner = (JSpinner) metawidget.getComponent(13);
    assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns());
    spinner.setValue(spinner.getModel().getPreviousValue());

    assertEquals("Short Object:", ((JLabel) metawidget.getComponent(14)).getText());
    assertTrue(metawidget.getComponent(15) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(15)).gridx);
    assertEquals(String.valueOf(Short.MIN_VALUE), metawidget.getValue("shortObject"));
    ((JTextField) metawidget.getComponent(15)).setText(String.valueOf(Short.MIN_VALUE + 1));

    assertEquals("Int Primitive:", ((JLabel) metawidget.getComponent(16)).getText());
    assertTrue(metawidget.getComponent(17) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(17)).gridx);
    assertTrue(Integer.MAX_VALUE == (Integer) metawidget.getValue("intPrimitive"));
    assertTrue(Integer.MIN_VALUE == (Integer) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(17))
            .getModel()).getMinimum());
    assertTrue(Integer.MAX_VALUE == (Integer) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(17))
            .getModel()).getMaximum());
    spinner = (JSpinner) metawidget.getComponent(17);
    assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns());
    spinner.setValue(spinner.getModel().getPreviousValue());

    assertEquals("Integer Object:", ((JLabel) metawidget.getComponent(18)).getText());
    assertTrue(metawidget.getComponent(19) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(19)).gridx);
    assertEquals(String.valueOf(Integer.MIN_VALUE), metawidget.getValue("integerObject"));
    ((JTextField) metawidget.getComponent(19)).setText(String.valueOf(Integer.MIN_VALUE + 1));

    assertEquals("Ranged Int:", ((JLabel) metawidget.getComponent(20)).getText());
    assertTrue(metawidget.getComponent(21) instanceof JSlider);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(21)).gridx);
    assertEquals(1, ((JSlider) metawidget.getComponent(21)).getMinimum());
    assertEquals(100, ((JSlider) metawidget.getComponent(21)).getMaximum());
    assertTrue(32 == (Integer) metawidget.getValue("rangedInt"));
    ((JSlider) metawidget.getComponent(21)).setValue(33);

    assertEquals("Ranged Integer:", ((JLabel) metawidget.getComponent(22)).getText());
    assertTrue(metawidget.getComponent(23) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(23)).gridx);
    assertEquals("33", metawidget.getValue("rangedInteger"));
    ((JTextField) metawidget.getComponent(23)).setText(String.valueOf(34));

    assertEquals("Long Primitive:", ((JLabel) metawidget.getComponent(24)).getText());
    assertTrue(metawidget.getComponent(25) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(25)).gridx);
    assertTrue(42 == (Long) metawidget.getValue("longPrimitive"));
    assertTrue(-7 == (Long) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(25)).getModel())
            .getMinimum());
    assertTrue(
            Long.MAX_VALUE == (Long) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(25)).getModel())
                    .getMaximum());
    spinner = (JSpinner) metawidget.getComponent(25);
    assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns());
    spinner.setValue(spinner.getModel().getNextValue());

    assertTrue(metawidget.getComponent(26) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(26)).gridx);
    assertEquals("43", metawidget.getValue("longObject"));
    ((JTextField) metawidget.getComponent(26)).setText("44");

    assertEquals("Float Primitive:", ((JLabel) metawidget.getComponent(27)).getText());
    assertTrue(metawidget.getComponent(28) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(28)).gridx);
    assertEquals(4.2f, metawidget.getValue("floatPrimitive"));
    assertEquals(-Float.MAX_VALUE,
            ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(28)).getModel()).getMinimum());
    assertTrue(2048 == (Float) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(28)).getModel())
            .getMaximum());
    spinner = (JSpinner) metawidget.getComponent(28);
    assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns());
    spinner.setValue(spinner.getModel().getNextValue());

    assertEquals("nullInBundle:", ((JLabel) metawidget.getComponent(29)).getText());
    assertTrue(metawidget.getComponent(30) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(30)).gridx);
    assertEquals("4.3", metawidget.getValue("floatObject"));
    ((JTextField) metawidget.getComponent(30)).setText("5.4");

    assertEquals("Double Primitive:", ((JLabel) metawidget.getComponent(31)).getText());
    assertTrue(metawidget.getComponent(32) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(32)).gridx);
    assertEquals(42.2d, metawidget.getValue("doublePrimitive"));
    assertTrue(-8 == (Double) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(32)).getModel())
            .getMinimum());
    assertEquals(Double.MAX_VALUE,
            ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(32)).getModel()).getMaximum());
    spinner = (JSpinner) metawidget.getComponent(32);
    assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns());
    spinner.setValue(spinner.getModel().getNextValue());

    assertTrue(metawidget.getComponent(33) instanceof JTextField);
    assertEquals(0, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(33)).gridx);
    assertEquals(2,
            ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(33)).gridwidth);
    assertEquals("43.3", metawidget.getValue("doubleObject"));
    ((JTextField) metawidget.getComponent(33)).setText("54.4");

    assertEquals("Char Primitive:", ((JLabel) metawidget.getComponent(34)).getText());
    assertTrue(metawidget.getComponent(35) instanceof JTextField);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(35)).gridx);
    assertEquals("A", metawidget.getValue("charPrimitive"));
    ((JTextField) metawidget.getComponent(35)).setText("Z");

    assertEquals("Character Object:", ((JLabel) metawidget.getComponent(36)).getText());
    assertTrue(metawidget.getComponent(37) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(37)).gridx);
    assertEquals("Z", metawidget.getValue("characterObject"));
    ((JTextField) metawidget.getComponent(37)).setText("A");

    assertEquals("Boolean Primitive:", ((JLabel) metawidget.getComponent(38)).getText());
    assertTrue(metawidget.getComponent(39) instanceof JCheckBox);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(39)).gridx);
    assertTrue(false == (Boolean) metawidget.getValue("booleanPrimitive"));
    ((JCheckBox) metawidget.getComponent(39)).setSelected(true);

    assertEquals("Boolean Object:", ((JLabel) metawidget.getComponent(40)).getText());
    assertTrue(metawidget.getComponent(41) instanceof JComboBox);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(37)).gridx);
    assertEquals(3, ((JComboBox) metawidget.getComponent(41)).getItemCount());
    assertEquals(Boolean.TRUE, metawidget.getValue("booleanObject"));
    ((JComboBox) metawidget.getComponent(41)).setSelectedItem(Boolean.FALSE);

    assertEquals("Dropdown:", ((JLabel) metawidget.getComponent(42)).getText());
    assertTrue(metawidget.getComponent(43) instanceof JComboBox);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(43)).gridx);
    assertEquals(4, ((JComboBox) metawidget.getComponent(43)).getItemCount());
    assertEquals("dropdown1", metawidget.getValue("dropdown"));
    ((JComboBox) metawidget.getComponent(43)).setSelectedItem("foo1");

    assertEquals("Dropdown With Labels:", ((JLabel) metawidget.getComponent(44)).getText());
    assertTrue(metawidget.getComponent(45) instanceof JComboBox);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(45)).gridx);

    JComboBox combo = (JComboBox) metawidget.getComponent(45);
    assertEquals(5, combo.getItemCount());
    assertEquals("Foo #2",
            ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "foo2", 1, false, false))
                    .getText());
    assertEquals("Dropdown #2", ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(),
            "dropdown2", 1, false, false)).getText());
    assertEquals("Bar #2",
            ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "bar2", 1, false, false))
                    .getText());
    assertEquals("Baz #2",
            ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "baz2", 1, false, false))
                    .getText());
    assertEquals("dropdown2", metawidget.getValue("dropdownWithLabels"));
    ((JComboBox) metawidget.getComponent(45)).setSelectedItem("bar2");

    assertEquals("Not Null Dropdown:", ((JLabel) metawidget.getComponent(46)).getText());
    assertTrue(metawidget.getComponent(47) instanceof JComboBox);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(47)).gridx);
    assertEquals(3, ((JComboBox) metawidget.getComponent(47)).getItemCount());
    assertTrue(0 == (Byte) metawidget.getValue("notNullDropdown"));
    ((JComboBox) metawidget.getComponent(47)).setSelectedItem((byte) 1);

    assertEquals("Not Null Object Dropdown*:", ((JLabel) metawidget.getComponent(48)).getText());
    assertTrue(metawidget.getComponent(49) instanceof JComboBox);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(49)).gridx);
    assertEquals(6, ((JComboBox) metawidget.getComponent(49)).getItemCount());
    assertEquals("dropdown3", metawidget.getValue("notNullObjectDropdown"));
    ((JComboBox) metawidget.getComponent(49)).setSelectedIndex(0);

    assertEquals("Nested Widgets:", ((JLabel) metawidget.getComponent(50)).getText());
    assertTrue(metawidget.getComponent(51) instanceof SwingMetawidget);

    SwingMetawidget metawidgetNested = (SwingMetawidget) metawidget.getComponent(51);

    assertEquals("Further Nested Widgets:", ((JLabel) metawidgetNested.getComponent(0)).getText());
    assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout())
            .getConstraints(metawidgetNested.getComponent(1)).gridx);

    SwingMetawidget metawidgetFurtherNested = (SwingMetawidget) metawidgetNested.getComponent(1);
    assertEquals("Further Nested Widgets:", ((JLabel) metawidgetFurtherNested.getComponent(0)).getText());
    assertTrue(metawidgetFurtherNested.getComponent(1) instanceof SwingMetawidget);
    assertEquals(((SwingMetawidget) metawidgetFurtherNested.getComponent(1)).getComponentCount(), 0);

    assertEquals("Nested Textbox 1:", ((JLabel) metawidgetFurtherNested.getComponent(2)).getText());
    assertTrue(metawidgetFurtherNested.getComponent(3) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidgetFurtherNested.getLayout())
            .getConstraints(metawidgetFurtherNested.getComponent(3)).gridx);
    assertEquals("Nested Textbox 1",
            metawidget.getValue("nestedWidgets", "furtherNestedWidgets", "nestedTextbox1"));
    ((JTextField) metawidgetFurtherNested.getComponent(3)).setText("Nested Textbox 1.1 (further)");

    assertEquals("Nested Textbox 2:", ((JLabel) metawidgetFurtherNested.getComponent(4)).getText());
    assertTrue(metawidgetFurtherNested.getComponent(5) instanceof JTextField);

    // (should be 1, as in next row, if getEffectiveNumberOfColumns is working)

    assertEquals(1, ((GridBagLayout) metawidgetFurtherNested.getLayout())
            .getConstraints(metawidgetFurtherNested.getComponent(5)).gridx);
    assertEquals("Nested Textbox 2",
            metawidget.getValue("nestedWidgets", "furtherNestedWidgets", "nestedTextbox2"));
    ((JTextField) metawidgetFurtherNested.getComponent(5)).setText("Nested Textbox 2.2 (further)");

    assertEquals("Nested Textbox 1:", ((JLabel) metawidgetNested.getComponent(2)).getText());
    assertTrue(metawidgetNested.getComponent(3) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout())
            .getConstraints(metawidgetNested.getComponent(3)).gridx);
    assertEquals("Nested Textbox 1", metawidget.getValue("nestedWidgets", "nestedTextbox1"));
    ((JTextField) metawidgetNested.getComponent(3)).setText("Nested Textbox 1.1");

    assertEquals("Nested Textbox 2:", ((JLabel) metawidgetNested.getComponent(4)).getText());
    assertTrue(metawidgetNested.getComponent(5) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout())
            .getConstraints(metawidgetNested.getComponent(5)).gridx);
    assertEquals("Nested Textbox 2", metawidget.getValue("nestedWidgets", "nestedTextbox2"));
    ((JTextField) metawidgetNested.getComponent(5)).setText("Nested Textbox 2.2");

    assertEquals("Read Only Nested Widgets:", ((JLabel) metawidget.getComponent(52)).getText());
    assertTrue(metawidget.getComponent(53) instanceof SwingMetawidget);

    metawidgetNested = (SwingMetawidget) metawidget.getComponent(53);
    assertEquals("Nested Textbox 1:", ((JLabel) metawidgetNested.getComponent(2)).getText());
    assertTrue(metawidgetNested.getComponent(3) instanceof JLabel);
    assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout())
            .getConstraints(metawidgetNested.getComponent(3)).gridx);
    assertEquals("Nested Textbox 1", metawidget.getValue("readOnlyNestedWidgets", "nestedTextbox1"));

    assertEquals("Nested Textbox 2:", ((JLabel) metawidgetNested.getComponent(4)).getText());
    assertTrue(metawidgetNested.getComponent(5) instanceof JLabel);
    assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout())
            .getConstraints(metawidgetNested.getComponent(5)).gridx);
    assertEquals("Nested Textbox 2", metawidget.getValue("readOnlyNestedWidgets", "nestedTextbox2"));

    assertEquals("Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(54)).getText());
    assertEquals("Nested Textbox 1, Nested Textbox 2", ((JTextField) metawidget.getComponent(55)).getText());
    ((JTextField) metawidget.getComponent(55)).setText("Nested Textbox 1.01, Nested Textbox 2.02");

    assertEquals("Read Only Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(56)).getText());
    assertEquals("Nested Textbox 1, Nested Textbox 2", ((JLabel) metawidget.getComponent(57)).getText());

    assertEquals("Date:", ((JLabel) metawidget.getComponent(58)).getText());
    assertTrue(metawidget.getComponent(59) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(59)).gridx);

    DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
    assertEquals(dateFormat.format(allWidgets.getDate()), metawidget.getValue("date"));
    ((JTextField) metawidget.getComponent(59)).setText("bad date");

    JPanel separatorPanel = (JPanel) metawidget.getComponent(60);
    assertEquals("Section Break", ((JLabel) separatorPanel.getComponent(0)).getText());
    assertEquals(GridBagConstraints.REMAINDER,
            ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(60)).gridwidth);
    assertTrue(separatorPanel.getComponent(1) instanceof JSeparator);

    assertEquals("Read Only:", ((JLabel) metawidget.getComponent(61)).getText());
    assertTrue(metawidget.getComponent(62) instanceof JLabel);
    assertEquals("Read Only", metawidget.getValue("readOnly"));

    assertTrue(metawidget.getComponent(63) instanceof JButton);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(63)).gridx);
    assertEquals(GridBagConstraints.NONE,
            ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(63)).fill);
    JButton button = ((JButton) metawidget.getComponent(63));
    assertEquals("Do Action", button.getText());
    assertTrue(button.isEnabled());
    try {
        button.doClick();
        fail();
    } catch (Exception e) {
        assertEquals("doAction called", e.getCause().getCause().getMessage());
    }

    assertEquals(64, metawidget.getComponentCount());

    // Check painting

    JFrame frame = new JFrame();
    metawidget.paint(frame.getGraphics());

    // Check MetawidgetException

    try {
        processor.getClass().getMethod("save", SwingMetawidget.class).invoke(processor, metawidget);
        fail();
    } catch (Exception e) {
        assertEquals("Could not parse 'bad date'", e.getCause().getCause().getMessage());
    }

    // Check saving

    String now = dateFormat.format(new GregorianCalendar().getTime());
    ((JTextField) metawidget.getComponent(59)).setText(now);
    processor.getClass().getMethod("save", SwingMetawidget.class).invoke(processor, metawidget);

    // Check read-only

    metawidget.setReadOnly(true);

    assertEquals("Textbox:", ((JLabel) metawidget.getComponent(0)).getText());
    assertEquals("Textbox1", ((JLabel) metawidget.getComponent(1)).getText());
    assertEquals("Limited Textbox:", ((JLabel) metawidget.getComponent(2)).getText());
    assertEquals("Limited Textbox1", ((JLabel) metawidget.getComponent(3)).getText());
    assertEquals("Textarea:", ((JLabel) metawidget.getComponent(4)).getText());
    assertEquals("Textarea1",
            ((JTextArea) ((JScrollPane) metawidget.getComponent(5)).getViewport().getView()).getText());
    assertEquals("Password:", ((JLabel) metawidget.getComponent(6)).getText());
    assertTrue(metawidget.getComponent(7) instanceof JPanel);
    assertEquals("Byte Primitive:", ((JLabel) metawidget.getComponent(8)).getText());
    assertEquals("126", ((JLabel) metawidget.getComponent(9)).getText());
    assertEquals("Byte Object:", ((JLabel) metawidget.getComponent(10)).getText());
    assertEquals("-127", ((JLabel) metawidget.getComponent(11)).getText());
    assertEquals("Short Primitive:", ((JLabel) metawidget.getComponent(12)).getText());
    assertEquals("32766", ((JLabel) metawidget.getComponent(13)).getText());
    assertEquals("Short Object:", ((JLabel) metawidget.getComponent(14)).getText());
    assertEquals("-32767", ((JLabel) metawidget.getComponent(15)).getText());
    assertEquals("Int Primitive:", ((JLabel) metawidget.getComponent(16)).getText());
    assertEquals("2147483646", ((JLabel) metawidget.getComponent(17)).getText());
    assertEquals("Integer Object:", ((JLabel) metawidget.getComponent(18)).getText());
    assertEquals("-2147483647", ((JLabel) metawidget.getComponent(19)).getText());
    assertEquals("Ranged Int:", ((JLabel) metawidget.getComponent(20)).getText());
    assertEquals("33", ((JLabel) metawidget.getComponent(21)).getText());
    assertEquals("Ranged Integer:", ((JLabel) metawidget.getComponent(22)).getText());
    assertEquals("34", ((JLabel) metawidget.getComponent(23)).getText());
    assertEquals("Long Primitive:", ((JLabel) metawidget.getComponent(24)).getText());
    assertEquals("43", ((JLabel) metawidget.getComponent(25)).getText());
    assertEquals("44", ((JLabel) metawidget.getComponent(26)).getText());
    assertEquals("Float Primitive:", ((JLabel) metawidget.getComponent(27)).getText());
    assertTrue(((JLabel) metawidget.getComponent(28)).getText().startsWith("4.3")
            || ((JLabel) metawidget.getComponent(28)).getText().startsWith("4.299"));
    assertEquals("nullInBundle:", ((JLabel) metawidget.getComponent(29)).getText());
    assertEquals("5.4", ((JLabel) metawidget.getComponent(30)).getText());
    assertEquals("Double Primitive:", ((JLabel) metawidget.getComponent(31)).getText());
    assertTrue(((JLabel) metawidget.getComponent(32)).getText().startsWith("42.3")
            || ((JLabel) metawidget.getComponent(32)).getText().startsWith("42.299"));
    assertEquals("54.4", ((JLabel) metawidget.getComponent(33)).getText());
    assertEquals("Char Primitive:", ((JLabel) metawidget.getComponent(34)).getText());
    assertEquals("Z", ((JLabel) metawidget.getComponent(35)).getText());
    assertEquals("Character Object:", ((JLabel) metawidget.getComponent(36)).getText());
    assertEquals("A", ((JLabel) metawidget.getComponent(37)).getText());
    assertEquals("Boolean Primitive:", ((JLabel) metawidget.getComponent(38)).getText());
    assertEquals("true", ((JLabel) metawidget.getComponent(39)).getText());
    assertEquals("Boolean Object:", ((JLabel) metawidget.getComponent(40)).getText());
    assertEquals("No", ((JLabel) metawidget.getComponent(41)).getText());
    assertEquals("Dropdown:", ((JLabel) metawidget.getComponent(42)).getText());
    assertEquals("foo1", ((JLabel) metawidget.getComponent(43)).getText());
    assertEquals("Dropdown With Labels:", ((JLabel) metawidget.getComponent(44)).getText());
    assertEquals("Bar #2", ((JLabel) metawidget.getComponent(45)).getText());
    assertEquals("Not Null Dropdown:", ((JLabel) metawidget.getComponent(46)).getText());
    assertEquals("1", ((JLabel) metawidget.getComponent(47)).getText());
    assertEquals("Not Null Object Dropdown:", ((JLabel) metawidget.getComponent(48)).getText());
    assertEquals("foo3", ((JLabel) metawidget.getComponent(49)).getText());
    assertEquals("Nested Widgets:", ((JLabel) metawidget.getComponent(50)).getText());
    assertEquals("Further Nested Widgets:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(0)).getText());
    assertEquals("Further Nested Widgets:",
            ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1))
                    .getComponent(0)).getText());
    assertEquals("Nested Textbox 1:",
            ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1))
                    .getComponent(2)).getText());
    assertEquals("Nested Textbox 1.1 (further)",
            ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1))
                    .getComponent(3)).getText());
    assertEquals("Nested Textbox 2:",
            ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1))
                    .getComponent(4)).getText());
    assertEquals("Nested Textbox 2.2 (further)",
            ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1))
                    .getComponent(5)).getText());
    assertEquals("Nested Textbox 1:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(2)).getText());
    assertEquals("Nested Textbox 1.1",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(3)).getText());
    assertEquals("Nested Textbox 2:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(4)).getText());
    assertEquals("Nested Textbox 2.2",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(5)).getText());
    assertEquals("Read Only Nested Widgets:", ((JLabel) metawidget.getComponent(52)).getText());
    assertEquals("Further Nested Widgets:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(0)).getText());
    assertEquals("Nested Textbox 1:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(2)).getText());
    assertEquals("Nested Textbox 1",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(3)).getText());
    assertEquals("Nested Textbox 2:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(4)).getText());
    assertEquals("Nested Textbox 2",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(5)).getText());
    assertEquals("Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(54)).getText());
    assertEquals("Nested Textbox 1.01, Nested Textbox 2.02", ((JLabel) metawidget.getComponent(55)).getText());
    assertEquals("Read Only Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(56)).getText());
    assertEquals("Nested Textbox 1, Nested Textbox 2", ((JLabel) metawidget.getComponent(57)).getText());
    assertEquals("Date:", ((JLabel) metawidget.getComponent(58)).getText());
    assertEquals(now, ((JLabel) metawidget.getComponent(59)).getText());
    assertEquals("Section Break", ((JLabel) ((JPanel) metawidget.getComponent(60)).getComponent(0)).getText());
    assertEquals("Read Only:", ((JLabel) metawidget.getComponent(61)).getText());
    assertEquals("Read Only", ((JLabel) metawidget.getComponent(62)).getText());
    assertEquals("Do Action", ((JButton) metawidget.getComponent(63)).getText());
    assertTrue(!((JButton) metawidget.getComponent(63)).isEnabled());

    assertEquals(metawidget.getComponentCount(), 64);

    // Test Binding.onStartBuild clears the state

    assertTrue(null != metawidget.getClientProperty(processor.getClass()));
    processor.onStartBuild(metawidget);
    assertEquals(null, metawidget.getClientProperty(processor.getClass()));
}

From source file:javadz.beanutils.converters.NumberConverter.java

/**
 * Convert any Number object to the specified type for this
 * <i>Converter</i>.//ww w . j ava  2s  . co m
 * <p>
 * This method handles conversion to the following types:
 * <ul>
 *     <li><code>java.lang.Byte</code></li>
 *     <li><code>java.lang.Short</code></li>
 *     <li><code>java.lang.Integer</code></li>
 *     <li><code>java.lang.Long</code></li>
 *     <li><code>java.lang.Float</code></li>
 *     <li><code>java.lang.Double</code></li>
 *     <li><code>java.math.BigDecimal</code></li>
 *     <li><code>java.math.BigInteger</code></li>
 * </ul>
 * @param sourceType The type being converted from
 * @param targetType The Number type to convert to
 * @param value The Number to convert.
 *
 * @return The converted value.
 */
private Number toNumber(Class sourceType, Class targetType, Number value) {

    // Correct Number type already
    if (targetType.equals(value.getClass())) {
        return value;
    }

    // Byte
    if (targetType.equals(Byte.class)) {
        long longValue = value.longValue();
        if (longValue > Byte.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        if (longValue < Byte.MIN_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too small " + toString(targetType));
        }
        return new Byte(value.byteValue());
    }

    // Short
    if (targetType.equals(Short.class)) {
        long longValue = value.longValue();
        if (longValue > Short.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        if (longValue < Short.MIN_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too small " + toString(targetType));
        }
        return new Short(value.shortValue());
    }

    // Integer
    if (targetType.equals(Integer.class)) {
        long longValue = value.longValue();
        if (longValue > Integer.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        if (longValue < Integer.MIN_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too small " + toString(targetType));
        }
        return new Integer(value.intValue());
    }

    // Long
    if (targetType.equals(Long.class)) {
        return new Long(value.longValue());
    }

    // Float
    if (targetType.equals(Float.class)) {
        if (value.doubleValue() > Float.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        return new Float(value.floatValue());
    }

    // Double
    if (targetType.equals(Double.class)) {
        return new Double(value.doubleValue());
    }

    // BigDecimal
    if (targetType.equals(BigDecimal.class)) {
        if (value instanceof Float || value instanceof Double) {
            return new BigDecimal(value.toString());
        } else if (value instanceof BigInteger) {
            return new BigDecimal((BigInteger) value);
        } else {
            return BigDecimal.valueOf(value.longValue());
        }
    }

    // BigInteger
    if (targetType.equals(BigInteger.class)) {
        if (value instanceof BigDecimal) {
            return ((BigDecimal) value).toBigInteger();
        } else {
            return BigInteger.valueOf(value.longValue());
        }
    }

    String msg = toString(getClass()) + " cannot handle conversion to '" + toString(targetType) + "'";
    if (log().isWarnEnabled()) {
        log().warn("    " + msg);
    }
    throw new ConversionException(msg);

}

From source file:org.apache.fop.afp.ptoca.PtocaBuilder.java

/**
 * Sets the intercharacter adjustment (additional increment or decrement between graphic
 * characters).//from  ww w  .  j  av a2  s .  co m
 * <p>
 * This is a modal control sequence.
 *
 * @param incr The increment to be set (1/1440 inch)
 * @throws IOException if an I/O error occurs
 */
public void setInterCharacterAdjustment(int incr) throws IOException {
    if (incr == this.currentInterCharacterAdjustment) {
        return;
    }
    assert incr >= Short.MIN_VALUE && incr <= Short.MAX_VALUE;
    newControlSequence();
    writeShort(Math.abs(incr)); //Increment
    writeBytes(incr >= 0 ? 0 : 1); // Direction
    commit(chained(SIA));

    this.currentInterCharacterAdjustment = incr;
}

From source file:org.lwes.db.EventTemplateDB.java

/**
 * This method checks the type and range of a default value (from the ESF).
 * It returns the desired form, if allowed.
 *
 * @param type     which controls the desired object type of the value
 * @param esfValue which should be converted to fit 'type'
 * @return a value suitable for storing in a BaseType of this 'type'
 * @throws EventSystemException if the value is not acceptable for the type.
 *//*from w w  w.j  av  a2  s.  c  om*/
@SuppressWarnings("cast")
private Object canonicalizeDefaultValue(String eventName, String attributeName, FieldType type, Object esfValue)
        throws EventSystemException {
    try {
        switch (type) {
        case BOOLEAN:
            return (Boolean) esfValue;
        case BYTE:
            checkRange(eventName, attributeName, esfValue, Byte.MIN_VALUE, Byte.MAX_VALUE);
            return ((Number) esfValue).byteValue();
        case INT16:
            checkRange(eventName, attributeName, esfValue, Short.MIN_VALUE, Short.MAX_VALUE);
            return ((Number) esfValue).shortValue();
        case INT32:
            checkRange(eventName, attributeName, esfValue, Integer.MIN_VALUE, Integer.MAX_VALUE);
            return ((Number) esfValue).intValue();
        case UINT16:
            checkRange(eventName, attributeName, esfValue, 0, 0x10000);
            return ((Number) esfValue).intValue() & 0xffff;
        case UINT32:
            checkRange(eventName, attributeName, esfValue, 0, 0x100000000L);
            return ((Number) esfValue).longValue() & 0xffffffff;
        case FLOAT:
            return ((Number) esfValue).floatValue();
        case DOUBLE:
            return ((Number) esfValue).doubleValue();
        case STRING:
            return ((String) esfValue);
        case INT64: {
            if (esfValue instanceof Long) {
                return esfValue;
            }
            final BigInteger bi = (BigInteger) esfValue;
            if (bi.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0
                    || bi.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
                throw new EventSystemException(
                        String.format("Field %s.%s value %s outside allowed range [%d,%d]", eventName,
                                attributeName, esfValue, Long.MIN_VALUE, Long.MAX_VALUE));
            }
            return bi.longValue();
        }
        case UINT64: {
            if (esfValue instanceof BigInteger) {
                return esfValue;
            }
            return BigInteger.valueOf(((Number) esfValue).longValue());
        }
        case IPADDR:
            return ((IPAddress) esfValue);
        case BOOLEAN_ARRAY:
        case BYTE_ARRAY:
        case DOUBLE_ARRAY:
        case FLOAT_ARRAY:
        case INT16_ARRAY:
        case INT32_ARRAY:
        case INT64_ARRAY:
        case IP_ADDR_ARRAY:
        case STRING_ARRAY:
        case UINT16_ARRAY:
        case UINT32_ARRAY:
        case UINT64_ARRAY:
        case NBOOLEAN_ARRAY:
        case NBYTE_ARRAY:
        case NDOUBLE_ARRAY:
        case NFLOAT_ARRAY:
        case NINT16_ARRAY:
        case NINT32_ARRAY:
        case NINT64_ARRAY:
        case NSTRING_ARRAY:
        case NUINT16_ARRAY:
        case NUINT32_ARRAY:
        case NUINT64_ARRAY:
            throw new EventSystemException("Unsupported default value type " + type);
        }
        throw new EventSystemException("Unrecognized type " + type + " for value " + esfValue);
    } catch (ClassCastException e) {
        throw new EventSystemException("Type " + type + " had an inappropriate default value " + esfValue);
    }
}

From source file:com.jcwhatever.nucleus.internal.managed.commands.Arguments.java

@Override
public short getShort(String parameterName) throws InvalidArgumentException {
    return getShort(parameterName, Short.MIN_VALUE, Short.MAX_VALUE);
}