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.acoveo.tools.Reflection.java

/**
 * Invoke the given setter on the given object.
 *///  ww  w . j  a v a  2 s  .c o  m
public static void set(Object target, Method setter, char value) {
    set(target, setter, new Character(value));
}

From source file:org.novoj.utils.datePattern.DatePatternConverter.java

/**
 * Converts Java DateFormat pattern to the jQueryUI DatePicker TimePicker addon Javascript format (or throws
 * PatternNotConvertableException)./*from  w w w .java 2s . c  o m*/
 * @param patternDecomposition
 * @param patternsA
 * @param patternsB
 * @param escapeInsideAllowed
 * @return
 * @throws PatternNotConvertableException
 */
@SuppressWarnings({ "ImplicitNumericConversion", "OverlyLongMethod", "OverlyComplexMethod" })
private String conversion(List<String> patternDecomposition, Map<String, String> patternsA,
        Map<String, String> patternsB, boolean escapeInsideAllowed) throws PatternNotConvertableException {
    boolean firstUsablePatternRecognized = false;
    boolean otherPatternRecognized = false;

    StringBuffer unknownPatterns = new StringBuffer();
    StringBuilder result = new StringBuilder();
    StringBuffer conditionalResult = new StringBuffer();
    for (String patternPart : patternDecomposition) {
        char leadLetter = patternPart.charAt(0);
        if (leadLetter == '\'') {
            if (firstUsablePatternRecognized && !escapeInsideAllowed) {
                throw new PatternNotConvertableException(
                        "Escaped parts in pattern are not allowed: " + patternPart);
            }
            //add escaped part without further analyzing it
            conditionalResult.append(patternPart);
        } else if (Character.isLetter(leadLetter)) {
            if (patternsA.containsKey(patternPart)) {
                firstUsablePatternRecognized = true;
                if (conditionalResult.length() > 0) {
                    if (otherPatternRecognized) {
                        conditionalResult = new StringBuffer();
                    } else {
                        result.append(conditionalResult);
                        conditionalResult = new StringBuffer();
                    }
                }
                result.append(patternsA.get(patternPart));
            } else if (patternsB.containsKey(patternPart)) {
                otherPatternRecognized = true;
                conditionalResult = new StringBuffer();
                if (firstUsablePatternRecognized) {
                    break;
                }
            } else {
                if (unknownPatterns.length() > 0) {
                    unknownPatterns.append(", ");
                }
                unknownPatterns.append(patternPart);
            }
        } else if (specialCharacters.contains(new Character(patternPart.charAt(0)))) {
            if (firstUsablePatternRecognized) {
                result.append(patternPart);
            }
        } else {
            conditionalResult.append(patternPart);
        }
    }

    if (unknownPatterns.length() > 0) {
        throw new PatternNotConvertableException(
                "Java pattern contains unconvertable chunks, that are not accepted by jQuery UI DatePicker: "
                        + unknownPatterns);
    }

    return result.toString();
}

From source file:org.apache.axis2.corba.receivers.CorbaUtil.java

