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:Main.java

public static Boolean getBooleanAttribute(final Context context, final AttributeSet attrs,
        final String namespace, final String name, final Boolean defValue) {
    final int resId = attrs.getAttributeResourceValue(namespace, name, Integer.MIN_VALUE);
    if (resId != Integer.MIN_VALUE) {
        return context.getResources().getBoolean(resId);
    }// w ww  .j  a va  2  s. c o m
    String str = attrs.getAttributeValue(namespace, name);
    return str != null ? Boolean.valueOf(str) : defValue;
}

From source file:Main.java

public static String formatXml(String xml) {

    try {/*from   w  ww.java2  s. c  o m*/
        final InputSource src = new InputSource(new StringReader(xml));
        final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src)
                .getDocumentElement();
        final Boolean keepDeclaration = Boolean.valueOf(xml.startsWith("<?xml"));

        //May need this: System.setProperty(DOMImplementationRegistry.
        //PROPERTY,"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");

        final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
        final LSSerializer writer = impl.createLSSerializer();

        // Set this to true if the output needs to be beautified.
        writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);

        // Set this to true if the declaration is needed to be outputted.
        writer.getDomConfig().setParameter("xml-declaration", keepDeclaration);

        return writer.writeToString(document);
    } catch (Exception e) {

        System.err.println("Exception thrown");
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static String prettyFormat(String input) {
    try {/* ww  w .j av  a 2s.  c o m*/
        final InputSource src = new InputSource(new StringReader(input));
        final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src)
                .getDocumentElement();
        final Boolean keepDeclaration = Boolean.valueOf(input.startsWith("<?xml"));
        final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
        final LSSerializer writer = impl.createLSSerializer();

        writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified.
        writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted.

        return writer.writeToString(document);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

/**
 * Returns attribute as boolean for class
 *
 * @param elem//from  w w  w .j a  v a  2s  . co m
 * @param attribName
 * @return
 */
public static boolean getAttributeAsBoolean(Element elem, String attribName) {
    String atribVal = elem.getAttribute(attribName);
    boolean retVal = false;

    try {
        retVal = Boolean.valueOf(atribVal).booleanValue();
    } catch (Exception e) {
    }
    return retVal;
}

From source file:Main.java

public static void removeSysKey(Activity context, EditText paramEditText) {
    if (Build.VERSION.SDK_INT <= 10) {
        paramEditText.setInputType(0);//  www . j a v a2s  . c  o m
        return;
    }
    context.getWindow().setSoftInputMode(3);
    try {
        Class[] arrayOfClass = new Class[1];
        arrayOfClass[0] = Boolean.TYPE;
        Method localMethod = EditText.class.getMethod("setShowSoftInputOnFocus", arrayOfClass);
        localMethod.setAccessible(true);
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = Boolean.valueOf(false);
        localMethod.invoke(paramEditText, arrayOfObject);
        return;
    } catch (Exception localException) {
        localException.printStackTrace();
    }
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> T getJsonObjectValue(JSONObject jsonObject, String key, Class<T> clazz) {
    T t = null;/*from  www  .  ja  v  a2 s . co m*/
    try {
        if (clazz == Integer.class) {
            t = (T) Integer.valueOf(jsonObject.getInt(key));
        } else if (clazz == Boolean.class) {
            t = (T) Boolean.valueOf(jsonObject.getBoolean(key));
        } else if (clazz == String.class) {
            t = (T) String.valueOf(jsonObject.getString(key));
        } else if (clazz == Double.class) {
            t = (T) Double.valueOf(jsonObject.getDouble(key));
        } else if (clazz == JSONObject.class) {
            t = (T) jsonObject.getJSONObject(key);
        } else if (clazz == JSONArray.class) {
            t = (T) jsonObject.getJSONArray(key);
        } else if (clazz == Long.class) {
            t = (T) Long.valueOf(jsonObject.getLong(key));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return t;
}

From source file:Main.java

public static boolean isBoolean(String string) {
    try {/*from w  w w .  j a v  a 2  s.  c o  m*/
        Boolean.valueOf(string);
        return true;
    } catch (NumberFormatException e) {
        return false;
    }
}

From source file:Main.java

public static boolean getBooleanValue(NamedNodeMap values, String name, boolean defaultValue) {
    Node node = values.getNamedItem(name);
    return node == null ? defaultValue : Boolean.valueOf(node.getNodeValue()).booleanValue();
}

From source file:Main.java

public static <T> T getData(Context context, String fileName, String key, Class T) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    T result;//  w w w . java2  s .c o m
    if (String.class.isAssignableFrom(T)) {
        result = (T) sharedPreferences.getString(key, "");
    } else if (Integer.class.isAssignableFrom(T)) {
        result = (T) Integer.valueOf(sharedPreferences.getInt(key, 0));
    } else if (Float.class.isAssignableFrom(T)) {
        result = (T) Float.valueOf(sharedPreferences.getFloat(key, 0));
    } else if (Long.class.isAssignableFrom(T)) {
        result = (T) Long.valueOf(sharedPreferences.getLong(key, 0));
    } else {
        result = (T) Boolean.valueOf(sharedPreferences.getBoolean(key, false));
    }
    return result;
}

From source file:Main.java

public static Boolean getAttributeBoolean(Node node, String attributeName) {
    String value = getAttribute(node, attributeName, null);
    return (value == null ? null : Boolean.valueOf(value));
}