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.flipkart.polyguice.dropwiz.DropConfigProvider.java

private String getNameFromMethod(Method method) {
    if (method.getParameterCount() > 0) {
        return null;
    }//from ww  w  .jav  a2s  .c  om
    if (method.getReturnType().equals(Void.TYPE)) {
        return null;
    }

    String mthdName = method.getName();
    if (mthdName.startsWith("get")) {
        if (mthdName.length() <= 3) {
            return null;
        }
        if (method.getReturnType().equals(Boolean.class) || method.getReturnType().equals(Boolean.TYPE)) {
            return null;
        }
        StringBuffer buffer = new StringBuffer(StringUtils.removeStart(mthdName, "get"));
        buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0)));
        return buffer.toString();
    } else if (!mthdName.startsWith("is")) {
        if (mthdName.length() <= 2) {
            return null;
        }
        if (!method.getReturnType().equals(Boolean.class) && !method.getReturnType().equals(Boolean.TYPE)) {
            return null;
        }
        StringBuffer buffer = new StringBuffer(StringUtils.removeStart(mthdName, "is"));
        buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0)));
        return buffer.toString();
    }
    return null;
}

From source file:org.opensaas.jaudit.test.BeanTest.java

/**
 * Returns a new Map of default test class to test values types useful in
 * testing getters/setters./*w  ww  .j  a  v  a  2 s.  c o  m*/
 * 
 * @return Map of supported types and associated values.
 */
protected static Map<Class<?>, Object[]> newClassToValues() {
    final Map<Class<?>, Object[]> ctov = new HashMap<Class<?>, Object[]>();

    ctov.put(Boolean.class, new Object[] { Boolean.TRUE, Boolean.FALSE, null });
    ctov.put(Boolean.TYPE, new Object[] { Boolean.TRUE, Boolean.FALSE });
    ctov.put(Date.class, new Object[] { new Date(), new Date(0L), new Date(1000L), null });
    ctov.put(Double.class, new Object[] { 0d, Double.MAX_VALUE, Double.MIN_VALUE, null });
    ctov.put(Double.TYPE, new Object[] { 0d, Double.MAX_VALUE, Double.MIN_VALUE });
    ctov.put(Integer.class, new Object[] { 0, Integer.MAX_VALUE, Integer.MIN_VALUE, null });
    ctov.put(Integer.TYPE, new Object[] { 0, Integer.MAX_VALUE, Integer.MIN_VALUE });
    ctov.put(Long.class, new Object[] { 0L, Long.MAX_VALUE, Long.MIN_VALUE, null });
    ctov.put(Long.TYPE, new Object[] { 0L, Long.MAX_VALUE, Long.MIN_VALUE });
    ctov.put(String.class, new Object[] { "", " ", "Texas Fight!", UUID.randomUUID().toString(), null });

    return Collections.unmodifiableMap(ctov);
}

From source file:com.adobe.acs.commons.mcp.util.AnnotatedFieldDeserializer.java

@SuppressWarnings("squid:S3776")
private static Object convertPrimitiveValue(String value, Class<?> type) throws ParseException {
    if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
        return value.toLowerCase().trim().equals("true");
    } else {/*from w  ww  .j a v  a  2  s.c om*/
        NumberFormat numberFormat = NumberFormat.getNumberInstance();
        Number num = numberFormat.parse(value);
        if (type.equals(Byte.class) || type.equals(Byte.TYPE)) {
            return num.byteValue();
        } else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
            return num.doubleValue();
        } else if (type.equals(Float.class) || type.equals(Float.TYPE)) {
            return num.floatValue();
        } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
            return num.intValue();
        } else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
            return num.longValue();
        } else if (type.equals(Short.class) || type.equals(Short.TYPE)) {
            return num.shortValue();
        } else {
            return null;
        }
    }
}

From source file:net.sf.json.JSONUtils.java

/**
 * Tests if obj is a Boolean or primitive boolean
 *//*from  w ww.  ja v  a  2 s  .c  om*/