public static Object extractValue(DataType returnType, Any returned) {
    Object returnValue = null;//ww w  .  jav a 2s.  c om
    TypeCode typeCode = returnType.getTypeCode();
    switch (typeCode.kind().value()) {
    case TCKind._tk_void:
        returnValue = null;
        break;
    case TCKind._tk_long:
        returnValue = new Integer(returned.extract_long());
        break;
    case TCKind._tk_ulong:
        returnValue = new Integer(returned.extract_ulong());
        break;
    case TCKind._tk_longlong:
        returnValue = new Long(returned.extract_longlong());
        break;
    case TCKind._tk_ulonglong:
        returnValue = new Long(returned.extract_ulonglong());
        break;
    case TCKind._tk_short:
        returnValue = new Short(returned.extract_short());
        break;
    case TCKind._tk_ushort:
        returnValue = new Short(returned.extract_ushort());
        break;
    case TCKind._tk_float:
        returnValue = new Float(returned.extract_float());
        break;
    case TCKind._tk_double:
        returnValue = new Double(returned.extract_double());
        break;
    case TCKind._tk_char:
        returnValue = new Character(returned.extract_char());
        break;
    case TCKind._tk_wchar:
        returnValue = new Character(returned.extract_wchar());
        break;
    case TCKind._tk_boolean:
        returnValue = Boolean.valueOf(returned.extract_boolean());
        break;
    case TCKind._tk_octet:
        returnValue = new Byte(returned.extract_octet());
        break;
    case TCKind._tk_string:
        returnValue = returned.extract_string();
        break;
    case TCKind._tk_wstring:
        returnValue = returned.extract_wstring();
        break;
    case TCKind._tk_any:
        returnValue = returned.extract_any();
        break;
    case TCKind._tk_value:
        returnValue = returned.extract_Value();
        break;
    case TCKind._tk_objref:
        returnValue = returned.extract_Object();
        break;
    //case TCKind._tk_longdouble :
    case TCKind._tk_struct:
        Struct struct = (Struct) returnType;
        StructValue structValue = new StructValue(struct);
        org.omg.CORBA_2_3.portable.InputStream inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned
                .create_input_stream();
        structValue.read(inputStream);
        returnValue = structValue;
        break;
    case TCKind._tk_except:
        ExceptionType exceptionType = (ExceptionType) returnType;
        ExceptionValue exceptionValue = new ExceptionValue(exceptionType);
        inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream();
        exceptionValue.read(inputStream);
        returnValue = exceptionValue;
        break;
    case TCKind._tk_enum:
        EnumType enumType = (EnumType) returnType;
        EnumValue enumValue = new EnumValue(enumType);
        inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream();
        enumValue.read(inputStream);
        returnValue = enumValue;
        break;
    case TCKind._tk_union:
        UnionType unionType = (UnionType) returnType;
        inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream();
        UnionValue unionValue = new UnionValue(unionType);
        unionValue.read(inputStream);
        returnValue = unionValue;
        break;
    case TCKind._tk_alias:
        Typedef typedef = (Typedef) returnType;
        inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream();
        AliasValue aliasValue = new AliasValue(typedef);
        aliasValue.read(inputStream);
        returnValue = aliasValue;
        break;
    case TCKind._tk_sequence:
        SequenceType sequenceType = (SequenceType) returnType;
        inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream();
        SequenceValue sequenceValue = new SequenceValue(sequenceType);
        sequenceValue.read(inputStream);
        returnValue = sequenceValue;
        break;
    case TCKind._tk_array:
        ArrayType arrayType = (ArrayType) returnType;
        inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream();
        ArrayValue arrayValue = new ArrayValue(arrayType);
        arrayValue.read(inputStream);
        returnValue = arrayValue;
        break;
    default:
        log.error("ERROR! Invalid dataType");
        break;
    }
    return returnValue;
}

From source file:com.krawler.portal.util.StringUtil.java

public static boolean startsWith(String s, char begin) {
    return startsWith(s, (new Character(begin)).toString());
}

From source file:org.apache.catalina.core.NamingContextListener.java

/**
 * Set the specified environment entries in the naming context.
 *///  w  w w  .j a v a 2 s . c om
public void addEnvironment(ContextEnvironment env) {

    Object value = null;
    // Instantiating a new instance of the correct object type, and
    // initializing it.
    String type = env.getType();
    try {
        if (type.equals("java.lang.String")) {
            value = env.getValue();
        } else if (type.equals("java.lang.Byte")) {
            if (env.getValue() == null) {
                value = new Byte((byte) 0);
            } else {
                value = Byte.decode(env.getValue());
            }
        } else if (type.equals("java.lang.Short")) {
            if (env.getValue() == null) {
                value = new Short((short) 0);
            } else {
                value = Short.decode(env.getValue());
            }
        } else if (type.equals("java.lang.Integer")) {
            if (env.getValue() == null) {
                value = new Integer(0);
            } else {
                value = Integer.decode(env.getValue());
            }
        } else if (type.equals("java.lang.Long")) {
            if (env.getValue() == null) {
                value = new Long(0);
            } else {
                value = Long.decode(env.getValue());
            }
        } else if (type.equals("java.lang.Boolean")) {
            value = Boolean.valueOf(env.getValue());
        } else if (type.equals("java.lang.Double")) {
            if (env.getValue() == null) {
                value = new Double(0);
            } else {
                value = Double.valueOf(env.getValue());
            }
        } else if (type.equals("java.lang.Float")) {
            if (env.getValue() == null) {
                value = new Float(0);
            } else {
                value = Float.valueOf(env.getValue());
            }
        } else if (type.equals("java.lang.Character")) {
            if (env.getValue() == null) {
                value = new Character((char) 0);
            } else {
                if (env.getValue().length() == 1) {
                    value = new Character(env.getValue().charAt(0));
                } else {
                    throw new IllegalArgumentException();
                }
            }
        } else {
            log(sm.getString("naming.invalidEnvEntryType", env.getName()));
        }
    } catch (NumberFormatException e) {
        log(sm.getString("naming.invalidEnvEntryValue", env.getName()));
    } catch (IllegalArgumentException e) {
        log(sm.getString("naming.invalidEnvEntryValue", env.getName()));
    }

    // Binding the object to the appropriate name
    if (value != null) {
        try {
            if (debug >= 2)
                log("  Adding environment entry " + env.getName());
            createSubcontexts(envCtx, env.getName());
            envCtx.bind(env.getName(), value);
        } catch (NamingException e) {
            log(sm.getString("naming.invalidEnvEntryValue", e));
        }
    }

}

