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:org.vertx.java.http.eventbusbridge.integration.MessageSendTest.java

@Test
public void testSendingCharacterJson() throws IOException {
    final EventBusMessageType messageType = EventBusMessageType.Character;
    final Character sentCharacter = new Character('T');
    Map<String, String> expectations = createExpectations("someaddress",
            Base64.encodeAsString(sentCharacter.toString()), messageType);
    Handler<Message> messageConsumerHandler = new MessageSendHandler(sentCharacter, expectations);
    vertx.eventBus().registerHandler(expectations.get("address"), messageConsumerHandler);
    String body = TemplateHelper.generateOutputUsingTemplate(SEND_REQUEST_TEMPLATE_JSON, expectations);
    HttpRequestHelper.sendHttpPostRequest(url, body, (VertxInternal) vertx, Status.ACCEPTED.getStatusCode(),
            MediaType.APPLICATION_JSON);
}

From source file:org.tolven.connectors.passwordstore.PasswordStoreImpl.java

private static char[] toCharArray(byte[] passwordBytes) {
    try {// w w w  .j  a  v a 2s . co m
        ByteArrayInputStream bais = new ByteArrayInputStream(passwordBytes);
        InputStreamReader inputStreamReader = null;
        List<Character> characters = new ArrayList<Character>();
        try {
            inputStreamReader = new InputStreamReader(bais, Charset.forName("UTF-8"));
            int c;
            while ((c = inputStreamReader.read()) > -1) {
                characters.add(new Character((char) c));
            }
        } finally {
            inputStreamReader.close();
        }
        char[] passwordAsCharArray = new char[characters.size()];
        for (int i = 0; i < characters.size(); i++) {
            passwordAsCharArray[i] = characters.get(i);
        }
        return passwordAsCharArray;
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.apache.axis2.corba.idl.values.AbstractValue.java

protected Object read(DataType dataType, InputStream inputStream) {
    TCKind kind = dataType.getTypeCode().kind();
    Object ret = null;//from  w  w w .  j  a v  a 2s .  co  m
    switch (kind.value()) {
    case TCKind._tk_long:
        ret = new Integer(inputStream.read_long());
        break;
    case TCKind._tk_ulong:
        ret = new Integer(inputStream.read_ulong());
        break;
    case TCKind._tk_longlong:
        ret = new Long(inputStream.read_longlong());
        break;
    case TCKind._tk_ulonglong:
        ret = new Long(inputStream.read_ulonglong());
        break;
    case TCKind._tk_short:
        ret = new Short(inputStream.read_short());
        break;
    case TCKind._tk_ushort:
        ret = new Short(inputStream.read_ushort());
        break;
    case TCKind._tk_float:
        ret = new Float(inputStream.read_float());
        break;
    case TCKind._tk_double:
        ret = new Double(inputStream.read_double());
        break;
    case TCKind._tk_char:
        ret = new Character(inputStream.read_char());
        break;
    case TCKind._tk_wchar:
        ret = new Character(inputStream.read_wchar());
        break;
    case TCKind._tk_boolean:
        ret = Boolean.valueOf(inputStream.read_boolean());
        break;
    case TCKind._tk_octet:
        ret = new Byte(inputStream.read_octet());
        break;
    case TCKind._tk_string:
        ret = inputStream.read_string();
        break;
    case TCKind._tk_wstring:
        ret = inputStream.read_wstring();
        break;
    case TCKind._tk_any:
        ret = inputStream.read_any();
        break;
    case TCKind._tk_value:
        ret = inputStream.read_value();
        break;
    //case TCKind._tk_longdouble :
    case TCKind._tk_struct:
        StructValue structValue = new StructValue((Struct) dataType);
        structValue.read(inputStream);
        ret = structValue;
        break;
    case TCKind._tk_enum:
        EnumValue enumValue = new EnumValue((EnumType) dataType);
        enumValue.read(inputStream);
        ret = enumValue;
        break;
    case TCKind._tk_union:
        UnionValue unionValue = new UnionValue((UnionType) dataType);
        unionValue.read(inputStream);
        ret = unionValue;
        break;
    case TCKind._tk_alias:
        AliasValue aliasValue = new AliasValue((Typedef) dataType);
        aliasValue.read(inputStream);
        ret = aliasValue;
        break;
    case TCKind._tk_sequence:
        SequenceValue sequenceValue = new SequenceValue((SequenceType) dataType);
        sequenceValue.read(inputStream);
        ret = sequenceValue;
        break;
    case TCKind._tk_array:
        ArrayValue arrayValue = new ArrayValue((ArrayType) dataType);
        arrayValue.read(inputStream);
        ret = arrayValue;
        break;
    case TCKind._tk_except:
        ExceptionValue exValue = new ExceptionValue((ExceptionType) dataType);
        exValue.read(inputStream);
        ret = exValue;
        break;
    default:
        log.error("ERROR! Invalid dataType");
        break;
    }
    return ret;
}

From source file:ReflectUtils.java

/**
 * //www  .  j a va  2s.co  m
 * @param arrayClass
 *          The array version of a given type (<em>YourType[].class</em>)
 * 
 * @return The non-array version of the given type. For example, if you pass
 *         <em>String[].class</em>, you get <em>String.class</em>. If
 *         you pass <em>int[].class</em>, you get <em>int.class</em>.
 * 
 * @see #getArrayClassFromClass(Class)
 * 
 */
public static Class getClassFromArrayClass(Class arrayClass) {
    if (arrayClass == null)
        throw new NullPointerException("NullClass");

    String name = arrayClass.getName();

    //
    // make sure it's an array type
    //
    if (name.charAt(0) != '[') {
        Object[] filler = { name };
        throw new RuntimeException("NotArrayClass");
    }

    if (name.charAt(1) == '[') {
        Object[] filler = { name };
        throw new RuntimeException("NoMultiArrays");
    }

    //
    // the char after the [ signifies the type of the array. these
    // values are documented with java.lang.Class.getName()
    //
    char type = name.charAt(1);

    switch (type) {
    case 'Z':
        return boolean.class;

    case 'B':
        return byte.class;

    case 'C':
        return char.class;

    case 'D':
        return double.class;

    case 'F':
        return float.class;

    case 'I':
        return int.class;

    case 'J':
        return long.class;

    case 'S':
        return short.class;

    case 'L':
        return getClass(name.substring(2, name.length() - 1));

    default:
        Object[] filler = { name, new Character(type) };
        String message = "UnsupportedType";
        throw new RuntimeException(message);
    }
}

From source file:com.blackducksoftware.tools.commonframework.core.encryption.Password.java

/**
 * Test to see whether this password adheres to the password rules. Ascii
 * chars '!' through '~' only (no spaces). Min len: 1 char Max len: 64 chars
 *
 * @param password/* w  ww .j av a  2 s.co  m*/
 * @return
 */
public static boolean isValidPassword(final String password) {
    if (password == null) {
        return false;
    }
    if (password.length() < MIN_LENGTH) {
        return false;
    }
    if (password.length() > MAX_LENGTH) {
        return false;
    }

    final List<Character> badChars = Arrays.asList(Password.PROHIBITED_CHARS);
    final byte[] passwordBytes = password.getBytes();
    for (int i = 0; i < password.length(); i++) {
        final byte passwordByte = passwordBytes[i];
        if (passwordByte < MIN_CHAR_VALUE) {
            return false;
        }
        if (passwordByte > MAX_CHAR_VALUE) {
            return false;
        }

        if (badChars.contains(new Character((char) passwordByte))) {
            return false;
        }
    }

    return true;
}

From source file:org.kuali.student.git.model.branch.utils.GitBranchUtils.java

protected static String convertPathToBranchName(String branchPath) {

    StringBuilder convertedPathBuilder = new StringBuilder();

    Map<String, String> characterToReplacementMap = new HashMap<>(CHARACTER_TO_REPLACEMENT_MAP);

    /*//w w w. ja  v  a 2  s . c  o  m
     * Replace spaces first
     */
    characterToReplacementMap.remove(SPACE_CHARACTER);

    String modifiedBranchPath = branchPath.replaceAll(SPACE_REPLACEMENT, SPACE_CHARACTER);

    /*
     * Replace underscores first
     */

    characterToReplacementMap.remove(UNDERSCORE_CHARACTER);

    modifiedBranchPath = branchPath.replaceAll(UNDERSCORE_REPLACEMENT, UNDERSCORE_CHARACTER);

    char[] charArray = modifiedBranchPath.toCharArray();

    for (int i = 0; i < charArray.length; i++) {

        String character = new Character(charArray[i]).toString();

        String replacement = CHARACTER_TO_REPLACEMENT_MAP.get(character);

        if (replacement != null)
            convertedPathBuilder.append(replacement);
        else
            convertedPathBuilder.append(character);
    }

    return convertedPathBuilder.toString();
}

From source file:org.clever.administration.CLI.java

public boolean createConfigurationFile() {
    InputStream inxml = null;//from w  w w . ja va2  s  .c om
    FileStreamer fs = null;
    ParserXML pXML = null;
    System.out.println("----------------------------------------");
    System.out.println("| Administration Console Configuration |");
    System.out.println("----------------------------------------");
    System.out.println("\n\nPlease insert the following data:\n\n");
    try {
        inxml = getClass().getResourceAsStream(cfgTemplatePath);
    } catch (Exception e) {
        System.out.println("Template file not found. " + e);
        System.exit(1);
    }
    try {
        fs = new FileStreamer();
        pXML = new ParserXML(fs.xmlToString(inxml));
    } catch (IOException e) {
        System.out.println("Error while parsing: " + e);
        System.exit(1);
    }
    try {
        cleverConsole = new ConsoleReader();
        cleverConsole.setBellEnabled(false);
        String server = cleverConsole.readLine("server XMPP: ");
        String port = cleverConsole.readLine("port: ");
        String room = cleverConsole.readLine("room: ");
        String username = cleverConsole.readLine("username: ");
        String password = cleverConsole.readLine("password: ", new Character('*'));
        String nickname = cleverConsole.readLine("nickname: ");
        pXML.modifyXML("server", server);
        pXML.modifyXML("port", port);
        pXML.modifyXML("username", username);
        pXML.modifyXML("password", password);
        pXML.modifyXML("nickname", nickname);
        pXML.modifyXML("room", room);
        File cliConfiguration = new File(cfgCLIPath);
        if (!new File(cfgCLIPath).exists()) {
            cliConfiguration.mkdirs();
        }
        pXML.saveXML(cfgCLIPath + "/config_clever_cli.xml");
        System.out.println("Configuration file created.");
        return true;
    } catch (IOException e) {
        System.out.println("Configuration file creation failed. " + e);
        return false;
    }
}

From source file:mil.jpeojtrs.sca.util.tests.AnyUtilsTest.java

@Test
public void test_convertAny() throws Exception {
    final Boolean result = (Boolean) AnyUtils.convertAny(this.any);

    Assert.assertTrue(result);/*  ww  w .j  a va 2s  . c o m*/

    Assert.assertNull(AnyUtils.convertAny(null));

    String str = (String) AnyUtils.convertAny(AnyUtils.toAny("2", TCKind.tk_string));
    Assert.assertEquals("2", str);
    str = (String) AnyUtils.convertAny(AnyUtils.toAny("3", TCKind.tk_wstring));
    Assert.assertEquals("3", str);
    final short b = (Short) AnyUtils.convertAny(AnyUtils.toAny(Byte.MAX_VALUE, TCKind.tk_octet));
    Assert.assertEquals(Byte.MAX_VALUE, b);
    char c = (Character) AnyUtils.convertAny(AnyUtils.toAny(Character.MAX_VALUE, TCKind.tk_char));
    Assert.assertEquals(Character.MAX_VALUE, c);
    c = (Character) AnyUtils.convertAny(AnyUtils.toAny(new Character('2'), TCKind.tk_wchar));
    Assert.assertEquals('2', c);
    final short s = (Short) AnyUtils.convertAny(AnyUtils.toAny(Short.MAX_VALUE, TCKind.tk_short));
    Assert.assertEquals(Short.MAX_VALUE, s);
    final int i = (Integer) AnyUtils.convertAny(AnyUtils.toAny(Integer.MAX_VALUE, TCKind.tk_long));
    Assert.assertEquals(Integer.MAX_VALUE, i);
    final long l = (Long) AnyUtils.convertAny(AnyUtils.toAny(Long.MAX_VALUE, TCKind.tk_longlong));
    Assert.assertEquals(Long.MAX_VALUE, l);
    final float f = (Float) AnyUtils.convertAny(AnyUtils.toAny(Float.MAX_VALUE, TCKind.tk_float));
    Assert.assertEquals(Float.MAX_VALUE, f, 0.00001);
    final double d = (Double) AnyUtils.convertAny(AnyUtils.toAny(Double.MAX_VALUE, TCKind.tk_double));
    Assert.assertEquals(Double.MAX_VALUE, d, 0.00001);
    final int us = (Integer) AnyUtils.convertAny(AnyUtils.toAny(Short.MAX_VALUE, TCKind.tk_ushort));
    Assert.assertEquals(Short.MAX_VALUE, us);
    final long ui = (Long) AnyUtils.convertAny(AnyUtils.toAny(Integer.MAX_VALUE, TCKind.tk_ulong));
    Assert.assertEquals(Integer.MAX_VALUE, ui);
    final BigInteger ul = (BigInteger) AnyUtils.convertAny(AnyUtils.toAny(Long.MAX_VALUE, TCKind.tk_ulonglong));
    Assert.assertEquals(Long.MAX_VALUE, ul.longValue());

    /** TODO Big Decimal not supported
    final BigDecimal fix = (BigDecimal) AnyUtils.convertAny(AnyUtils.toAny(new BigDecimal(1.0), TCKind.tk_fixed));
    Assert.assertEquals(1.0, fix.doubleValue(), 0.00001);
    */

    Any tmpAny = (Any) AnyUtils.convertAny(AnyUtils.toAny(AnyUtils.toAny(1, TCKind.tk_long), TCKind.tk_any));
    Assert.assertNotNull(tmpAny);
    Assert.assertEquals(1, tmpAny.extract_long());
    /** TODO Why do these not work in Jacorb? **/
    //      tmpAny = (Any) AnyUtils.convertAny(AnyUtils.toAny(AnyUtils.toAny((short) 1, TCKind.tk_short), TCKind.tk_value));
    //      Assert.assertNotNull(tmpAny);
    //      Assert.assertEquals((short) 1, tmpAny.extract_short());
    //      final TypeCode tmpType = (TypeCode) AnyUtils.convertAny(AnyUtils.toAny(tmpAny.type(), TCKind.tk_TypeCode));
    //      Assert.assertNotNull(tmpType);
    //      Assert.assertEquals(TCKind._tk_short, tmpType.kind().value());
    //      final Object obj = AnyUtils.convertAny(null, tmpType);
    //      Assert.assertNull(obj);
}

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

public void testNullPrimitive() throws Exception {
        assertEquals(Boolean.FALSE, ParseUtils.parse(boolean.class, null));
        assertEquals(new Character((char) 0), ParseUtils.parse(char.class, null));
        assertEquals(new Byte((byte) 0), ParseUtils.parse(byte.class, null));
        assertEquals(new Short((short) 0), ParseUtils.parse(short.class, null));
        assertEquals(new Integer(0), ParseUtils.parse(int.class, null));
        assertEquals(new Long(0), ParseUtils.parse(long.class, null));
        assertEquals(new Float(0), ParseUtils.parse(float.class, null));
        assertEquals(new Double(0), ParseUtils.parse(double.class, null));
    }//from  w ww .  j  a  v  a 2 s. c  o m

From source file:org.sakaiproject.importer.impl.handlers.SamigoPoolHandler.java

private Collection doQuestions(List questions, String siteId) {
    AssessmentQuestion importableQuestion;
    AssessmentAnswer importableAnswer;/* w  ww.  ja  v  a 2 s .c  o m*/
    AssessmentAnswer importableChoice;
    Collection rv = new Vector();
    ItemFacade itemFacade = null;
    String questionTextString = null;
    ItemText text = null;
    HashSet textSet = null;
    Answer answer = null;
    HashSet answerSet = null;
    AnswerFeedback answerFeedback = null;
    HashSet answerFeedbackSet = null;
    int questionCount = 0;
    for (Iterator i = questions.iterator(); i.hasNext();) {
        importableQuestion = (AssessmentQuestion) i.next();
        questionCount++;
        Set correctAnswerIDs = importableQuestion.getCorrectAnswerIDs();
        itemFacade = new ItemFacade();
        itemFacade.setTypeId(new Long(importableQuestion.getQuestionType()));
        textSet = new HashSet();
        questionTextString = contextualizeUrls(importableQuestion.getQuestionText(), siteId);
        if (importableQuestion.getQuestionType() == SamigoPoolHandler.MATCHING) {
            itemFacade.setInstruction(questionTextString);
            Collection answers = importableQuestion.getAnswers().values();
            Collection choices = importableQuestion.getChoices().values();
            int answerIndex = 1;
            for (Iterator j = answers.iterator(); j.hasNext();) {
                importableAnswer = (AssessmentAnswer) j.next();
                text = new ItemText();
                text.setSequence(Long.valueOf(answerIndex));
                answerIndex++;
                text.setText(contextualizeUrls(importableAnswer.getAnswerText(), siteId));
                answerSet = new HashSet();
                int choiceIndex = 1;
                for (Iterator k = choices.iterator(); k.hasNext();) {
                    importableChoice = (AssessmentAnswer) k.next();
                    answer = new Answer();
                    answer.setItem(itemFacade.getData());
                    answer.setItemText(text);
                    answer.setSequence(new Long(choiceIndex));
                    choiceIndex++;
                    // set label A, B, C, D, etc. on answer based on its sequence number
                    answer.setLabel(new Character((char) (64 + choiceIndex)).toString());
                    answer.setText(contextualizeUrls(importableChoice.getAnswerText(), siteId));
                    answer.setIsCorrect(Boolean
                            .valueOf(importableAnswer.getChoiceId().equals(importableChoice.getAnswerId())));
                    answerSet.add(answer);
                }
                text.setAnswerSet(answerSet);
                text.setItem(itemFacade.getData());
                textSet.add(text);
            }
        } else {

            text = new ItemText();
            text.setSequence(new Long(1));
            text.setText(questionTextString);

            answerSet = new HashSet();
            answerFeedbackSet = new HashSet();
            Collection answers = importableQuestion.getAnswers().values();
            StringBuilder answerBuffer = new StringBuilder();
            for (Iterator j = answers.iterator(); j.hasNext();) {
                importableAnswer = (AssessmentAnswer) j.next();
                answerBuffer.append(importableAnswer.getAnswerText());
                if (j.hasNext())
                    answerBuffer.append("|");
                String answerId = importableAnswer.getAnswerId();
                answer = new Answer();
                answer.setItem(itemFacade.getData());
                answer.setItemText(text);
                answer.setSequence(new Long(importableAnswer.getPosition()));
                // set label A, B, C, D, etc. on answer based on its sequence number
                answer.setLabel(new Character((char) (64 + importableAnswer.getPosition())).toString());

                if (importableQuestion.getQuestionType() == SamigoPoolHandler.TRUE_FALSE) {
                    // Samigo only understands True/False answers in lower case
                    answer.setText(importableAnswer.getAnswerText().toLowerCase());
                } else if (importableQuestion.getQuestionType() == SamigoPoolHandler.FILL_BLANK_PLUS) {
                    answer.setText(importableAnswer.getAnswerText());
                    Pattern pattern = Pattern.compile("_+|<<.*>>");
                    Matcher matcher = pattern.matcher(questionTextString);
                    if (matcher.find())
                        questionTextString = questionTextString.replaceFirst(matcher.group(), "{}");
                    text.setText(questionTextString);
                    itemFacade.setTypeId(Long.valueOf(SamigoPoolHandler.FILL_BLANK));
                } else if (importableQuestion.getQuestionType() == SamigoPoolHandler.FILL_BLANK) {
                    if (j.hasNext())
                        continue;
                    answer.setText(answerBuffer.toString());
                    Pattern pattern = Pattern.compile("_+|<<.*>>");
                    Matcher matcher = pattern.matcher(questionTextString);
                    if (matcher.find())
                        questionTextString = questionTextString.replaceFirst(matcher.group(), "{}");
                    text.setText(questionTextString);
                    answer.setSequence(new Long(1));
                } else {
                    answer.setText(contextualizeUrls(importableAnswer.getAnswerText(), siteId));
                }

                answer.setIsCorrect(Boolean.valueOf(correctAnswerIDs.contains(answerId)));
                answerSet.add(answer);
            }
            text.setAnswerSet(answerSet);
            text.setItem(itemFacade.getData());
            textSet.add(text);
        }
        itemFacade.setItemTextSet(textSet);
        itemFacade.setCorrectItemFeedback(importableQuestion.getFeedbackWhenCorrect());
        itemFacade.setInCorrectItemFeedback(importableQuestion.getFeedbackWhenIncorrect());
        itemFacade.setScore(importableQuestion.getPointValue());
        itemFacade.setSequence(importableQuestion.getPosition());
        // status is 0=inactive or 1=active
        itemFacade.setStatus(Integer.valueOf(1));
        itemFacade.setHasRationale(Boolean.FALSE);
        itemFacade.setCreatedBy(SessionManager.getCurrentSessionUserId());
        itemFacade.setCreatedDate(new java.util.Date());
        itemFacade.setLastModifiedBy(SessionManager.getCurrentSessionUserId());
        itemFacade.setLastModifiedDate(new java.util.Date());
        itemService.saveItem(itemFacade);
        rv.add(itemFacade);

    }
    return rv;

}