List of usage examples for java.lang Character Character
@Deprecated(since = "9") public Character(char value)
From source file:org.jboss.dashboard.factory.PropertyChangeProcessingInstruction.java
protected Object getNewInstanceForClass(Class expectedClass) { log.debug("Creating 'empty' class of type " + expectedClass); Object object = null;/*from w w w . j a v a 2s . c o m*/ if (expectedClass.isArray()) { Class componentClass = expectedClass.getComponentType(); if (componentClass.isPrimitive()) { if (componentClass.equals(int.class)) object = new int[0]; else if (componentClass.equals(boolean.class)) object = new boolean[0]; else if (componentClass.equals(long.class)) object = new long[0]; else if (componentClass.equals(char.class)) object = new char[0]; else if (componentClass.equals(double.class)) object = new double[0]; else if (componentClass.equals(float.class)) object = new float[0]; else if (componentClass.equals(byte.class)) object = new byte[0]; else if (componentClass.equals(short.class)) object = new short[0]; } else if (String.class.equals(componentClass)) //Array of Strings object = new String[0]; else if (componentClass.equals(Integer.class)) object = new Integer[0]; else if (componentClass.equals(Boolean.class)) object = new Boolean[0]; else if (componentClass.equals(Long.class)) object = new Long[0]; else if (componentClass.equals(Character.class)) object = new Character[0]; else if (componentClass.equals(Double.class)) object = new Double[0]; else if (componentClass.equals(Float.class)) object = new Float[0]; else if (componentClass.equals(Byte.class)) object = new Byte[0]; else if (componentClass.equals(Short.class)) object = new Short[0]; else { //It will be an array of components object = Array.newInstance(componentClass, 0); } } else { if (String.class.equals(expectedClass)) object = ""; else if (expectedClass.equals(int.class)) object = new Integer(0); else if (expectedClass.equals(boolean.class)) object = new Boolean(false); else if (expectedClass.equals(long.class)) object = new Long(0); else if (expectedClass.equals(char.class)) object = new Character((char) 0); else if (expectedClass.equals(double.class)) object = new Double(0); else if (expectedClass.equals(float.class)) object = new Float(0); else if (expectedClass.equals(byte.class)) object = new Byte((byte) 0); else if (expectedClass.equals(short.class)) object = new Short((short) 0); else if (expectedClass.equals(Integer.class)) object = new Integer(0); else if (expectedClass.equals(Boolean.class)) object = new Boolean(false); else if (expectedClass.equals(Long.class)) object = new Long(0); else if (expectedClass.equals(Character.class)) object = new Character((char) 0); else if (expectedClass.equals(Double.class)) object = new Double(0); else if (expectedClass.equals(Float.class)) object = new Float(0); else if (expectedClass.equals(Byte.class)) object = new Byte((byte) 0); else if (expectedClass.equals(Short.class)) object = new Short((short) 0); else { //It will be a component object = null; } } return object; }
From source file:com.krawler.br.nodes.Activity.java
/** * converts the given object value to the given primitive type's wrapper class * if possible (if it is a <tt>Number</tt>) * * @param type the premitive type name, may be: * <ul>/* ww w . j a v a2 s . c o m*/ * <li><tt>byte</tt> * <li><tt>char</tt> * <li><tt>short</tt> * <li><tt>int</tt> * <li><tt>long</tt> * <li><tt>float</tt> * <li><tt>double</tt> * </ul> * @param value the original value * @return the converted value */ private Object convert(String type, Object value) { Object val = value; if (value instanceof Number) { Number num = (Number) value; if (Byte.class.getCanonicalName().equals(type)) val = new Byte(num.byteValue()); else if (Character.class.getCanonicalName().equals(type)) val = new Character((char) num.intValue()); else if (Short.class.getCanonicalName().equals(type)) val = new Short(num.shortValue()); else if (Integer.class.getCanonicalName().equals(type)) val = new Integer(num.intValue()); else if (Long.class.getCanonicalName().equals(type)) val = new Long(num.longValue()); else if (Float.class.getCanonicalName().equals(type)) val = new Float(num.floatValue()); else if (Double.class.getCanonicalName().equals(type)) val = new Double(num.doubleValue()); } return val; }
From source file:com.judoscript.jamaica.MyUtils.java
public static Object value2object(Object val, String typeHint) { if (typeHint == null) return val; if (typeHint.equals("boolean") || val instanceof Boolean) return val; // leave type check to caller. double v;// w ww .j av a 2 s. com if (val instanceof Character) v = ((Character) val).charValue(); else if (val instanceof Number) v = ((Number) val).doubleValue(); else return val; // leave type check to caller. if (typeHint.equals("int")) return new Integer((int) v); if (typeHint.equals("long")) return new Long((long) v); if (typeHint.equals("short")) return new Short((short) v); if (typeHint.equals("char")) return new Character((char) v); if (typeHint.equals("byte")) return new Byte((byte) v); if (typeHint.equals("float")) return new Float((float) v); // if (typeHint.equals("double")) return new Double(v); }
From source file:org.osaf.cosmo.eim.json.JsonStreamWriterTest.java
public void testUnicodeClob() throws Exception { String unicode = "\u2028\u2029"; String unicodeResult = "\\u2028\\u2029"; log.error("unicode: " + unicode); StringReader reader = new StringReader(unicode); //log.error("reader: " + IOUtils.toString(reader)); //log.error("json: " + JSONObject.valueToString(IOUtils.toString(reader))); ClobField field = new ClobField("unicode", reader); StringWriter out = new StringWriter(); JsonStreamWriter writer = new JsonStreamWriter(out); writer.getActual().object();//from ww w .j a va2 s . c o m writer.writeField(field); writer.getActual().endObject(); writer.close(); log.error("UTF-8 JSON: " + out); String jsonString = out.toString(); String preamble = "{\"unicode\":[\"clob\",\""; //get rid of the json stuff, just want the clob jsonString = jsonString.substring(preamble.length()); jsonString = jsonString.substring(0, jsonString.length() - 3); for (int x = 0; x < jsonString.length(); x++) { Character j = new Character(jsonString.charAt(x)); Character s = new Character(unicodeResult.charAt(x)); assertEquals(j, s); } assertEquals(unicodeResult, jsonString); }
From source file:net.sibcolombia.portal.web.tag.AlphabetLinkTag.java
/** * @see javax.servlet.jsp.tagext.TagSupport#doStartTag() *//*from w ww. j a v a 2 s .c o m*/ @Override public int doStartTag() throws JspException { Locale locale = RequestContextUtils.getLocale((HttpServletRequest) pageContext.getRequest()); if (letters == null || letters.isEmpty()) { return super.doStartTag(); } StringBuffer sb = new StringBuffer(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String contextPath = request.getContextPath(); List<Character> ignoreChars = new ArrayList<Character>(); if (StringUtils.isNotEmpty(ignores)) { ignores = ignores.trim(); StringTokenizer st = new StringTokenizer(ignores); while (st.hasMoreTokens()) { String ignoreChar = st.nextToken(); if (ignoreChar.length() != 1) { throw new JspException("Invalid ignore list :" + ignoreChar); } ignoreChars.add(new Character(ignoreChar.charAt(0))); } } sb.append("<ul class=\""); sb.append(listClass); sb.append("\">"); sb.append("<li class=\"lt\">"); letters.add(0, '0'); int indexOfSelected = letters.indexOf(selected); if (indexOfSelected > 0) { addLink(sb, contextPath, letters.get(indexOfSelected - 1), "<<"); } else { sb.append("<<"); } sb.append("</li>"); List<String> acceptedChars = Arrays.asList(accepted); for (Character letter : letters) { if (!ignoreChars.contains(letter) && acceptedChars.contains(letter.toString())) { sb.append("<li"); if (!(letter == '0')) { if (selected != letter) { sb.append('>'); addLink(sb, contextPath, letter); } else { sb.append(" id=\"chosen\">"); sb.append(letter); } } else { if (selected != letter) { sb.append('>'); addLink(sb, contextPath, '0', messageSource.getMessage("dataset.list.showall", null, "Todas", locale)); } else { sb.append(" id=\"chosen\">"); sb.append(messageSource.getMessage("dataset.list.showall", null, "Todas", locale)); } } sb.append("</li>"); } } sb.append("<li class=\"lt\">"); if (indexOfSelected < (letters.size() - 1)) { addLink(sb, contextPath, letters.get(indexOfSelected + 1), ">>"); } else { sb.append(">>"); } sb.append("</li>"); sb.append("</ul>"); try { pageContext.getOut().write(sb.toString()); } catch (IOException e) { throw new JspException(e); } return super.doStartTag(); }
From source file:com.aw.swing.mvp.validation.support.AWDefaultRulesSource.java
private static Character findNonDigit(String str) { for (int i = 0; i < str.length(); i++) { if (!Character.isDigit(str.charAt(i))) return new Character(str.charAt(i)); }/* ww w .ja v a 2s. c om*/ return null; }
From source file:org.mule.transport.jms.JmsMessageUtilsTestCase.java
@Test public void testStreamMessageSerialization() throws Exception { Session session = mock(Session.class); when(session.createStreamMessage()).thenReturn(new ActiveMQStreamMessage()); // Creates a test list with data List data = new ArrayList(); data.add(Boolean.TRUE);/*from www.j av a2 s . c om*/ data.add(new Byte("1")); data.add(new Short("2")); data.add(new Character('3')); data.add(new Integer("4")); // can't write Longs: https://issues.apache.org/activemq/browse/AMQ-1965 // data.add(new Long("5")); data.add(new Float("6")); data.add(new Double("7")); data.add(new String("8")); data.add(null); data.add(new byte[] { 9, 10 }); StreamMessage result = (StreamMessage) JmsMessageUtils.toMessage(data, session); // Resets so it's readable result.reset(); assertEquals(Boolean.TRUE, result.readObject()); assertEquals(new Byte("1"), result.readObject()); assertEquals(new Short("2"), result.readObject()); assertEquals(new Character('3'), result.readObject()); assertEquals(new Integer("4"), result.readObject()); // can't write Longs: https://issues.apache.org/activemq/browse/AMQ-1965 // assertEquals(new Long("5"), result.readObject()); assertEquals(new Float("6"), result.readObject()); assertEquals(new Double("7"), result.readObject()); assertEquals(new String("8"), result.readObject()); assertNull(result.readObject()); assertTrue(Arrays.equals(new byte[] { 9, 10 }, (byte[]) result.readObject())); }
From source file:org.floggy.synchronization.jme.core.impl.JSONSerializationManagerTest.java
/** * DOCUMENT ME!//from w ww . ja v a 2 s .c om * * @throws Exception DOCUMENT ME! */ public void testReceiveCharNotNull() throws Exception { JSONObject jsonObject = new JSONObject(); String name = "character"; Character value = new Character('F'); jsonObject.put(name, value); Character actual = JSONSerializationManager.receiveChar(name, jsonObject); assertEquals(value, actual); }
From source file:com.meiah.core.util.StringUtil.java
public static boolean endsWith(String s, char end) { return endsWith(s, (new Character(end)).toString()); }
From source file:de.javakaffee.web.msm.serializer.javolution.AaltoTranscoderTest.java
@DataProvider(name = "typesAsSessionAttributesProvider") protected Object[][] createTypesAsSessionAttributesData() { return new Object[][] { { int.class, 42 }, { long.class, 42 }, { Boolean.class, Boolean.TRUE }, { String.class, "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() }, { 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 } }, { boolean[].class, new boolean[] { true, false } }, { byte[].class, "42".getBytes() }, { char[].class, "42".toCharArray() }, { String[].class, new String[] { "23", "42" } }, { Person[].class, new Person[] { createPerson("foo bar", Gender.MALE, 42) } } }; }