From source file:net.sf.json.TestJSONObject.java

public void testFromObject_ObjectBean() {
    // FR 1611204
    ObjectBean bean = new ObjectBean();
    bean.setPbyte(Byte.valueOf("1"));
    bean.setPshort(Short.valueOf("1"));
    bean.setPint(Integer.valueOf("1"));
    bean.setPlong(Long.valueOf("1"));
    bean.setPfloat(Float.valueOf("1"));
    bean.setPdouble(Double.valueOf("1"));
    bean.setPchar(new Character('1'));
    bean.setPboolean(Boolean.TRUE);
    bean.setPstring("json");
    bean.setParray(new String[] { "a", "b" });
    bean.setPbean(new BeanA());
    List list = new ArrayList();
    list.add("1");
    list.add("2");
    bean.setPlist(list);//ww w .  j a va  2s  . co m
    Map map = new HashMap();
    map.put("string", "json");
    bean.setPmap(map);
    bean.setPfunction(new JSONFunction("this;"));

    JSONObject json = JSONObject.fromObject(bean);
    assertEquals(1, json.getInt("pbyte"));
    assertEquals(1, json.getInt("pshort"));
    assertEquals(1, json.getInt("pint"));
    assertEquals(1, json.getInt("plong"));
    assertEquals(1d, json.getDouble("pfloat"), 0d);
    assertEquals(1d, json.getDouble("pdouble"), 0d);
    assertTrue(json.getBoolean("pboolean"));
    assertEquals("json", json.get("pstring"));
    Assertions.assertEquals(JSONArray.fromObject("['a','b']"), json.getJSONArray("parray"));
    Assertions.assertEquals(JSONArray.fromObject("['1','2']"), json.getJSONArray("plist"));
    assertEquals("1", json.getString("pchar"));
    JSONObject b = new JSONObject().element("string", "json").element("integer", "42").element("bool", "true");
    Assertions.assertEquals(b, json.getJSONObject("pbean"));
    b = new JSONObject().element("string", "json");
    Assertions.assertEquals(b, json.getJSONObject("pmap"));
}

From source file:com.alibaba.wasp.jdbc.TestPreparedStatement.java

