Example usage for java.lang Boolean TYPE

List of usage examples for java.lang Boolean TYPE

Introduction

In this page you can find the example usage for java.lang Boolean TYPE.

Prototype

Class TYPE

To view the source code for java.lang Boolean TYPE.

Click Source Link

Document

The Class object representing the primitive type boolean.

Usage

From source file:com.streamsets.datacollector.execution.preview.sync.SyncPreviewer.java

private static Object getValueFromParam(Field field, String stringValue) {
    Class<?> type = field.getType();
    if (String.class.isAssignableFrom(type)) {
        return stringValue;
    } else if (Integer.class.isAssignableFrom(type) || Integer.TYPE == type) {
        return Integer.parseInt(stringValue);
    } else if (Long.class.isAssignableFrom(type) || Long.TYPE == type) {
        return Long.parseLong(stringValue);
    } else if (Boolean.class.isAssignableFrom(type) || Boolean.TYPE == type) {
        return Boolean.parseBoolean(stringValue);
    }//www  .ja v  a2  s .c  o m
    return null;
}

From source file:net.sourceforge.vulcan.web.struts.forms.PluginConfigForm.java

private boolean isBoolean(Class<?> c) {
    return Boolean.class.equals(c) || Boolean.TYPE.equals(c);
}

From source file:org.apache.jackrabbit.core.persistence.db.OraclePersistenceManager.java

/**
 * Creates a temporary oracle.sql.BLOB instance via reflection and spools
 * the contents of the specified stream.
 *//*from www  .  j  a v a 2  s .  c  om*/
protected Blob createTemporaryBlob(InputStream in) throws Exception {
    /*
    BLOB blob = BLOB.createTemporary(con, false, BLOB.DURATION_SESSION);
    blob.open(BLOB.MODE_READWRITE);
    OutputStream out = blob.getBinaryOutputStream();
    ...
    out.flush();
    out.close();
    blob.close();
    return blob;
    */
    Method createTemporary = blobClass.getMethod("createTemporary",
            new Class[] { Connection.class, Boolean.TYPE, Integer.TYPE });
    Object blob = createTemporary.invoke(null,
            new Object[] { ConnectionFactory.unwrap(con), Boolean.FALSE, durationSessionConstant });
    Method open = blobClass.getMethod("open", new Class[] { Integer.TYPE });
    open.invoke(blob, new Object[] { modeReadWriteConstant });
    Method getBinaryOutputStream = blobClass.getMethod("getBinaryOutputStream", new Class[0]);
    OutputStream out = (OutputStream) getBinaryOutputStream.invoke(blob);
    try {
        IOUtils.copy(in, out);
    } finally {
        try {
            out.flush();
        } catch (IOException ioe) {
        }
        out.close();
    }
    Method close = blobClass.getMethod("close", new Class[0]);
    close.invoke(blob);
    return (Blob) blob;
}

From source file:net.sf.jrf.domain.PersistentObjectDynaProperty.java

/** Gets default value.
 * @return default value.//from  ww  w. j a  v a 2 s. c om
 */
public Object getDefaultValue() {
    if (defaultValue != null)
        return this.defaultValue;
    Class cls = getType();
    if (primitiveWrapperClass != null) {
        if (cls.equals(Boolean.TYPE))
            return new Boolean(false);
        else if (cls.equals(Byte.TYPE))
            return new Byte((byte) 0);
        else if (cls.equals(Character.TYPE))
            return new Character((char) 0);
        else if (cls.equals(Double.TYPE))
            return new Double((double) 0);
        else if (cls.equals(Float.TYPE))
            return new Float((float) 0);
        else if (cls.equals(Integer.TYPE))
            return new Integer((int) 0);
        else if (cls.equals(Long.TYPE))
            return new Long((long) 0);
        else if (cls.equals(Short.TYPE))
            return new Short((short) 0);
        else
            return null;
    } else
        return null;
}

From source file:ca.sqlpower.matchmaker.MatchMakerTestCase.java

