List of usage examples for java.lang Character Character
@Deprecated(since = "9") public Character(char value)
From source file:com.edmunds.autotest.AutoTestGetterSetter.java
private static Map<Class<?>, Object> createDefaultValueMap() { Map<Class<?>, Object> valueMap = new HashMap<Class<?>, Object>(); valueMap.put(byte.class, new Byte((byte) 0)); valueMap.put(short.class, new Short((short) 0)); valueMap.put(int.class, new Integer(0)); valueMap.put(long.class, new Long(0)); valueMap.put(float.class, new Float(0)); valueMap.put(double.class, new Double(0)); valueMap.put(boolean.class, Boolean.FALSE); valueMap.put(char.class, new Character((char) 0)); valueMap.put(Byte.class, new Byte((byte) 0)); valueMap.put(Short.class, new Short((short) 0)); valueMap.put(Integer.class, new Integer(0)); valueMap.put(Long.class, new Long(0)); valueMap.put(Float.class, new Float(0)); valueMap.put(Double.class, new Double(0)); valueMap.put(Boolean.class, Boolean.FALSE); valueMap.put(Character.class, new Character((char) 0)); return valueMap; }
From source file:org.latticesoft.util.common.ClassUtil.java
/** * Instantiate a new object from a string value * //from ww w . j a v a2 s . c o m */ public static Object newInstance(String type, String value, String format) { Object o = null; Class clazz = null; if (type == null || value == null) { return null; } if (type.equals("java.lang.String")) { return value; } try { clazz = Class.forName(type); if ("java.lang.Character".equals(type)) { o = new Character(value.charAt(0)); } else if ("java.util.Date".equals(type) || "java.sql.Time".equals(type) || "java.sql.Timestamp".equals(type)) { if (format == null) { format = "yyyy-MM-dd HH:mm:ss.SSS"; } DateFormat fmt = new SimpleDateFormat(format); try { o = fmt.parse(value); } catch (ParseException pe) { } if (o != null && "java.sql.Time".equals(type)) { Date d = (Date) o; o = new Time(d.getTime()); } if (o != null && "java.sql.Timestamp".equals(type)) { Date d = (Date) o; o = new Timestamp(d.getTime()); } } } catch (Exception e) { e.printStackTrace(); } if (o != null) return o; try { Method[] m = clazz.getMethods(); for (int i = 0; i < m.length; i++) { if ("fromString".equalsIgnoreCase(m[i].getName())) { Object[] args = { value }; o = m[i].invoke(clazz, args); break; } else if ("parse".equalsIgnoreCase(m[i].getName())) { Object[] args = { value }; o = m[i].invoke(clazz, args); break; } else if ("newInstance".equalsIgnoreCase(m[i].getName())) { Object[] args = { value }; o = m[i].invoke(clazz, args); break; } else if ("valueOf".equalsIgnoreCase(m[i].getName())) { Object[] args = { value }; o = m[i].invoke(clazz, args); break; } } } catch (Exception e) { } if (o != null) { return o; } try { Constructor[] c = clazz.getConstructors(); for (int i = 0; i < c.length; i++) { Class[] param = c[i].getParameterTypes(); if (param != null && param.length == 1 && param[0].getName().equals("java.lang.String")) { Object[] args = { value }; o = c[i].newInstance(args); } } } catch (Exception e) { } if (o == null) { o = value; } return o; }
From source file:org.apache.struts.action.DynaActionForm.java
/** * <p>Return the value of a simple property with the specified name.</p> * * @param name Name of the property whose value is to be retrieved * @return The value of a simple property with the specified name. * @throws IllegalArgumentException if there is no property of the * specified name * @throws NullPointerException if the type specified for the property * is invalid *//*from w w w . j a v a 2s . c om*/ public Object get(String name) { // Return any non-null value for the specified property Object value = dynaValues.get(name); if (value != null) { return (value); } // Return a null value for a non-primitive property Class type = getDynaProperty(name).getType(); if (type == null) { throw new NullPointerException("The type for property " + name + " is invalid"); } if (!type.isPrimitive()) { return (value); } // Manufacture default values for primitive properties if (type == Boolean.TYPE) { return (Boolean.FALSE); } else if (type == Byte.TYPE) { return (new Byte((byte) 0)); } else if (type == Character.TYPE) { return (new Character((char) 0)); } else if (type == Double.TYPE) { return (new Double(0.0)); } else if (type == Float.TYPE) { return (new Float((float) 0.0)); } else if (type == Integer.TYPE) { return (new Integer(0)); } else if (type == Long.TYPE) { return (new Long(0)); } else if (type == Short.TYPE) { return (new Short((short) 0)); } else { return (null); } }
From source file:com.jada.admin.contactus.ContactUsMaintAction.java
public ActionForward save(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Throwable { EntityManager em = JpaConnection.getInstance().getCurrentEntityManager(); boolean insertMode = false; ContactUsMaintActionForm form = (ContactUsMaintActionForm) actionForm; if (form.getMode().equals("C")) { insertMode = true;/*from www . jav a2 s.c o m*/ } AdminBean adminBean = getAdminBean(request); Site site = adminBean.getSite(); initSiteProfiles(form, site); ContactUs contactUs = new ContactUs(); if (!insertMode) { contactUs = ContactUsDAO.load(site.getSiteId(), Format.getLong(form.getContactUsId())); } ActionMessages errors = validate(form, site.getSiteId()); if (errors.size() != 0) { saveMessages(request, errors); initSearchInfo(form, site.getSiteId()); return mapping.findForward("error"); } if (insertMode) { contactUs.setSite(site); contactUs.setRecCreateBy(adminBean.getUser().getUserId()); contactUs.setRecCreateDatetime(new Date(System.currentTimeMillis())); } contactUs.setActive(new Character(Constants.ACTIVE_NO)); if (form.getActive() != null && form.getActive().equals(String.valueOf(Constants.ACTIVE_YES))) { contactUs.setActive(new Character(Constants.ACTIVE_YES)); } contactUs.setContactUsEmail(form.getContactUsEmail()); contactUs.setContactUsPhone(form.getContactUsPhone()); contactUs.setContactUsAddressLine1(form.getContactUsAddressLine1()); contactUs.setContactUsAddressLine2(form.getContactUsAddressLine2()); contactUs.setContactUsCityName(form.getContactUsCityName()); contactUs.setContactUsStateCode(form.getContactUsStateCode()); String stateName = Utility.getStateName(site.getSiteId(), form.getContactUsStateCode()); if (stateName == null) { stateName = ""; } contactUs.setContactUsStateName(stateName); contactUs.setContactUsCountryCode(form.getContactUsCountryCode()); contactUs.setContactUsCountryName(Utility.getCountryName(site.getSiteId(), form.getContactUsCountryCode())); contactUs.setContactUsZipCode(form.getContactUsZipCode()); if (!Format.isNullOrEmpty(form.getSeqNum())) { contactUs.setSeqNum(Format.getIntObj(form.getSeqNum())); } else { contactUs.setSeqNum(new Integer(0)); } contactUs.setRecUpdateBy(adminBean.getUser().getUserId()); contactUs.setRecUpdateDatetime(new Date(System.currentTimeMillis())); if (form.isSiteProfileClassDefault()) { saveDefault(contactUs, form, adminBean); } else { saveLanguage(contactUs, form, adminBean); } if (insertMode) { em.persist(contactUs); } else { // em.update(contactUs); } form.setContactUsId(Format.getLong(contactUs.getContactUsId())); form.setMode("U"); initSearchInfo(form, site.getSiteId()); FormUtils.setFormDisplayMode(request, form, FormUtils.EDIT_MODE); return mapping.findForward("success"); }
From source file:jp.terasoluna.fw.web.struts.reset.ResetterImpl.java
/** * ANVtH?[wv?peBZbg?B//from www. j a v a2 s .co m * v?peB^boolean^?ABoolean^??false??B * v~eBu^bp?[^???A0??B * v?peB^bp?[^OObject^??null??B<br> * ??A?entrynulln?B * * @param form ?NGXggpANVtH?[ * @param entry Zbg?v?peB?lGg * @throws PropertyAccessException v?peBl?s?? */ protected void resetValue(FormEx form, Entry<String, Object> entry) { if (log.isDebugEnabled()) { log.debug("resetValue(" + form + ", " + entry.getKey() + ") called."); } String propName = entry.getKey(); try { Object value = entry.getValue(); if (value == null) { return; } Class type = null; type = value.getClass(); if (type != null) { // ^???B if (type == Boolean.TYPE || type == Boolean.class) { BeanUtil.setBeanProperty(form, propName, Boolean.FALSE); } else if (type == Byte.TYPE || type == Byte.class) { BeanUtil.setBeanProperty(form, propName, new Byte((byte) 0)); } else if (type == Character.TYPE || type == Character.class) { BeanUtil.setBeanProperty(form, propName, new Character((char) 0)); } else if (type == Double.TYPE || type == Double.class) { BeanUtil.setBeanProperty(form, propName, new Double(0.0)); } else if (type == Float.TYPE || type == Float.class) { BeanUtil.setBeanProperty(form, propName, new Float((float) 0.0)); } else if (type == Integer.TYPE || type == Integer.class) { BeanUtil.setBeanProperty(form, propName, new Integer(0)); } else if (type == Long.TYPE || type == Long.class) { BeanUtil.setBeanProperty(form, propName, new Long(0)); } else if (type == Short.TYPE || type == Short.class) { BeanUtil.setBeanProperty(form, propName, new Short((short) 0)); } else { // v~eBu^?Abp?[^??null? BeanUtil.setBeanProperty(form, propName, null); } } } catch (PropertyAccessException e) { log.error("cannot access property " + form + "." + propName, e); } }
From source file:mitm.application.djigzo.tools.ProxyManager.java
private void handleCommandline(String[] args) throws Exception { CommandLineParser parser = new BasicParser(); Options options = createCommandLineOptions(); HelpFormatter formatter = new HelpFormatter(); CommandLine commandLine;//w w w . j a v a 2 s .co m try { commandLine = parser.parse(options, args); } catch (ParseException e) { formatter.printHelp(COMMAND_NAME, options, true); throw e; } if (commandLine.getOptions().length == 0 || commandLine.hasOption("help")) { formatter.printHelp(COMMAND_NAME, options, true); System.exit(2); } user = commandLine.getOptionValue("user"); password = commandLine.getOptionValue("password"); if (commandLine.hasOption("pwd")) { System.err.println("Please enter password: "); password = new jline.ConsoleReader().readLine(new Character('*')); } if (commandLine.hasOption("get")) { handleGet(); } }
From source file:org.vertx.java.http.eventbusbridge.integration.MessageSendWithReplyTest.java
@Test public void testSendingCharacterJsonWithResponseJson() throws IOException { final EventBusMessageType messageType = EventBusMessageType.Character; final Character sentCharacter = new Character('T'); int port = findFreePort(); String responseUrl = createHttpServerUrl(port); Map<String, String> expectations = createExpectations("someaddress", Base64.encodeAsString(sentCharacter.toString()), messageType, responseUrl, MediaType.APPLICATION_JSON); String responseBody = TemplateHelper.generateOutputUsingTemplate(SEND_RESPONSE_TEMPLATE_JSON, expectations); createHttpServer(port, MediaType.APPLICATION_JSON, responseBody); Handler<Message> messageConsumerHandler = new MessageSendWithReplyHandler(sentCharacter, expectations); vertx.eventBus().registerHandler(expectations.get("address"), messageConsumerHandler); String requestBody = TemplateHelper.generateOutputUsingTemplate(SEND_REQUEST_TEMPLATE_JSON, expectations); HttpRequestHelper.sendHttpPostRequest(url, requestBody, (VertxInternal) vertx, Status.ACCEPTED.getStatusCode(), MediaType.APPLICATION_JSON); }
From source file:de.odysseus.calyxo.base.util.ParseUtils.java
public void testObject() 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(Character.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(Integer.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")); assertEquals(new BigInteger("10"), ParseUtils.parse(BigInteger.class, "10")); assertEquals(new BigDecimal(10), ParseUtils.parse(BigDecimal.class, "10")); assertEquals(new Date(0), ParseUtils.parse(Date.class, "1/1/70")); assertEquals("foo", ParseUtils.parse(String.class, "foo")); }//from w w w.j av a 2s . c om
From source file:org.apache.directory.server.tools.commands.exportcmd.ExportCommandExecutor.java
private void execute() throws Exception { // Connecting to server and retreiving entries NamingEnumeration entries = connectToServerAndGetEntries(); // Creating destination file File destionationFile = new File(ldifFileName); // Deleting the destination file if it already exists if (destionationFile.exists()) { destionationFile.delete();// ww w .j a v a 2s . co m } // Creating the writer to generate the LDIF file FileWriter fw = new FileWriter(ldifFileName, true); BufferedWriter writer = new BufferedWriter(fw); OtcLdifComposerImpl composer = new OtcLdifComposerImpl(); MultiValueMap map = new MultiValueMap(); // MultiMap map = new MultiMap() { // // FIXME Stop forking commons-collections. // private final MultiValueMap map = new MultiValueMap(); // // public Object remove(Object arg0, Object arg1) { // return map.remove(arg0, arg1); // } // // public int size() { // return map.size(); // } // // public Object get(Object arg0) { // return map.get(arg0); // } // // public boolean containsValue(Object arg0) { // return map.containsValue(arg0); // } // // public Object put(Object arg0, Object arg1) { // return map.put(arg0, arg1); // } // // public Object remove(Object arg0) { // return map.remove(arg0); // } // // public Collection values() { // return map.values(); // } // // public boolean isEmpty() { // return map.isEmpty(); // } // // public boolean containsKey(Object key) { // return map.containsKey(key); // } // // public void putAll(Map arg0) { // map.putAll(arg0); // } // // public void clear() { // map.clear(); // } // // public Set keySet() { // return map.keySet(); // } // // public Set entrySet() { // return map.entrySet(); // } // }; int entriesCounter = 1; long t0 = System.currentTimeMillis(); while (entries.hasMoreElements()) { SearchResult sr = (SearchResult) entries.nextElement(); Attributes attributes = sr.getAttributes(); NamingEnumeration attributesEnumeration = attributes.getAll(); map.clear(); while (attributesEnumeration.hasMoreElements()) { Attribute attr = (Attribute) attributesEnumeration.nextElement(); NamingEnumeration e2 = null; e2 = attr.getAll(); while (e2.hasMoreElements()) { Object value = e2.nextElement(); map.put(attr.getID(), value); } } // Writing entry in the file writer.write("dn: " + sr.getNameInNamespace() + "\n"); writer.write(composer.compose(map) + "\n"); notifyEntryWrittenListener(sr.getNameInNamespace()); entriesCounter++; if (entriesCounter % 10 == 0) { notifyOutputListener(new Character('.')); } if (entriesCounter % 500 == 0) { notifyOutputListener("" + entriesCounter); } } writer.flush(); writer.close(); fw.close(); long t1 = System.currentTimeMillis(); notifyOutputListener("Done!"); notifyOutputListener(entriesCounter + " entries exported in " + ((t1 - t0) / 1000) + " seconds"); }
From source file:com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.java
private Object doConvertToCharacter(Object value) { if (value instanceof String) { String cStr = (String) value; return (cStr.length() > 0) ? new Character(cStr.charAt(0)) : null; }//from www.j av a2 s . c om return null; }