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

private static Object readThisPrimitiveValueXml(XmlPullParser parser, String tagName)
        throws XmlPullParserException {
    try {/*from w w  w.  j  a  va2 s .com*/
        switch (tagName) {
        case "int":
            return Integer.parseInt(parser.getAttributeValue(null, "value"));
        case "long":
            return Long.valueOf(parser.getAttributeValue(null, "value"));
        case "float":
            return Float.valueOf(parser.getAttributeValue(null, "value"));
        case "double":
            return Double.valueOf(parser.getAttributeValue(null, "value"));
        case "boolean":
            return Boolean.valueOf(parser.getAttributeValue(null, "value"));
        default:
            return null;
        }
    } catch (NullPointerException e) {
        throw new XmlPullParserException("Need value attribute in <" + tagName + ">");
    } catch (NumberFormatException e) {
        throw new XmlPullParserException("Not a number in value attribute in <" + tagName + ">");
    }
}

From source file:com.bibisco.manager.RichTextEditorSettingsManager.java

public static RichTextEditorSettings load() {

    mLog.debug("Start load()");

    RichTextEditorSettings lRichTextEditorSettings = new RichTextEditorSettings();

    PropertiesManager lPropertiesManager = PropertiesManager.getInstance();

    // font//from w  w w . j a v  a  2 s. co  m
    lRichTextEditorSettings.setFont(lPropertiesManager.getProperty("font"));

    // font size
    lRichTextEditorSettings.setSize(lPropertiesManager.getProperty("font-size"));

    // spell check enabled
    lRichTextEditorSettings
            .setSpellCheckEnabled(Boolean.valueOf(lPropertiesManager.getProperty("spellCheckEnabled")));

    mLog.debug("End load()");

    return lRichTextEditorSettings;
}

From source file:Main.java

/**
   Return the value of an attribute of a node as a boolean variable
   or <code>null</code> if the attribute is not present.
 *//*  w ww.  ja v a 2  s .  c o m*/
static public Boolean getBooleanAttribute(Node node, String att_name) {
    if (node == null)
        return null;
    String text = getText(node.getAttributes().getNamedItem(att_name));
    if (text == null)
        return null;
    return Boolean.valueOf(text);
}

From source file:Main.java

public static Object typeConversion(Class<?> cls, String str) {
    Object obj = null;/*from  w  ww.  j  a v a2 s  .c o  m*/
    String nameType = cls.getSimpleName();
    if ("Integer".equals(nameType)) {
        obj = Integer.valueOf(str);
    }
    if ("String".equals(nameType)) {
        obj = str;
    }
    if ("Float".equals(nameType)) {
        obj = Float.valueOf(str);
    }
    if ("Double".equals(nameType)) {
        obj = Double.valueOf(str);
    }

    if ("Boolean".equals(nameType)) {
        obj = Boolean.valueOf(str);
    }
    if ("Long".equals(nameType)) {
        obj = Long.valueOf(str);
    }

    if ("Short".equals(nameType)) {
        obj = Short.valueOf(str);
    }

    if ("Character".equals(nameType)) {
        obj = str.charAt(1);
    }

    return obj;
}

From source file:Main.java

/**
 * Formats an XML string for pretty printing. Requires Java 1.6.
 * //from   w ww .  ja v a  2  s  . c o m
 * Taken from http://stackoverflow.com/questions/139076/how-to-pretty-print-xml-from-java
 * 
 * @param xml
 * @return pretty-print formatted XML
 */
public static String prettyPrintXml(String xml) {
    try {
        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();

        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

/**
 * /*from w  ww.j a va  2  s.  c om*/
 * @param value
 * @return boolean[]
 */
public static boolean[] toBooleanArray(final String value) {
    if (value == null) {
        return new boolean[] {};
    }

    final String strippedValue = value.replace(ARRAY_OPEN_TAG, EMPTY_STRING).replace(ARRAY_CLOSE_TAG,
            EMPTY_STRING);
    final StringTokenizer tokenizer = new StringTokenizer(strippedValue, ELEMENT_SEPARATOR);
    final Collection<Boolean> intCollection = new ArrayList<>();

    while (tokenizer.hasMoreTokens()) {
        intCollection.add(Boolean.valueOf(tokenizer.nextToken().trim()));
    }

    return toBooleanArray(intCollection);
}

From source file:PrimitiveUtils.java

public static Object read(String value, Class type) {
    Object ret = value;//  ww  w .j  av a  2 s  .c o  m
    if (Integer.TYPE.equals(type)) {
        ret = Integer.valueOf(value);
    }
    if (Byte.TYPE.equals(type)) {
        ret = Byte.valueOf(value);
    }
    if (Short.TYPE.equals(type)) {
        ret = Short.valueOf(value);
    }
    if (Long.TYPE.equals(type)) {
        ret = Long.valueOf(value);
    }
    if (Float.TYPE.equals(type)) {
        ret = Float.valueOf(value);
    }
    if (Double.TYPE.equals(type)) {
        ret = Double.valueOf(value);
    }
    if (Boolean.TYPE.equals(type)) {
        ret = Boolean.valueOf(value);
    }
    if (Character.TYPE.equals(type)) {
        ret = value.charAt(0);
    }
    // TODO others.
    return ret;
}

From source file:Main.java

private static final Object readThisPrimitiveValueXml(XmlPullParser parser, String tagName)
        throws XmlPullParserException, java.io.IOException {
    try {//from  www . j  a  v a2  s .co  m
        if (tagName.equals("int")) {
            return Integer.parseInt(parser.getAttributeValue(null, "value"));
        } else if (tagName.equals("long")) {
            return Long.valueOf(parser.getAttributeValue(null, "value"));
        } else if (tagName.equals("float")) {
            return new Float(parser.getAttributeValue(null, "value"));
        } else if (tagName.equals("double")) {
            return new Double(parser.getAttributeValue(null, "value"));
        } else if (tagName.equals("boolean")) {
            return Boolean.valueOf(parser.getAttributeValue(null, "value"));
        } else {
            return null;
        }
    } catch (NullPointerException e) {
        throw new XmlPullParserException("Need value attribute in <" + tagName + ">");
    } catch (NumberFormatException e) {
        throw new XmlPullParserException("Not a number in value attribute in <" + tagName + ">");
    }
}

From source file:Main.java

public static void setFrameModified(RootPaneContainer frame, boolean flag) {

    setFrameModified(frame, Boolean.valueOf(flag));
}

From source file:Main.java

private static final Object readThisPrimitiveValueXml(XmlPullParser parser, String tagName)
        throws XmlPullParserException, IOException {
    try {// w w  w . j a  v a 2  s .c  o m
        if (tagName.equals("int")) {
            return Integer.parseInt(parser.getAttributeValue(null, "value"));
        } else if (tagName.equals("long")) {
            return Long.valueOf(parser.getAttributeValue(null, "value"));
        } else if (tagName.equals("float")) {
            return new Float(parser.getAttributeValue(null, "value"));
        } else if (tagName.equals("double")) {
            return new Double(parser.getAttributeValue(null, "value"));
        } else if (tagName.equals("boolean")) {
            return Boolean.valueOf(parser.getAttributeValue(null, "value"));
        } else {
            return null;
        }
    } catch (NullPointerException e) {
        throw new XmlPullParserException("Need value attribute in <" + tagName + ">");
    } catch (NumberFormatException e) {
        throw new XmlPullParserException("Not a number in value attribute in <" + tagName + ">");
    }
}