/**
 * Returns a new value that is not equal to oldVal. If oldVal is immutable, the
 * returned object will be a new instance compatible with oldVal.  If oldVal is 
 * mutable, it will be modified in some way so it is no longer equal to its original
 * value. {@link #getNewDifferentValue(MatchMakerObject, PropertyDescriptor, Object)}
 * is a similar method that does not take mutability into account and always returns 
 * a new value.//from  www  .  jav  a 2 s. com
 * 
 * @param mmo The object to which the property belongs.  You might need this
 *  if you have a special case for certain types of objects.
 * @param property The property that should be modified.  It belongs to mmo.
 * @param oldVal The existing value of the property to modify.  The returned value
 * will not equal this one at the time this method was first called, although it may
 * be the same instance as this one, but modified in some way.
 */
private Object modifyObject(MatchMakerObject mmo, PropertyDescriptor property, Object oldVal)
        throws IOException {
    if (property.getPropertyType() == Integer.TYPE || property.getPropertyType() == Integer.class) {
        return ((Integer) oldVal) + 1;
    } else if (property.getPropertyType() == Short.TYPE || property.getPropertyType() == Short.class) {
        return ((Short) oldVal) + 1;
    } else if (property.getPropertyType() == String.class) {
        if (oldVal == null) {
            return "new";
        } else {
            return "new " + oldVal;
        }
    } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) {
        return new Boolean(!((Boolean) oldVal).booleanValue());
    } else if (property.getPropertyType() == Long.class) {
        return new Long(((Long) oldVal).longValue() + 1L);
    } else if (property.getPropertyType() == BigDecimal.class) {
        return new BigDecimal(((BigDecimal) oldVal).longValue() + 1L);
    } else if (property.getPropertyType() == MungeSettings.class) {
        Integer processCount = ((MatchMakerSettings) oldVal).getProcessCount();
        processCount = new Integer((processCount == null) ? new Integer(0) : processCount + 1);
        ((MatchMakerSettings) oldVal).setProcessCount(processCount);
        return oldVal;
    } else if (property.getPropertyType() == MergeSettings.class) {
        Integer processCount = ((MatchMakerSettings) oldVal).getProcessCount();
        processCount = new Integer((processCount == null) ? new Integer(0) : processCount + 1);
        ((MatchMakerSettings) oldVal).setProcessCount(processCount);
        return oldVal;
    } else if (property.getPropertyType() == SQLTable.class) {
        ((SQLTable) oldVal).setRemarks("Testing Remarks");
        return oldVal;
    } else if (property.getPropertyType() == ViewSpec.class) {
        ((ViewSpec) oldVal).setName("Testing New Name");
        return oldVal;
    } else if (property.getPropertyType() == File.class) {
        oldVal = File.createTempFile("mmTest2", ".tmp");
        ((File) oldVal).deleteOnExit();
        return oldVal;
    } else if (property.getPropertyType() == ProjectMode.class) {
        if (oldVal == ProjectMode.BUILD_XREF) {
            return ProjectMode.FIND_DUPES;
        } else {
            return ProjectMode.BUILD_XREF;
        }
    } else if (property.getPropertyType() == MergeActionType.class) {
        if (oldVal == MergeActionType.AUGMENT) {
            return MergeActionType.SUM;
        } else {
            return MergeActionType.AUGMENT;
        }
    } else if (property.getPropertyType() == MatchMakerObject.class) {
        ((MatchMakerObject) oldVal).setName("Testing New Name");
        return oldVal;
    } else if (property.getPropertyType() == MatchMakerTranslateGroup.class) {
        ((MatchMakerObject) oldVal).setName("Testing New Name2");
        return oldVal;
    } else if (property.getPropertyType() == SQLColumn.class) {
        ((SQLColumn) oldVal).setRemarks("Testing Remarks");
        return oldVal;
    } else if (property.getPropertyType() == Date.class) {
        ((Date) oldVal).setTime(((Date) oldVal).getTime() + 10000);
        return oldVal;
    } else if (property.getPropertyType() == List.class) {
        if (property.getName().equals("children")) {
            if (mmo instanceof TableMergeRules) {
                ((List) oldVal).add(new ColumnMergeRules());
            } else {
                ((List) oldVal).add(new StubMatchMakerObject());
            }
        } else {
            ((List) oldVal).add("Test");
        }
        return oldVal;
    } else if (property.getPropertyType() == SQLIndex.class) {
        ((SQLIndex) oldVal).setName("modified index");
        return oldVal;
    } else if (property.getPropertyType() == Color.class) {
        if (oldVal == null) {
            return new Color(0xFAC157);
        } else {
            Color oldColor = (Color) oldVal;
            return new Color((oldColor.getRGB() + 0xF00) % 0x1000000);
        }
    } else if (property.getPropertyType() == ChildMergeActionType.class) {
        if (oldVal != null && oldVal.equals(ChildMergeActionType.DELETE_ALL_DUP_CHILD)) {
            return ChildMergeActionType.UPDATE_DELETE_ON_CONFLICT;
        } else {
            return ChildMergeActionType.DELETE_ALL_DUP_CHILD;
        }
    } else if (property.getPropertyType() == TableMergeRules.class) {
        if (oldVal == null) {
            return mmo;
        } else {
            return null;
        }
    } else if (property.getPropertyType() == PoolFilterSetting.class) {
        if (oldVal != PoolFilterSetting.EVERYTHING) {
            return PoolFilterSetting.EVERYTHING;
        } else {
            return PoolFilterSetting.INVALID_ONLY;
        }
    } else if (property.getPropertyType() == AutoValidateSetting.class) {
        if (oldVal != AutoValidateSetting.NOTHING) {
            return AutoValidateSetting.NOTHING;
        } else {
            return AutoValidateSetting.SERP_CORRECTABLE;
        }
    } else if (property.getPropertyType() == TableIndex.class) {
        CachableTable cachableTable = new CachableTable("newValue");
        TableIndex tableIndex = new TableIndex(cachableTable, "newValueIndex");
        if (tableIndex.getTableIndex() == null) {
            tableIndex.setTableIndex(new SQLIndex());
        } else {
            tableIndex.setTableIndex(null);
        }
        return tableIndex;
    } else if (property.getPropertyType() == CachableTable.class) {
        CachableTable cachableTable = new CachableTable("newValue");
        return cachableTable;
    } else {
        throw new RuntimeException("This test case lacks the ability to modify values for " + property.getName()
                + " (type " + property.getPropertyType().getName() + ")");
    }
}

