Example usage for java.lang Character Character

List of usage examples for java.lang Character Character

Introduction

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

Prototype

@Deprecated(since = "9")
public Character(char value) 

Source Link

Document

Constructs a newly allocated Character object that represents the specified char value.

Usage

From source file:ca.sqlpower.dao.json.SPJSONMessageDecoder.java

/**
 * Takes in a {@link JSONTokener} that contains persister calls. The tokener
 * is used to parse each {@link JSONObject} token. Each JSONObject contains
 * details for making a SPPersister method call. The parsing is done in this
 * method in this way for performance reasons. Every time the next token is
 * parsed, the corresponding persister call is made immediately after. Since
 * the token is not used after parsing it, it will eventually be garbage
 * collected.//from  w  w w. ja v a 2 s  .c om
 * 
 * It expects the following key-value pairs in each JSONObject message:
 * <ul>
 * <li>method - The String value of a {@link SPPersistMethod}. This is used
 * to determine which {@link SPPersister} method to call.</li>
 * <li>uuid - The UUID of the SPObject, if there is one, that the persist
 * method call will act on. If there is none, it expects
 * {@link JSONObject#NULL}</li>
 * </ul>
 * Other possible key-value pairs (depending on the intended method call)
 * include:
 * <ul>
 * <li>parentUUID</li>
 * <li>type</li>
 * <li>newValue</li>
 * <li>oldValue</li>
 * <li>propertyName</li>
 * </ul>
 * See the method documentation of {@link SPPersister} for full details on
 * the expected values
 * <p>
 */
public void decode(JSONTokener tokener) throws SPPersistenceException {
    String uuid = null;
    JSONObject jsonObject = null;
    try {
        synchronized (persister) {
            // This code comes from JSONArray's constructor that takes in a
            // JSONTokener. The reason why a JSONArray is not used is because
            // we do not want to store all of the JSONObjects first before
            // persisting the calls. Instead, we want to make the persist calls
            // on the fly while parsing each token. By doing so, we allow
            // garbage collection on each JSONObject immediately after the
            // persist call is made.
            char c = tokener.nextClean();
            char q;
            if (c == '[') {
                q = ']';
            } else if (c == '(') {
                q = ')';
            } else {
                throw tokener.syntaxError("A JSONArray text must start with '['");
            }
            if (tokener.nextClean() == ']') {
                return;
            }
            tokener.back();

            int index = 0;

            while (true) {
                if (tokener.nextClean() == ',') {
                    tokener.back();
                    throw new JSONException("JSONArray[" + index + "] not found.");
                } else {
                    tokener.back();
                    Object nextValue = tokener.nextValue();

                    if (nextValue instanceof JSONObject) {
                        // Instead of storing the JSONObject in a List as
                        // JSONArray does, simply make the persist call straight
                        // from this object. Since it is not used after, it
                        // will eventually be garbage collected.
                        jsonObject = (JSONObject) nextValue;
                        logger.debug("Decoding Message: " + jsonObject);
                        uuid = jsonObject.getString("uuid");
                        decode(jsonObject);
                        index++;
                    } else {
                        throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
                    }
                }
                c = tokener.nextClean();
                switch (c) {
                case ';':
                case ',':
                    if (tokener.nextClean() == ']') {
                        return;
                    }
                    tokener.back();
                    break;
                case ']':
                case ')':
                    if (q != c) {
                        throw tokener.syntaxError("Expected a '" + new Character(q) + "'");
                    }
                    return;
                default:
                    throw tokener.syntaxError("Expected a ',' or ']'");
                }
            }
        }
    } catch (JSONException e) {
        if (jsonObject != null) {
            logger.error("Error decoding JSONObject " + jsonObject);
        }
        throw new SPPersistenceException(uuid, e);
    }
}

From source file:hermes.providers.messages.MapMessageImpl.java

public void setChar(String arg0, char arg1) throws JMSException {
    body.put(arg0, new Character(arg1));
}

