List of usage examples for java.lang String getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:ClassInfoDemo1.java
public static void main(String[] args) { String s = ""; Class c = s.getClass(); System.out.println(c.getName()); c = new ClassInfoDemo1().getClass(); System.out.println(c.getName()); }
From source file:Main.java
public static void main(String[] args) { String str = "This is from java2s.com"; Class cls = str.getClass(); boolean arr = cls.isArray(); System.out.println(arr);/*from w w w. j av a 2 s. co m*/ Object array = Array.newInstance(int.class, 3); Class type = array.getClass(); if (type.isArray()) { Class elementType = type.getComponentType(); System.out.println("Array of: " + elementType); System.out.println("Array size: " + Array.getLength(array)); } }
From source file:com.glaf.core.util.JsonUtils.java
public static void main(String[] args) throws Exception { Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); dataMap.put("key01", ""); dataMap.put("key02", 12345); dataMap.put("key03", 789.85D); dataMap.put("date", new Date()); Collection<Object> actorIds = new HashSet<Object>(); actorIds.add("sales01"); actorIds.add("sales02"); actorIds.add("sales03"); actorIds.add("sales04"); actorIds.add("sales05"); dataMap.put("actorIds", actorIds.toArray()); dataMap.put("x_sale_actor_actorIds", actorIds); Map<String, Object> xxxMap = new java.util.HashMap<String, Object>(); xxxMap.put("0", "--------"); xxxMap.put("1", "?"); xxxMap.put("2", ""); xxxMap.put("3", ""); dataMap.put("trans", xxxMap); String str = JsonUtils.encode(dataMap); System.out.println(str);//from ww w . j a va 2 s .com Map<?, ?> p = JsonUtils.decode(str); System.out.println(p); System.out.println(p.get("date").getClass().getName()); String xx = "{name:\"trans\",nodeType:\"select\",children:{\"1\":\"?\",\"3\":\"\",\"2\":\"\",\"0\":\"--------\"}}"; Map<String, Object> xMap = JsonUtils.decode(xx); System.out.println(xMap); Set<Entry<String, Object>> entrySet = xMap.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); System.out.println(key + " = " + value); System.out.println(key.getClass().getName() + " " + value.getClass().getName()); if (value instanceof JSONObject) { JSONObject json = (JSONObject) value; Iterator<?> iter = json.keySet().iterator(); while (iter.hasNext()) { String kk = (String) iter.next(); System.out.println(kk + " = " + json.get(kk)); } } } }
From source file:net.trust.datacollection.thread.DataCollectionThread.java
public static void main(String arg[]) { String a = "111"; System.out.println(a.getClass().getName()); // DataCollectionThread dataCollectionThread = new DataCollectionThread(); // String sql = "INSERT INTO INTER_CAR_INFO"+ // " (INTER_CAR_INFO_ID,"+ // " CAR_MARK,"+ // " CARID,"+ // " CAR_GROUP,"+ // " CAR_CLASS,"+ // " CAR_TYPE,"+ // " MOTORID,"+ // " GSM_NUMBER,"+ // " CAR_COLOR,"+ // " COMPANYID,"+ // " INSTALL_TIME,"+ // " CAR_STATUS,"+ // " LICENSE,"+ // " REGIST_AGENT,"+ // " REGIST_TIME,"+ // " ACCIDENT_DATE,"+ // " CAR_MUSTERTIME,"+ // " CAR_MUSTERFLAG,"+ // " LAST_LON,"+ // " LAST_LAT,"+ // " LAST_SPEED,"+ // " LAST_ANGLE,"+ // " LAST_TIME,"+ // " LAST_FLAG,"+ // " TERMINAL_VER,"+ // " TERMINAL_UPDATE_TIME,"+ // " MAX_SPEED,"+ // " INBOUND_LIMIT,"+ // " OUTBOUND_LIMIT,"+ // " TERMINAL_REPORT,"+ // " TERMINAL_REPORT_TIME,"+ // " LAST_LOCATION,"+ // " UPDATE_RECORD_DATE)"+ // " VALUES"+ // " (pb_get_sequences(@in_seq_name:='INTER_CAR_INFO_ID'),"+ // " '::CAR_MARK::',"+ // " ::CARID::,"+ // " ::CAR_GROUP::,"+ // " ::CAR_CLASS::,"+ // " '::CAR_TYPE::',"+ // " '::MOTORID::',"+ // " '::GSM_NUMBER::',"+ // " '::CAR_COLOR::',"+ // " '::COMPANYID::',"+ // " '::INSTALL_TIME::',"+ // " '::CAR_STATUS::',"+ // " '::LICENSE::',"+ // " '::REGIST_AGENT::',"+ // " '::REGIST_TIME::',"+ // " '::ACCIDENT_DATE::',"+ // " '::CAR_MUSTERTIME::',"+ // " '::CAR_MUSTERFLAG::',"+ // " ::LAST_LON::,"+ // " ::LAST_LAT::,"+ // " ::LAST_SPEED::,"+ // " ::LAST_ANGLE::,"+ // " '::LAST_TIME::',"+ // " ::LAST_FLAG::,"+ // " ::TERMINAL_VER::,"+ // " '::TERMINAL_UPDATE_TIME::',"+ // " ::MAX_SPEED::,"+ // " ::INBOUND_LIMIT::,"+ // " ::OUTBOUND_LIMIT::,"+ // " ::TERMINAL_REPORT::,"+ // " '::TERMINAL_REPORT_TIME::',"+ // " '::LAST_LOCATION::',"+ // " NOW())"; // List list = dataCollectionThread.createField(sql); // System.out.println(list); // sql = " UPDATE inter_car_info"+ // " SET CAR_GROUP = ::CAR_GROUP::,"+ // " CAR_CLASS = ::CAR_CLASS::,"+ // " CAR_TYPE = ''::CAR_TYPE::'',"+ // " MOTORID = ''::MOTORID::'',"+ // " GSM_NUMBER = ''::GSM_NUMBER::'',"+ // " CAR_COLOR = ''::CAR_COLOR::'',"+ // " COMPANYID = ''::COMPANYID::'',"+ // " INSTALL_TIME = ''::INSTALL_TIME::'',"+ // " CAR_STATUS = ''::CAR_STATUS::'',"+ // " LICENSE = ''::LICENSE::'',"+ // " REGIST_AGENT = ''::REGIST_AGENT::'',"+ // " REGIST_TIME = ''::REGIST_TIME::'',"+ // " ACCIDENT_DATE = ''::ACCIDENT_DATE::'',"+ // " CAR_MUSTERTIME = ''::CAR_MUSTERTIME::'',"+ // " CAR_MUSTERFLAG = ''::CAR_MUSTERFLAG::'',"+ // " LAST_LON = ::LAST_LON::,"+ // " LAST_LAT = ::LAST_LAT::,"+ // " LAST_SPEED = ::LAST_SPEED::,"+ // " LAST_ANGLE = ::LAST_ANGLE::,"+ // " LAST_TIME = ''::LAST_TIME::'',"+ // " LAST_FLAG = ::LAST_FLAG::,"+ // " TERMINAL_VER = ::TERMINAL_VER::,"+ // " TERMINAL_UPDATE_TIME = ''::TERMINAL_UPDATE_TIME::'',"+ // " MAX_SPEED = ::MAX_SPEED::,"+ // " INBOUND_LIMIT = ::INBOUND_LIMIT::,"+ // " OUTBOUND_LIMIT = ::OUTBOUND_LIMIT::,"+ // " TERMINAL_REPORT = ::TERMINAL_REPORT::,"+ // " TERMINAL_REPORT_TIME = ''::TERMINAL_REPORT_TIME::'',"+ // " LAST_LOCATION = ''::LAST_LOCATION::'',"+ // " UPDATE_RECORD_DATE = NOW()"+ // " WHERE CAR_MARK = ''::CAR_MARK::''"+ // " AND CARID = ::CARID::"; // list = dataCollectionThread.createField(sql); // System.out.println(list); }
From source file:Main.java
/** * @param <T>/*w w w . ja va 2 s . c o m*/ * the type we want to convert the XML into * @param c * the class of the parameterized type * @param xml * the instance XML description * @return a deserialization of the XML into an object of type T of class * class <T> * @throws javax.xml.bind.JAXBException */ @SuppressWarnings("unchecked") public static <T> T unmarshal(Class<T> c, String xml) throws JAXBException { T res; if (c == xml.getClass()) { res = (T) xml; } else { JAXBContext ctx = JAXBContext.newInstance(c); Unmarshaller marshaller = ctx.createUnmarshaller(); res = (T) marshaller.unmarshal(new StringReader(xml)); } return res; }
From source file:com.adaptris.core.fs.FsHelper.java
public static FileFilter createFilter(String filterExpression, String filterImpl) throws Exception { FileFilter result = null;/*w w w.j av a 2 s. co m*/ if (isEmpty(filterExpression)) { result = new NoOpFileFilter(); } else { Class[] paramTypes = { filterExpression.getClass() }; Object[] args = { filterExpression }; Class c = Class.forName(filterImpl); Constructor cnst = c.getDeclaredConstructor(paramTypes); result = (FileFilter) cnst.newInstance(args); } return logWarningIfRequired(result); }
From source file:ninja.utils.SwissKnife.java
/** * Convert value to class type value./* ww w .java 2 s . com*/ * * If something goes wrong it returns null. * * @param from string value * @param to type of the class * @return class type value or null if something goes wrong. */ public static <T> T convert(String from, Class<T> to) { Class<T> toAsNonPrimitiveType; if (from == null) { return null; } T t = null; toAsNonPrimitiveType = Primitives.wrap(to); if (toAsNonPrimitiveType.isAssignableFrom(from.getClass())) { return toAsNonPrimitiveType.cast(from); } Method converter = CONVERTERS.get(toAsNonPrimitiveType.getName()); if (converter == null) { logger.error( "No converter found to convert {}. " + "Returning null. " + "You may want to extend the class.", toAsNonPrimitiveType); } else { try { t = toAsNonPrimitiveType.cast(converter.invoke(toAsNonPrimitiveType, from)); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { logger.error("Cannot convert from " + from.getClass().getName() + " to " + toAsNonPrimitiveType.getName() + ". Conversion failed with " + ex.getMessage(), ex); } } return t; }
From source file:org.apache.distributedlog.namespace.NamespaceDriverManager.java
private static void loadInitialDrivers() { Set<String> driverList = Sets.newHashSet(); // add default bookkeeper based driver driverList.add(BKNamespaceDriver.class.getName()); // load drivers from system property String driversStr = System.getProperty("distributedlog.namespace.drivers"); if (null != driversStr) { String[] driversArray = StringUtils.split(driversStr, ':'); for (String driver : driversArray) { driverList.add(driver);/*from ww w .j a va 2 s . c o m*/ } } // initialize the drivers for (String driverClsName : driverList) { try { NamespaceDriver driver = ReflectionUtils.newInstance(driverClsName, NamespaceDriver.class); NamespaceDriverInfo driverInfo = new NamespaceDriverInfo(driver.getClass()); drivers.put(driver.getScheme().toLowerCase(), driverInfo); } catch (Exception ex) { logger.warn("Failed to load namespace driver {} : ", driverClsName, ex); } } }
From source file:net.big_oh.common.web.WebUtil.java
/** * /*from w w w .ja v a2 s.co m*/ * Calculate an <b>approximation</b> of the memory consumed by the objects * stored under each attribute of a user's {@link HttpSession}. The estimate * will often be greater than the actual value because of "double counting" * objects that appear multiple times in the attribute value's object graph. * * @param session * An HttpSession object from any web application. * @return An <b>approximation</b> of the memory consumed for each attribute * <b>name</b> in the session. */ public static Map<String, Integer> getSessionAttributeNameToApproxSizeInBytesMap(HttpSession session) { // Use an IdentityHashMap because we don't want to miss distinct objects // that are equivalent according to equals(..) method. Map<String, Integer> sessionAttributeNameToApproxSizeInBytesMap = new IdentityHashMap<String, Integer>(); Enumeration<?> enumeration = session.getAttributeNames(); while (enumeration.hasMoreElements()) { String attributeName = (String) enumeration.nextElement(); session.getAttribute(attributeName); try { sessionAttributeNameToApproxSizeInBytesMap.put(attributeName, new Integer(approximateObjectSize(attributeName))); } catch (IOException ioe) { logger.error("Failed to approximate size of session attribute name: " + attributeName.getClass().getName(), ioe); sessionAttributeNameToApproxSizeInBytesMap.put(attributeName, new Integer(0)); } } return sessionAttributeNameToApproxSizeInBytesMap; }
From source file:com.yoncabt.ebr.executor.jasper.Convert.java
private static <T> T str2Number(String val, Class<T> valueClass) { if (StringUtils.isBlank(val)) { return null; }//ww w.j a va 2s . c o m if (valueClass == Integer.class) { return (T) Integer.valueOf(val); } if (valueClass == Long.class) { return (T) Long.valueOf(val); } if (valueClass == Short.class) { return (T) Short.valueOf(val); } if (valueClass == Double.class) { return (T) Double.valueOf(val); } if (valueClass == BigDecimal.class) { return (T) new BigDecimal(val); } throw new IllegalArgumentException(val.getClass() + "->" + valueClass.getName()); }