public static boolean isBoolean(Object obj) {
    if (obj instanceof Boolean) {
        return true;
    }

    if ((obj != null) && (obj.getClass() == Boolean.TYPE)) {
        return true;
    }

    return false;
}

From source file:org.soybeanMilk.SbmUtils.java

/**
 * ?<code>type</code>?/*from  w  w  w.  jav  a  2 s.c om*/
 * @param type
 * @return
 * @date 2010-12-31
 */
public static Type wrapType(Type type) {
    if (!isClassType(type))
        return type;
    else if (!narrowToClass(type).isPrimitive())
        return type;
    else if (Byte.TYPE.equals(type))
        return Byte.class;
    else if (Short.TYPE.equals(type))
        return Short.class;
    else if (Integer.TYPE.equals(type))
        return Integer.class;
    else if (Long.TYPE.equals(type))
        return Long.class;
    else if (Float.TYPE.equals(type))
        return Float.class;
    else if (Double.TYPE.equals(type))
        return Double.class;
    else if (Boolean.TYPE.equals(type))
        return Boolean.class;
    else if (Character.TYPE.equals(type))
        return Character.class;
    else
        return type;
}

From source file:org.ow2.proactive_grid_cloud_portal.cli.EntryPoint.java

protected int run(String... args) {

    CommandFactory commandFactory = null;
    CommandLine cli = null;/*  w  w  w . j  av a 2  s  . c  om*/
    AbstractDevice console;

    ApplicationContext currentContext = new ApplicationContextImpl().currentContext();

    // Cannot rely on AbstractCommand#isDebugModeEnabled
    // because at this step SetDebugModeCommand#execute has not yet been executed
    // Consequently, SetDebugModeCommand.PROP_DEBUG_MODE is not set even if debug mode is enabled.
    boolean isDebugModeEnabled = isDebugModeEnabled(args);

    try {
        commandFactory = getCommandFactory(currentContext);
        Options options = commandFactory.supportedOptions();

        cli = parseArgs(options, args);
    } catch (IOException ioe) {
        System.err.println("An error occurred.");
        ioe.printStackTrace(System.err);
        return 1;
    } catch (ParseException pe) {
        writeError(currentContext, pe.getMessage(), pe, isDebugModeEnabled);
        // print usage
        Command help = commandFactory.commandForOption(new Option("h", null));
        if (help != null) {
            help.execute(currentContext);
        }
        return 1;
    }

    currentContext.setObjectMapper(new ObjectMapper().configure(FAIL_ON_UNKNOWN_PROPERTIES, false));
    currentContext.setRestServerUrl(DFLT_REST_SCHEDULER_URL);
    currentContext.setResourceType(resourceType());

    // retrieve the (ordered) command list corresponding to command-line
    // arguments
    List<Command> commands;
    try {
        commands = commandFactory.getCommandList(cli, currentContext);
    } catch (CLIException e) {
        writeError(currentContext, "An error occurred.", e, isDebugModeEnabled);
        return 1;
    }

    boolean retryLogin = false;

    try {
        executeCommandList(commands, currentContext);
    } catch (CLIException error) {
        if (REASON_UNAUTHORIZED_ACCESS == error.reason() && hasLoginCommand(commands)) {
            retryLogin = true;
        } else {
            writeError(currentContext, "An error occurred.", error, isDebugModeEnabled);
            return 1;
        }
    } catch (Throwable e) {
        writeError(currentContext, "An error occurred.", e, isDebugModeEnabled);
        return 1;
    }

    /*
     * in case of an existing session-id, the REST CLI reuses it without
     * obtaining a new session-id even if a login with credentials
     * specified. However if the REST server responds with an authorization
     * error (e.g. due to session timeout), it re-executes the commands list
     * with AbstractLoginCommand.PROP_RENEW_SESSION property set to 'true'.
     * This will effectively re-execute the user command with a new
     * session-id from server.
     */
    if (retryLogin && currentContext.getProperty(PROP_PERSISTED_SESSION, Boolean.TYPE, false)) {
        try {
            currentContext.setProperty(PROP_RENEW_SESSION, true);
            executeCommandList(commands, currentContext);
        } catch (Throwable error) {
            writeError(currentContext, "An error occurred while execution.", error, isDebugModeEnabled);
            return 1;
        }
    }
    return 0;
}