From source file:mitm.common.tools.SendMail.java

public SendMail(String[] args) throws ParseException, IOException, MessagingException, InterruptedException {
    CommandLineParser parser = new BasicParser();

    Options options = createCommandLineOptions();

    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("SendMail", options, true);

    CommandLine commandLine = parser.parse(options, args);

    smtpHost = commandLine.getOptionValue("h");
    smtpPort = optionAsInteger(commandLine, "p", 25);
    username = commandLine.getOptionValue("u");
    password = commandLine.getOptionValue("password");
    sender = commandLine.getOptionValue("s");
    from = commandLine.getOptionValue("f");
    recipients = commandLine.getOptionValue("r");
    inFile = commandLine.getOptionValue("in");
    subject = commandLine.getOptionValue("su");
    count = optionAsInteger(commandLine, "c", 1);
    threads = optionAsInteger(commandLine, "t", 1);
    delay = optionAsLong(commandLine, "d", 0L);
    serverPort = optionAsInteger(commandLine, "sp", 2525);
    throttle = optionAsInteger(commandLine, "throttle", null);
    uniqueFrom = commandLine.hasOption("uf");

    throtllingSemaphore = throttle != null ? new Semaphore(throttle, true) : null;

    if (commandLine.hasOption("pwd")) {
        System.out.println("Please enter your password: ");
        password = new jline.ConsoleReader().readLine(new Character('*'));
    }//www  .java 2 s .c o m

    if (commandLine.hasOption("l")) {
        startSMTPServer();
        /* allow the SMTP server to settle */
        ThreadUtils.sleepQuietly(1000);
    }

    Address[] recipientsAddresses = getRecipients(recipients);

    if (recipientsAddresses != null) {
        MimeMessage message = commandLine.hasOption("in") ? loadMessage(inFile)
                : MailUtils.loadMessage(System.in);

        sendMessage(recipientsAddresses, message);
    }
}

From source file:StringUtils.java

public static String[] split(String string, char[] separatorChars) {
    if (string == null || string.equals(""))
        return new String[] { string };
    int len = string.length();
    Vector separators = new Vector(separatorChars.length);
    for (int s = 0; s < separatorChars.length; s++)
        separators.addElement(new Character(separatorChars[s]));
    Vector list = new Vector();
    int i = 0;/*from   w  w  w.  ja  v a2s . c  o  m*/
    int start = 0;
    boolean match = false;
    while (i < len) {
        if (separators.contains(new Character(string.charAt(i)))) {
            if (match) {
                list.addElement(string.substring(start, i));
                match = false;
            }
            start = ++i;
            continue;
        }
        match = true;
        i++;
    }
    if (match) {
        list.addElement(string.substring(start, i));
    }
    String[] arr = new String[list.size()];
    list.copyInto(arr);
    return arr;
}

From source file:com.github.xbn.text.StringUtil.java

/**
   <p>Creates a string where every element is the same character.</p>
        /*from w  w w .  j  a v a  2 s. c  o m*/
 * @param  length  The length of the returned string.
 * @param  char_toDup  The character to duplicate.
 * @param  length_varName  Descriptive name of {@code length}. <i>Should</i> not be {@code null} or empty.
 * @return  <code>new String(new char[length]).java.lang.String#replace(CharSequence, CharSequence)(&quot;\0&quot;, (new Character(char_toDup)).toString())</code>
 * @see  <code><a href="http://stackoverflow.com/questions/1235179/simple-way-to-repeat-a-string-in-java/4903603#4903603">http://stackoverflow.com/questions/1235179/simple-way-to-repeat-a-string-in-java/4903603#4903603</a></code>
 * @exception  NegativeArraySizeException  If {@code length} is less than zero.
 */
public static final String getStringOfLengthAllCharsEqualTo(int length, char char_toDup,
        String length_varName) {
    try {
        return new String(new char[length]).replace("\0", (new Character(char_toDup)).toString());
    } catch (NegativeArraySizeException nasx) {
        throw new NegativeArraySizeException(length_varName + "=" + length);
    }
}