From source file:com.netflix.governator.lifecycle.LifecycleManager.java

private void assignConfiguration(Object obj, Field field) throws Exception {
    Configuration configuration = field.getAnnotation(Configuration.class);
    String configurationName = configuration.value();
    ConfigurationKey key = new ConfigurationKey(configurationName, KeyParser.parse(configurationName));

    Object value = null;//from w w  w.  ja  va 2s. c  o m

    boolean has = configurationProvider.has(key);
    if (has) {
        try {
            if (String.class.isAssignableFrom(field.getType())) {
                value = configurationProvider.getString(key);
            } else if (Boolean.class.isAssignableFrom(field.getType())
                    || Boolean.TYPE.isAssignableFrom(field.getType())) {
                value = configurationProvider.getBoolean(key);
            } else if (Integer.class.isAssignableFrom(field.getType())
                    || Integer.TYPE.isAssignableFrom(field.getType())) {
                value = configurationProvider.getInteger(key);
            } else if (Long.class.isAssignableFrom(field.getType())
                    || Long.TYPE.isAssignableFrom(field.getType())) {
                value = configurationProvider.getLong(key);
            } else if (Double.class.isAssignableFrom(field.getType())
                    || Double.TYPE.isAssignableFrom(field.getType())) {
                value = configurationProvider.getDouble(key);
            } else if (Date.class.isAssignableFrom(field.getType())) {
                value = parseDate(configurationName, configurationProvider.getString(key), configuration);
                if (null == value) {
                    field = null;
                }
            } else {
                log.error("Field type not supported: " + field.getType());
                field = null;
            }
        } catch (IllegalArgumentException e) {
            if (!Date.class.isAssignableFrom(field.getType())) {
                ignoreTypeMismtachIfConfigured(configuration, configurationName, e);
                field = null;
            }
        } catch (ConversionException e) {
            if (!Date.class.isAssignableFrom(field.getType())) {
                ignoreTypeMismtachIfConfigured(configuration, configurationName, e);
                field = null;
            }
        }
    }

    if (field != null) {
        String defaultValue = String.valueOf(field.get(obj));
        String documentationValue;
        if (has) {
            field.set(obj, value);
            documentationValue = String.valueOf(value);
        } else {
            documentationValue = "";
        }
        configurationDocumentation.registerConfiguration(field, configurationName, has, defaultValue,
                documentationValue, configuration.documentation());
    }
}