From source file:uk.ac.imperial.presage2.db.json.JsonStorage.java

private <T> T returnAsType(JsonNode n, Class<T> type) {
    if (type == String.class)
        return type.cast(n.textValue());
    else if (type == Integer.class || type == Integer.TYPE)
        return type.cast(n.asInt());
    else if (type == Double.class || type == Double.TYPE)
        return type.cast(n.asDouble());
    else if (type == Boolean.class || type == Boolean.TYPE)
        return type.cast(n.asBoolean());
    else if (type == Long.class || type == Long.TYPE)
        return type.cast(n.asLong());

    throw new RuntimeException("Unknown type cast request");
}

From source file:org.rhq.helpers.pluginGen.PluginGen.java

/**
 * Ask the questions by introspecting the {@link Props} class
 * @param br  BufferedReader to read the users answers from
 * @param parentProps Props of the parent - some of them will be copied to the children
 * @return an initialized Props object/*from w ww. ja v a2 s .  co  m*/
 * @throws Exception if anything goes wrong
 * @see org.rhq.helpers.pluginGen.Props
 */
private Props askQuestions(BufferedReader br, Props parentProps) throws Exception {

    Method[] meths = Props.class.getDeclaredMethods();
    Props props = new Props();

    System.out.print("Please specify the plugin root category ");
    List<ResourceCategory> possibleChildren = ResourceCategory.getPossibleChildren(parentProps.getCategory());
    for (ResourceCategory cat : possibleChildren) {
        System.out.print(cat + "(" + cat.getAbbrev() + "), ");
    }

    String answer = br.readLine();
    answer = answer.toUpperCase(Locale.getDefault());
    ResourceCategory cat = ResourceCategory.getByAbbrv(answer.charAt(0));
    if (cat != null)
        props.setCategory(cat);
    else {
        System.err.println("Bad answer, only use P/S/I");
        System.exit(1);
    }

    for (Method m : meths) {
        String name = m.getName();
        if (!name.startsWith("get") && !name.startsWith("is"))
            continue;

        Class retType = m.getReturnType();
        if (!retType.equals(String.class) && !retType.equals(Boolean.TYPE)) {
            continue;
        }

        if (name.startsWith("get"))
            name = name.substring(3);
        else
            name = name.substring(2);

        if (name.equals("PackagePrefix") && parentProps.getPackagePrefix() != null) {
            props.setPackagePrefix(parentProps.getPackagePrefix());
        } else if (name.equals("FileSystemRoot") && parentProps.getFileSystemRoot() != null) {
            props.setFileSystemRoot(parentProps.getFileSystemRoot());
        } else if (name.equals("ParentType") && parentProps.getName() != null) {
            // Set parent type always when we are in the child
            props.setParentType(caps(parentProps.getComponentClass()));
        } else if (name.equals("UsesExternalJarsInPlugin") && parentProps.getName() != null) {
            // Skip this one on children
        } else if (name.equals("UsePluginLifecycleListenerApi") && parentProps.getName() != null) {
            // Skip this one on children
        } else if (name.equals("DependsOnJmxPlugin") && parentProps.getName() != null) {
            // Skip this one on children
        } else if (name.equals("RhqVersion") && parentProps.getName() != null) {
            // Skip this one on children
        } else if (name.equals("Pkg")) {
            // Always skip this - we postprocess it
        } else {

            System.out.print("Please specify");
            boolean isBool = false;
            if (retType.equals(Boolean.TYPE)) {
                System.out.print(" if it should support " + name + " (y/N): ");
                isBool = true;
            } else {
                System.out.print(" its " + name + ": ");
            }

            answer = br.readLine();
            if (answer == null) {
                System.out.println("EOL .. aborting");
                return null;
            }
            String setterName = "set" + caps(name);

            Method setter;
            if (isBool)
                setter = Props.class.getMethod(setterName, Boolean.TYPE);
            else
                setter = Props.class.getMethod(setterName, String.class);

            if (isBool) {
                if (answer.toLowerCase(Locale.getDefault()).startsWith("y")
                        || answer.toLowerCase(Locale.getDefault()).startsWith("j")) {
                    setter.invoke(props, true);
                }
            } else {
                if (!answer.startsWith("\n") && !answer.startsWith("\r") && !(answer.length() == 0))
                    setter.invoke(props, answer);
            }
        }
    }

    return props;
}