public void testObject() throws SQLException {
    Statement stat = conn.createStatement();
    ResultSet rs;/*from   www  .j  a  v  a  2s  .c  o  m*/
    stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
    stat.execute("INSERT INTO TEST VALUES(1, 'Hello')");
    PreparedStatement prep = conn
            .prepareStatement("SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? FROM TEST");
    prep.setObject(1, Boolean.TRUE);
    prep.setObject(2, "Abc");
    prep.setObject(3, new BigDecimal("10.2"));
    prep.setObject(4, new Byte((byte) 0xff));
    prep.setObject(5, new Short(Short.MAX_VALUE));
    prep.setObject(6, new Integer(Integer.MIN_VALUE));
    prep.setObject(7, new Long(Long.MAX_VALUE));
    prep.setObject(8, new Float(Float.MAX_VALUE));
    prep.setObject(9, new Double(Double.MAX_VALUE));
    prep.setObject(10, Date.valueOf("2001-02-03"));
    prep.setObject(11, Time.valueOf("04:05:06"));
    prep.setObject(12, Timestamp.valueOf("2001-02-03 04:05:06.123456789"));
    prep.setObject(13, new java.util.Date(Date.valueOf("2001-02-03").getTime()));
    prep.setObject(14, new byte[] { 10, 20, 30 });
    prep.setObject(15, new Character('a'), Types.OTHER);
    prep.setObject(16, "2001-01-02", Types.DATE);
    // converting to null seems strange...
    prep.setObject(17, "2001-01-02", Types.NULL);
    prep.setObject(18, "3.725", Types.DOUBLE);
    prep.setObject(19, "23:22:21", Types.TIME);
    prep.setObject(20, new java.math.BigInteger("12345"), Types.OTHER);
    rs = prep.executeQuery();
    rs.next();
    assertTrue(rs.getObject(1).equals(Boolean.TRUE));
    assertTrue(rs.getObject(2).equals("Abc"));
    assertTrue(rs.getObject(3).equals(new BigDecimal("10.2")));
    assertTrue(rs.getObject(4).equals((byte) 0xff));
    assertTrue(rs.getObject(5).equals(new Short(Short.MAX_VALUE)));
    assertTrue(rs.getObject(6).equals(new Integer(Integer.MIN_VALUE)));
    assertTrue(rs.getObject(7).equals(new Long(Long.MAX_VALUE)));
    assertTrue(rs.getObject(8).equals(new Float(Float.MAX_VALUE)));
    assertTrue(rs.getObject(9).equals(new Double(Double.MAX_VALUE)));
    assertTrue(rs.getObject(10).equals(Date.valueOf("2001-02-03")));
    assertEquals("04:05:06", rs.getObject(11).toString());
    assertTrue(rs.getObject(11).equals(Time.valueOf("04:05:06")));
    assertTrue(rs.getObject(12).equals(Timestamp.valueOf("2001-02-03 04:05:06.123456789")));
    assertTrue(rs.getObject(13).equals(Timestamp.valueOf("2001-02-03 00:00:00")));
    assertEquals(new byte[] { 10, 20, 30 }, (byte[]) rs.getObject(14));
    assertTrue(rs.getObject(15).equals('a'));
    assertTrue(rs.getObject(16).equals(Date.valueOf("2001-01-02")));
    assertTrue(rs.getObject(17) == null && rs.wasNull());
    assertTrue(rs.getObject(18).equals(new Double(3.725)));
    assertTrue(rs.getObject(19).equals(Time.valueOf("23:22:21")));
    assertTrue(rs.getObject(20).equals(new java.math.BigInteger("12345")));

    // } else if(x instanceof java.io.Reader) {
    // return session.createLob(Value.CLOB,
    // TypeConverter.getInputStream((java.io.Reader)x), 0);
    // } else if(x instanceof java.io.InputStream) {
    // return session.createLob(Value.BLOB, (java.io.InputStream)x, 0);
    // } else {
    // return ValueBytes.get(TypeConverter.serialize(x));

    stat.execute("DROP TABLE TEST");

}

From source file:org.gbif.portal.dao.resources.impl.hibernate.DataResourceDAOImpl.java

/**
 * @see org.gbif.portal.dao.resources.DataResourceDAO#getDatasetAlphabet()
 *///from   www  . jav  a  2  s  .  c  o m
@SuppressWarnings("unchecked")
public List<Character> getDatasetAlphabet() {
    HibernateTemplate template = getHibernateTemplate();
    List<String> dataResourceChars = (List<String>) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            Query query = session.createSQLQuery(
                    "select distinct(SUBSTRING(display_name,1,1)) from data_resource where display_name is not null and deleted is null order by display_name");
            return query.list();
        }
    });
    List<String> dataProviderChars = (List<String>) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            Query query = session.createSQLQuery(
                    "select distinct(SUBSTRING(name,1,1)) from data_provider where name is not null order by name");
            return query.list();
        }
    });
    /*
     * SIB Colombia Edit, do not search resourceNetworks
     */
    /*
     * List<String> resourceNetworksChars = (List<String>) template.execute(new HibernateCallback() {
     * public Object doInHibernate(Session session) {
     * Query query =
     * session
     * .createSQLQuery("select distinct(SUBSTRING(name,1,1)) from resource_network where name is not null order by name")
     * ;
     * return query.list();
     * }
     * });
     */

    ArrayList<Character> chars = new ArrayList<Character>();
    for (String result : dataResourceChars) {
        if (StringUtils.isNotEmpty(result))
            chars.add(new Character(Character.toUpperCase(result.charAt(0))));
    }
    for (String result : dataProviderChars) {
        if (StringUtils.isNotEmpty(result)) {
            Character theChar = new Character(Character.toUpperCase(result.charAt(0)));
            if (!chars.contains(theChar))
                chars.add(theChar);
        }
    }
    /*
     * SIB Colombia Edit, do not search resourceNetworks
     */
    /*
     * for (String result : resourceNetworksChars) {
     * if (StringUtils.isNotEmpty(result)) {
     * Character theChar = new Character(Character.toUpperCase(result.charAt(0)));
     * if (!chars.contains(theChar))
     * chars.add(theChar);
     * }
     * }
     */

    Collections.sort(chars);
    return chars;
}