From source file:org.ocelotds.dashboard.services.ServiceToolsTest.java

/**
 * Test of getInstanceOfClass method, of class ServiceTools.
 *
 * @throws com.fasterxml.jackson.core.JsonProcessingException
 *//*ww  w  . j a v  a2 s.  co m*/
@Test
public void testGetInstanceOfClass() throws JsonProcessingException {
    System.out.println("getTemplateOfClass");
    ObjectMapper om = new ObjectMapper();
    Result r = new Result();
    String expResult = om.writeValueAsString(r);
    Class cls = Boolean.class;
    Object result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(false);

    cls = Boolean.TYPE;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(false);

    cls = Integer.class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0);

    cls = Integer.TYPE;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0);

    cls = Long.class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0L);

    cls = Long.TYPE;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0l);

    cls = Float.class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0.1f);

    cls = Float.TYPE;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0.1f);

    cls = Double.class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0.1d);

    cls = Double.TYPE;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(0.1d);

    cls = Float[].class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualTo(new Float[] { 0.1f, 0.1f });

    cls = Result.class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualToComparingFieldByField(r);

    cls = Result[].class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isEqualToComparingFieldByField(new Result[] { r, r });

    cls = Locale.class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isInstanceOf(Locale.class);

    cls = Serializable.class;
    result = instance.getInstanceOfClass(cls);
    assertThat(result).isNull();
}

From source file:net.dmulloy2.ultimatearena.types.ArenaConfig.java

@Override
public Map<String, Object> serialize() {
    Map<String, Object> data = new LinkedHashMap<>();

    for (Field field : ArenaConfig.class.getDeclaredFields()) {
        try {/*from   www .ja  va  2  s  .c  o m*/
            if (Modifier.isTransient(field.getModifiers()))
                continue;

            boolean accessible = field.isAccessible();

            field.setAccessible(true);

            if (field.getType().equals(Integer.TYPE)) {
                if (field.getInt(this) != 0)
                    data.put(field.getName(), field.getInt(this));
            } else if (field.getType().equals(Long.TYPE)) {
                if (field.getLong(this) != 0)
                    data.put(field.getName(), field.getLong(this));
            } else if (field.getType().equals(Boolean.TYPE)) {
                if (field.getBoolean(this))
                    data.put(field.getName(), field.getBoolean(this));
            } else if (field.getType().isAssignableFrom(Collection.class)) {
                if (!((Collection<?>) field.get(this)).isEmpty())
                    data.put(field.getName(), field.get(this));
            } else if (field.getType().isAssignableFrom(String.class)) {
                if ((String) field.get(this) != null)
                    data.put(field.getName(), field.get(this));
            } else if (field.getType().isAssignableFrom(Map.class)) {
                if (!((Map<?, ?>) field.get(this)).isEmpty())
                    data.put(field.getName(), field.get(this));
            } else {
                if (field.get(this) != null)
                    data.put(field.getName(), field.get(this));
            }

            field.setAccessible(accessible);
        } catch (Throwable ex) {
        }
    }

    serializeCustomOptions(data);
    return data;
}

From source file:Main.java