From source file:com.adobe.acs.commons.data.Variant.java

@SuppressWarnings("squid:S3776")
public final <T> void setValue(T val) {
    if (val == null) {
        return;//from   w w w .ja  va2 s  .  c  o  m
    }
    Class type = val.getClass();
    if (type == Variant.class) {
        Variant v = (Variant) val;
        longVal = v.longVal;
        doubleVal = v.doubleVal;
        stringVal = v.stringVal;
        booleanVal = v.booleanVal;
        dateVal = v.dateVal;
    } else if (type == Byte.TYPE || type == Byte.class) {
        setLongVal(((Byte) val).longValue());
    } else if (type == Integer.TYPE || type == Integer.class) {
        setLongVal(((Integer) val).longValue());
    } else if (type == Long.TYPE || type == Long.class) {
        setLongVal((Long) val);
    } else if (type == Short.TYPE || type == Short.class) {
        setLongVal(((Short) val).longValue());
    } else if (type == Float.TYPE || type == Float.class) {
        setDoubleVal((Double) val);
    } else if (type == Double.TYPE || type == Double.class) {
        setDoubleVal((Double) val);
    } else if (type == Boolean.TYPE || type == Boolean.class) {
        setBooleanVal((Boolean) val);
    } else if (type == String.class) {
        setStringVal((String) val);
    } else if (type == Date.class) {
        setDateVal((Date) val);
    } else if (type == Instant.class) {
        setDateVal(new Date(((Instant) val).toEpochMilli()));
    } else if (type == Calendar.class) {
        setDateVal(((Calendar) val).getTime());
    } else {
        setStringVal(String.valueOf(val));
    }
}

From source file:nl.strohalm.cyclos.controls.accounts.transfertypes.EditTransferTypeAction.java