From source file:de.javakaffee.kryoserializers.KryoTest.java

@DataProvider(name = "typesAsSessionAttributesProvider")
protected Object[][] createTypesAsSessionAttributesData() {
    return new Object[][] { { Boolean.class, Boolean.TRUE }, { String.class, "42" },
            { StringBuilder.class, new StringBuilder("42") }, { StringBuffer.class, new StringBuffer("42") },
            { Class.class, String.class }, { Long.class, new Long(42) }, { Integer.class, new Integer(42) },
            { Character.class, new Character('c') }, { Byte.class, new Byte("b".getBytes()[0]) },
            { Double.class, new Double(42d) }, { Float.class, new Float(42f) },
            { Short.class, new Short((short) 42) }, { BigDecimal.class, new BigDecimal(42) },
            { AtomicInteger.class, new AtomicInteger(42) }, { AtomicLong.class, new AtomicLong(42) },
            { MutableInt.class, new MutableInt(42) }, { Integer[].class, new Integer[] { 42 } },
            { Date.class, new Date(System.currentTimeMillis() - 10000) },
            { Calendar.class, Calendar.getInstance() }, { Currency.class, Currency.getInstance("EUR") },
            { ArrayList.class, new ArrayList<String>(Arrays.asList("foo")) },
            { int[].class, new int[] { 1, 2 } }, { long[].class, new long[] { 1, 2 } },
            { short[].class, new short[] { 1, 2 } }, { float[].class, new float[] { 1, 2 } },
            { double[].class, new double[] { 1, 2 } }, { int[].class, new int[] { 1, 2 } },
            { byte[].class, "42".getBytes() }, { char[].class, "42".toCharArray() },
            { String[].class, new String[] { "23", "42" } },
            { Person[].class, new Person[] { createPerson("foo bar", Gender.MALE, 42) } } };
}

From source file:org.fhcrc.cpl.viewer.gui.MRMDialog.java

public void AQUAinitializations() {
    if (transDefHeader == null || transDefHeader.getAQUApairs() == null)
        return;//from  ww  w. j  a v  a 2  s .  c  o  m
    for (TransitionDefinitionHeader.AQUApair aqp : transDefHeader.getAQUApairs().values()) {
        if (aqp.getHeavyMember().getAssociatedProduct() == null
                || aqp.getLightMember().getAssociatedProduct() == null)
            continue;
        MRMDaughter light = aqp.getLightMember().getAssociatedProduct();
        MRMDaughter heavy = aqp.getHeavyMember().getAssociatedProduct();
        if (light.getBestElutionCurve() == null || heavy.getBestElutionCurve() == null)
            continue;
        ElutionCurve lec = light.getBestElutionCurve();
        ElutionCurve hec = heavy.getBestElutionCurve();
        Float lhratio = new Float(lec.getAUC() / hec.getAUC());
        ((PeaksTableModel) (peaksTable.getModel())).setValueAt(
                new Character(aqp.getLightMember().getLowOrHigh()).toString(), light.getElutionDataTableRow(),
                peaksData.Label.colno);
        ((PeaksTableModel) (peaksTable.getModel())).setValueAt(
                new Character(aqp.getHeavyMember().getLowOrHigh()).toString(), heavy.getElutionDataTableRow(),
                peaksData.Label.colno);
        ((PeaksTableModel) (peaksTable.getModel())).setValueAt(lhratio, light.getElutionDataTableRow(),
                peaksData.LHRatio.colno);
        ((PeaksTableModel) (peaksTable.getModel())).setValueAt(lhratio, heavy.getElutionDataTableRow(),
                peaksData.LHRatio.colno);
    }
}