From source file:TypeUtil.java

/** Convert String value to instance.
 * @param type The class of the instance, which may be a primitive TYPE field.
 * @param value The value as a string.// www . j a va  2s.c o  m
 * @return The value as an Object.
 */
public static Object valueOf(Class type, String value) {
    try {
        if (type.equals(java.lang.String.class))
            return value;

        Method m = (Method) class2Value.get(type);
        if (m != null)
            return m.invoke(null, new Object[] { value });

        if (type.equals(java.lang.Character.TYPE) || type.equals(java.lang.Character.class))
            return new Character(value.charAt(0));

        Constructor c = type.getConstructor(stringArg);
        return c.newInstance(new Object[] { value });
    }

    catch (InvocationTargetException e) {
        if (e.getTargetException() instanceof Error)
            throw (Error) (e.getTargetException());

    }
    return null;
}

From source file:com.tc.object.ApplicatorDNAEncodingTest.java

private char[] makeCharArray() {
    final char[] rv = new char[this.rnd.nextInt(10)];
    for (int i = 0; i < rv.length; i++) {
        rv[i] = new Character((char) this.rnd.nextInt(Character.MAX_VALUE)).charValue();
    }/*from  w ww  .  j  ava2 s . c  o m*/
    return rv;
}

From source file:TypeUtil.java

/** Convert String value to instance.
 * @param type The class of the instance, which may be a primitive TYPE field.
 * @param value The value as a string./*from www.j  a  va  2s.com*/
 * @return The value as an Object.
 */
public static Object valueOf(Class type, String value) {
    try {
        if (type.equals(java.lang.String.class))
            return value;

        Method m = (Method) class2Value.get(type);
        if (m != null)
            return m.invoke(null, new Object[] { value });

        if (type.equals(java.lang.Character.TYPE) || type.equals(java.lang.Character.class))
            return new Character(value.charAt(0));

        Constructor c = type.getConstructor(stringArg);
        return c.newInstance(new Object[] { value });
    } catch (NoSuchMethodException e) {
        // LogSupport.ignore(log,e);
    } catch (IllegalAccessException e) {
        // LogSupport.ignore(log,e);
    } catch (InstantiationException e) {
        // LogSupport.ignore(log,e);
    } catch (InvocationTargetException e) {
        if (e.getTargetException() instanceof Error)
            throw (Error) (e.getTargetException());
        // LogSupport.ignore(log,e);
    }
    return null;
}

From source file:de.odysseus.calyxo.base.util.ParseUtils.java

public void testPrimitive() throws Exception {
        assertEquals(Boolean.TRUE, ParseUtils.parse(boolean.class, "true"));
        assertEquals(Boolean.FALSE, ParseUtils.parse(boolean.class, "false"));
        assertEquals(new Character((char) 10), ParseUtils.parse(char.class, "\n"));
        assertEquals(new Byte((byte) 10), ParseUtils.parse(byte.class, "10"));
        assertEquals(new Short((short) 10), ParseUtils.parse(short.class, "10"));
        assertEquals(new Integer(10), ParseUtils.parse(int.class, "10"));
        assertEquals(new Long(10), ParseUtils.parse(long.class, "10"));
        assertEquals(new Float(10), ParseUtils.parse(float.class, "10"));
        assertEquals(new Double(10), ParseUtils.parse(double.class, "10"));
    }//from   www  .  j  a  v a 2s  .c o m

From source file:org.joda.primitives.list.impl.AbstractTestCharList.java

public void testFirst_notEmpty() {
    if (isAddSupported() == false) {
        return;//from w w  w.  j a  v a  2 s. c o  m
    }
    resetEmpty();
    CharList plist = (CharList) collection;
    plist.add((char) 0);
    plist.add('A');
    assertEquals(new Character((char) 0), plist.first());
}