public DataBinder<TransferType> getDataBinder() {
    try {/*from  ww w  .j a  v  a 2s.c om*/
        lock.readLock().lock();
        if (dataBinder == null) {
            final LocalSettings localSettings = settingsService.getLocalSettings();

            final BeanBinder<Context> contextBinder = BeanBinder.instance(TransferType.Context.class,
                    "context");
            contextBinder.registerBinder("payment", PropertyBinder.instance(Boolean.TYPE, "payment"));
            contextBinder.registerBinder("selfPayment", PropertyBinder.instance(Boolean.TYPE, "selfPayment"));

            final BeanBinder<LoanParameters> loanBinder = BeanBinder.instance(LoanParameters.class, "loan");
            loanBinder.registerBinder("type", PropertyBinder.instance(Loan.Type.class, "type"));
            loanBinder.registerBinder("repaymentDays", PropertyBinder.instance(Integer.class, "repaymentDays"));
            loanBinder.registerBinder("repaymentType",
                    PropertyBinder.instance(TransferType.class, "repaymentType"));
            loanBinder.registerBinder("monthlyInterest", PropertyBinder.instance(BigDecimal.class,
                    "monthlyInterest", localSettings.getNumberConverter()));
            loanBinder.registerBinder("monthlyInterestRepaymentType",
                    PropertyBinder.instance(TransferType.class, "monthlyInterestRepaymentType"));
            loanBinder.registerBinder("grantFee", DataBinderHelper.amountConverter("grantFee", localSettings));
            loanBinder.registerBinder("grantFeeRepaymentType",
                    PropertyBinder.instance(TransferType.class, "grantFeeRepaymentType"));
            loanBinder.registerBinder("expirationFee",
                    DataBinderHelper.amountConverter("expirationFee", localSettings));
            loanBinder.registerBinder("expirationFeeRepaymentType",
                    PropertyBinder.instance(TransferType.class, "expirationFeeRepaymentType"));
            loanBinder.registerBinder("expirationDailyInterest", PropertyBinder.instance(BigDecimal.class,
                    "expirationDailyInterest", localSettings.getNumberConverter()));
            loanBinder.registerBinder("expirationDailyInterestRepaymentType",
                    PropertyBinder.instance(TransferType.class, "expirationDailyInterestRepaymentType"));

            final BeanBinder<TransferType> binder = BeanBinder.instance(TransferType.class);
            binder.registerBinder("id", PropertyBinder.instance(Long.class, "id", IdConverter.instance()));
            binder.registerBinder("name", PropertyBinder.instance(String.class, "name"));
            binder.registerBinder("description", PropertyBinder.instance(String.class, "description"));
            binder.registerBinder("confirmationMessage",
                    PropertyBinder.instance(String.class, "confirmationMessage"));
            binder.registerBinder("context", contextBinder);
            binder.registerBinder("channels", SimpleCollectionBinder.instance(Channel.class, "channels"));
            binder.registerBinder("priority", PropertyBinder.instance(Boolean.TYPE, "priority"));
            binder.registerBinder("from", PropertyBinder.instance(AccountType.class, "from"));
            binder.registerBinder("to", PropertyBinder.instance(AccountType.class, "to"));
            binder.registerBinder("maxAmountPerDay", PropertyBinder.instance(BigDecimal.class,
                    "maxAmountPerDay", localSettings.getNumberConverter()));
            binder.registerBinder("minAmount",
                    PropertyBinder.instance(BigDecimal.class, "minAmount", localSettings.getNumberConverter()));
            binder.registerBinder("conciliable", PropertyBinder.instance(Boolean.TYPE, "conciliable"));
            binder.registerBinder("loan", loanBinder);
            binder.registerBinder("requiresAuthorization",
                    PropertyBinder.instance(Boolean.TYPE, "requiresAuthorization"));
            binder.registerBinder("allowsScheduledPayments",
                    PropertyBinder.instance(Boolean.TYPE, "allowsScheduledPayments"));
            binder.registerBinder("requiresFeedback",
                    PropertyBinder.instance(Boolean.TYPE, "requiresFeedback"));
            binder.registerBinder("feedbackExpirationTime",
                    DataBinderHelper.timePeriodBinder("feedbackExpirationTime"));
            binder.registerBinder("feedbackReplyExpirationTime",
                    DataBinderHelper.timePeriodBinder("feedbackReplyExpirationTime"));
            binder.registerBinder("defaultFeedbackComments",
                    PropertyBinder.instance(String.class, "defaultFeedbackComments"));
            binder.registerBinder("defaultFeedbackLevel",
                    PropertyBinder.instance(Reference.Level.class, "defaultFeedbackLevel"));
            binder.registerBinder("fixedDestinationMember",
                    PropertyBinder.instance(Member.class, "fixedDestinationMember"));
            binder.registerBinder("reserveTotalAmountOnScheduling",
                    PropertyBinder.instance(Boolean.TYPE, "reserveTotalAmountOnScheduling"));
            binder.registerBinder("allowCancelScheduledPayments",
                    PropertyBinder.instance(Boolean.TYPE, "allowCancelScheduledPayments"));
            binder.registerBinder("allowBlockScheduledPayments",
                    PropertyBinder.instance(Boolean.TYPE, "allowBlockScheduledPayments"));
            binder.registerBinder("showScheduledPaymentsToDestination",
                    PropertyBinder.instance(Boolean.TYPE, "showScheduledPaymentsToDestination"));
            binder.registerBinder("allowSmsNotification",
                    PropertyBinder.instance(Boolean.TYPE, "allowSmsNotification"));
            binder.registerBinder("transferListenerClass",
                    PropertyBinder.instance(String.class, "transferListenerClass"));
            binder.registerBinder("transactionHierarchyVisibility", PropertyBinder
                    .instance(TransactionHierarchyVisibility.class, "transactionHierarchyVisibility"));
            dataBinder = binder;
        }
        return dataBinder;
    } finally {
        lock.readLock().unlock();
    }
}