Example usage for java.lang Boolean valueOf

List of usage examples for java.lang Boolean valueOf

Introduction

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

Prototype

public static Boolean valueOf(String s) 

Source Link

Document

Returns a Boolean with a value represented by the specified string.

Usage

From source file:com.googlecode.jtiger.modules.ecside.core.bean.RowDefaults.java

static Boolean isHighlightRow(TableModel model, Boolean highlightRow) {
    if (highlightRow == null) {
        return Boolean.valueOf(model.getPreferences().getPreference(PreferencesConstants.ROW_HIGHLIGHT_ROW));
    }//from w ww  .  jav  a2  s  .c  om

    return highlightRow;
}

From source file:Main.java

public static boolean modifyPermissionAutoStart(Context context, boolean enable) {
    try {//from  www .j a v  a  2s .c  om
        Class cls = Class.forName("android.miui.AppOpsUtils");
        if (cls != null) {
            Method declaredMethod = cls.getDeclaredMethod("setApplicationAutoStart",
                    new Class[] { Context.class, String.class, Boolean.TYPE });
            if (declaredMethod != null) {
                declaredMethod.invoke(cls,
                        new Object[] { context, context.getPackageName(), Boolean.valueOf(enable) });
                return true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

From source file:controllers.Mock.java

public static F.Promise<Result> mock(final String serviceName, final int vehicleId) {
    final int secsDelayed = Optional.ofNullable(request().getQueryString("secsDelayed"))
            .map(str -> Integer.parseInt(str)).orElse(0);
    final boolean boom = Optional.ofNullable(request().getQueryString("boom")).map(str -> Boolean.valueOf(str))
            .orElse(false);//ww  w . j a v  a 2  s.  c o  m

    if (boom) {
        return F.Promise.throwing(new RuntimeException("boom!!!"));
    }

    if (vehicleId != 1) {
        return F.Promise.pure(notFound(Json.toJson(ImmutableMap.of("error", "content not found!"))));
    }

    switch (serviceName) {
    case "vehicleData":
        return respond(Json.toJson(fakeVehicleData()), secsDelayed);
    case "vehicleImage":
        return respond(Json.toJson(fakeVehicleImage()), secsDelayed);
    case "searchResults":
        return respond(Json.toJson(fakeSearchResults()), secsDelayed);
    default:
        return F.Promise.pure(badRequest(String.format("serviceName %s not supported!", serviceName)));
    }
}

From source file:SystemProperty.java

/**
 * Returns the value of a system property as a boolean.
 * If such a system property exists it is converted to a boolean with
 * <tt>Boolean.valueOf(String)</tt>.
 * Returns the specified default value if no such system property exists or
 * the property value is invalid.//from w  w w. j  a va2 s.  c o m
 *
 * @return
 *      the boolean value of the specified property
 */
public static boolean booleanValue(String propName, boolean defaultValue) {
    String prop = System.getProperty(propName);
    boolean val;

    if (prop == null)
        val = defaultValue;
    else
        val = Boolean.valueOf(prop.trim()).booleanValue();

    return val;
}

From source file:Main.java

private static void setterValue(PropertyDescriptor property, Object mapValue, Object object)
        throws InvocationTargetException, IllegalAccessException, ParseException {
    Method setter = property.getWriteMethod();
    if (mapValue == null) {
        setter.invoke(object, mapValue);
        return;/*  ww w.  ja  v  a  2 s . c  o m*/
    }

    Class propertyType = property.getPropertyType();
    String type = propertyType.getName();
    String value = mapValue.toString();

    if (type.equals("java.lang.String")) {
        setter.invoke(object, value);
    } else if (type.equals("java.lang.Integer")) {
        setter.invoke(object, Integer.parseInt(value));
    } else if (type.equals("java.lang.Long")) {
        setter.invoke(object, Long.parseLong(value));
    } else if (type.equals("java.math.BigDecimal")) {
        setter.invoke(object, BigDecimal.valueOf(Double.parseDouble(value)));
    } else if (type.equals("java.math.BigInteger")) {
        setter.invoke(object, BigInteger.valueOf(Long.parseLong(value)));
    } else if (type.equals("java.util.Date")) {
        setter.invoke(object, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value));
    } else if (type.equals("java.lang.Boolean")) {
        setter.invoke(object, Boolean.valueOf(value));
    } else if (type.equals("java.lang.Float")) {
        setter.invoke(object, Float.parseFloat(value));
    } else if (type.equals("java.lang.Double")) {
        setter.invoke(object, Double.parseDouble(value));
    } else if (type.equals("java.lang.byte[]")) {
        setter.invoke(object, value.getBytes());
    } else {
        setter.invoke(object, value);
    }
}

From source file:org.wso2.carbon.inbound.endpoint.protocol.hl7.context.MLLPContextFactory.java

public static MLLPContext createMLLPContext(IOSession session, HL7Processor processor) {
    InboundProcessorParams inboundParams = (InboundProcessorParams) processor.getInboundParameterMap()
            .get(MLLPConstants.INBOUND_PARAMS);

    CharsetDecoder decoder = (CharsetDecoder) processor.getInboundParameterMap()
            .get(MLLPConstants.HL7_CHARSET_DECODER);
    boolean autoAck = processor.isAutoAck();
    boolean validate = Boolean
            .valueOf(inboundParams.getProperties().getProperty(MLLPConstants.PARAM_HL7_VALIDATE));
    Parser preParser = (Parser) processor.getInboundParameterMap().get(MLLPConstants.HL7_PRE_PROC_PARSER_CLASS);
    BufferFactory bufferFactory = (BufferFactory) processor.getInboundParameterMap()
            .get(MLLPConstants.INBOUND_HL7_BUFFER_FACTORY);

    return new MLLPContext(session, decoder, autoAck, validate, preParser, bufferFactory);
}

From source file:Main.java

public static List<Boolean> toList(boolean... array) {
    if (isEmpty(array)) {
        return new ArrayList<>(0);
    }//from  w  w  w .j a v  a2  s. com
    List<Boolean> list = new ArrayList<>(array.length);
    for (boolean b : array) {
        list.add(Boolean.valueOf(b));
    }
    return list;
}

From source file:Main.java

/**
 * Convert a string value to a boxed primitive type.
 *
 * @param type the boxed primitive type//  ww  w .  jav  a2 s . c o m
 * @param value the string value
 * @return a boxed primitive type
 */
public static Object valueOf(final Class<?> type, final String value) {
    if (type == String.class) {
        return value;
    }
    if (type == boolean.class) {
        return Boolean.valueOf(value);
    }
    if (type == int.class) {
        return Integer.valueOf(value);
    }
    if (type == long.class) {
        return Long.valueOf(value);
    }
    if (type == float.class) {
        return Float.valueOf(value);
    }
    if (type == double.class) {
        return Double.valueOf(value);
    }
    throw new IllegalArgumentException("Unsupported type " + type.getName());
}

From source file:controleur.moncompte.CmdEssaiConnexion.java

@Override
public String execute(HttpServletRequest request, HttpServletResponse response) {

    REST_Utilisateur ru = new REST_Utilisateur();
    Boolean connecte = Boolean.valueOf(ru.verifier(String.class, request.getParameter("identifiant"),
            DigestUtils.sha1Hex(request.getParameter("password"))));
    if (connecte) {
        Connexion connexion = new Connexion();
        connexion.setConnexion(true);//from  ww w  .  j  a  v  a 2  s.c  om
        Utilisateur utilisateur;
        utilisateur = ru.findByLogin_JSON(Utilisateur.class, request.getParameter("identifiant"));
        HttpSession httpSession = request.getSession(false);
        httpSession.setAttribute("connexion", connexion);
        httpSession.setAttribute("utilisateur", utilisateur);
        return "WEB-INF/accueil.jsp";
    } else {
        String erreur = "Erreur identification";
        request.setAttribute("erreur", erreur);
        request.setAttribute("identifiant", request.getParameter("identifiant"));
        request.setAttribute("password", request.getParameter("password"));
        return "WEB-INF/connexion.jsp";
    }
}

From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java

/**
 * ?,?,//from ww w  .jav  a  2s .c o  m
 * 
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
private static <T> T getInternalDefaultValue(Class<T> clazz) {
    if (!clazz.isPrimitive()) {
        return null;
    }
    if (Short.TYPE.equals(clazz)) {
        return (T) Short.valueOf((short) 0);
    }
    if (Integer.TYPE.equals(clazz)) {
        return (T) Integer.valueOf(0);
    }
    if (Long.TYPE.equals(clazz)) {
        return (T) Long.valueOf(0);
    }
    if (Boolean.TYPE.equals(clazz)) {
        return (T) Boolean.valueOf(false);
    }
    if (Float.TYPE.equals(clazz)) {
        return (T) Float.valueOf(0);
    }
    if (Double.TYPE.equals(clazz)) {
        return (T) Double.valueOf(0);
    }
    if (Byte.TYPE.equals(clazz)) {
        return (T) Byte.valueOf((byte) 0);
    }
    if (Character.TYPE.equals(clazz)) {
        return (T) Character.valueOf('\0');
    }
    return null;
}