/**
 * <p>Inserts the specified element at the specified position in the array.
 * Shifts the element currently at that position (if any) and any subsequent
 * elements to the right (adds one to their indices).</p>
 *
 * <p>This method returns a new array with the same elements of the input
 * array plus the given element on the specified position. The component
 * type of the returned array is always the same as that of the input
 * array.</p>//ww  w . ja v  a 2 s. c om
 *
 * <p>If the input array is {@code null}, a new one element array is returned
 *  whose component type is the same as the element.</p>
 *
 * <pre>
 * ArrayUtils.add(null, 0, true)          = [true]
 * ArrayUtils.add([true], 0, false)       = [false, true]
 * ArrayUtils.add([false], 1, true)       = [false, true]
 * ArrayUtils.add([true, false], 1, true) = [true, true, false]
 * </pre>
 *
 * @param array  the array to add the element to, may be {@code null}
 * @param index  the position of the new object
 * @param element  the object to add
 * @return A new array containing the existing elements and the new element
 * @throws IndexOutOfBoundsException if the index is out of range
 * (index < 0 || index > array.length).
 */
public static boolean[] add(boolean[] array, int index, boolean element) {
    return (boolean[]) add(array, index, Boolean.valueOf(element), Boolean.TYPE);
}

From source file:com.flexive.faces.renderer.FxSelectRenderer.java

/**
 * Convert select many values to given array class
 *
 * @param context      faces context//w  w  w.j a  v  a2  s .co  m
 * @param uiSelectMany select many component
 * @param arrayClass   the array class
 * @param newValues    new values to convert
 * @return converted values
 * @throws ConverterException on errors
 */
protected Object convertSelectManyValues(FacesContext context, UISelectMany uiSelectMany, Class arrayClass,
        String[] newValues) throws ConverterException {

    Object result;
    Converter converter;
    int len = (null != newValues ? newValues.length : 0);

    Class elementType = arrayClass.getComponentType();

    // Optimization: If the elementType is String, we don't need
    // conversion.  Just return newValues.
    if (elementType.equals(String.class))
        return newValues;

    try {
        result = Array.newInstance(elementType, len);
    } catch (Exception e) {
        throw new ConverterException(e);
    }

    // bail out now if we have no new values, returning our
    // oh-so-useful zero-length array.
    if (null == newValues)
        return result;

    // obtain a converter.

    // attached converter takes priority
    if (null == (converter = uiSelectMany.getConverter())) {
        // Otherwise, look for a by-type converter
        if (null == (converter = FxJsfComponentUtils.getConverterForClass(elementType, context))) {
            // if that fails, and the attached values are of Object type,
            // we don't need conversion.
            if (elementType.equals(Object.class))
                return newValues;
            StringBuffer valueStr = new StringBuffer();
            for (int i = 0; i < len; i++) {
                if (i == 0)
                    valueStr.append(newValues[i]);
                else
                    valueStr.append(' ').append(newValues[i]);
            }
            throw new ConverterException("Could not get a converter for " + String.valueOf(valueStr));
        }
    }

    if (elementType.isPrimitive()) {
        for (int i = 0; i < len; i++) {
            if (elementType.equals(Boolean.TYPE)) {
                Array.setBoolean(result, i,
                        ((Boolean) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Byte.TYPE)) {
                Array.setByte(result, i, ((Byte) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Double.TYPE)) {
                Array.setDouble(result, i,
                        ((Double) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Float.TYPE)) {
                Array.setFloat(result, i, ((Float) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Integer.TYPE)) {
                Array.setInt(result, i, ((Integer) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Character.TYPE)) {
                Array.setChar(result, i,
                        ((Character) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Short.TYPE)) {
                Array.setShort(result, i, ((Short) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Long.TYPE)) {
                Array.setLong(result, i, ((Long) converter.getAsObject(context, uiSelectMany, newValues[i])));
            }
        }
    } else {
        for (int i = 0; i < len; i++)
            Array.set(result, i, converter.getAsObject(context, uiSelectMany, newValues[i]));
    }
    return result;
}