List of usage examples for java.lang Long TYPE
Class TYPE
To view the source code for java.lang Long TYPE.
Click Source Link
From source file:org.jcommon.com.util.config.ConfigLoader.java
public static void loadConf4xml(InputStream is, BaseConfigMBean config) throws FileNotFoundException { if (is == null) throw new FileNotFoundException(); try {//from w ww. j a v a 2s. com Document doc = new SAXReader().read(is); Element root = doc.getRootElement(); String element = null; Class<?> type = null; java.lang.reflect.Field[] fs = config.getClass().getDeclaredFields(); for (java.lang.reflect.Field f : fs) { element = f.getName(); String value = getTextFromElement(root, element); if (value == null) continue; type = f.getType(); Object args = null; java.lang.reflect.Method m = getMethod(config.getClass(), "set" + element); if (m == null) m = getMethod(config.getClass(), "is" + element); if (m != null) { if (notNull(value)) { if (String.class == type) { args = value; } else if (java.lang.Integer.class == type || Integer.TYPE == type) { args = Integer.valueOf(value); } else if (java.lang.Boolean.class == type || Boolean.TYPE == type) { args = Boolean.parseBoolean(value); } else if (java.lang.Long.class == type || Long.TYPE == type) { args = Long.valueOf(value); } else if (java.lang.Float.class == type || Float.TYPE == type) { args = Float.valueOf(value); } else if (java.util.Collection.class.isAssignableFrom(type)) { args = loadCollection(root, element, f); } else if (java.util.Map.class.isAssignableFrom(type)) { args = loadMap(root, element, f); } else { logger.info("not map Class:" + type); continue; } } try { m.invoke(config, args); logger.info(element + ":" + value); } catch (Exception e) { logger.warn(e); continue; } } else if (notNull(value)) logger.warn("can't find element:" + value); } try { is.close(); } catch (Exception e) { } logger.info(String.format("Read config file: %s", is)); } catch (Throwable t) { logger.error("read config file error:" + is + "\n" + t.getMessage()); } }
From source file:fragment.web.AuthenticationControllerTest.java
@Test public void testLandingRouting() throws Exception { logger.debug("Testing routing...."); DispatcherTestServlet servlet = getServletInstance(); Method expected = locateMethod(controller.getClass(), "login", new Class[] { HttpServletRequest.class, ModelMap.class, HttpSession.class }); Method handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/login")); Assert.assertEquals(expected, handler); expected = locateMethod(controller.getClass(), "loggedout", new Class[] { java.lang.String.class, ModelMap.class, HttpSession.class, HttpServletResponse.class, HttpServletRequest.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/userParam/loggedout")); Assert.assertEquals(expected, handler); MockHttpServletRequest request = getRequestTemplate(HttpMethod.GET, "/reset_password"); expected = locateMethod(controller.getClass(), "requestReset", new Class[] { ModelMap.class, }); handler = servlet.recognize(request); Assert.assertEquals(expected, handler); request.removeAllParameters();//www .j a va 2 s . co m request.addParameter("username", "value"); request.setMethod(HttpMethod.POST.name()); expected = locateMethod(controller.getClass(), "requestReset", new Class[] { String.class, HttpServletRequest.class, ModelMap.class }); handler = servlet.recognize(request); Assert.assertEquals(expected, handler); request.removeAllParameters(); request.setMethod(HttpMethod.GET.name()); request.addParameter("a", "value"); request.addParameter("t", "0"); request.addParameter("i", "value"); expected = locateMethod(controller.getClass(), "reset", new Class[] { String.class, Long.TYPE, String.class, HttpSession.class, ModelMap.class }); handler = servlet.recognize(request); Assert.assertEquals(expected, handler); request.removeAllParameters(); request.addParameter("password", "password"); request.setMethod(HttpMethod.POST.name()); expected = locateMethod(controller.getClass(), "reset", new Class[] { String.class, HttpSession.class, HttpServletRequest.class }); handler = servlet.recognize(request); Assert.assertEquals(expected, handler); request.removeAllParameters(); expected = locateMethod(controller.getClass(), "requestCall", new Class[] { String.class, String.class, HttpServletRequest.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/request_call_by_user")); Assert.assertEquals(expected, handler); request.removeAllParameters(); expected = locateMethod(controller.getClass(), "requestSMS", new Class[] { String.class, String.class, HttpServletRequest.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/request_sms_by_user")); Assert.assertEquals(expected, handler); request.removeAllParameters(); expected = locateMethod(controller.getClass(), "verifyAdditionalEmail", new Class[] { String.class, String.class, String.class, HttpServletRequest.class, ModelMap.class, HttpSession.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/verify_additional_email")); Assert.assertEquals(expected, handler); request.removeAllParameters(); expected = locateMethod(controller.getClass(), "getGoogleAnalytics", new Class[] {}); handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/getGoogleAnalytics")); Assert.assertEquals(expected, handler); }
From source file:com.manydesigns.elements.util.Util.java
public static boolean isNumericType(Class type) { return Number.class.isAssignableFrom(type) || type == Integer.TYPE || type == Byte.TYPE || type == Short.TYPE || type == Long.TYPE || type == Float.TYPE || type == Double.TYPE; }
From source file:cc.aileron.accessor.TypeConvertorImpl.java
/** * default constractor/*from ww w . j ava 2 s. co m*/ */ @Inject public TypeConvertorImpl() { map.put(Boolean.TYPE, new C() { @Override public Boolean convert(final java.lang.Number number) { return number.intValue() != 0; } }); map.put(Byte.TYPE, new C() { @Override public Byte convert(final java.lang.Number number) { return number.byteValue(); } }); map.put(Short.TYPE, new C() { @Override public Short convert(final java.lang.Number number) { return number.shortValue(); } }); map.put(Integer.TYPE, new C() { @Override public Integer convert(final java.lang.Number number) { return number.intValue(); } }); map.put(Long.TYPE, new C() { @Override public Long convert(final java.lang.Number number) { return number.longValue(); } }); map.put(Float.TYPE, new C() { @Override public Float convert(final java.lang.Number number) { return number.floatValue(); } }); map.put(Double.TYPE, new C() { @Override public Double convert(final java.lang.Number number) { return number.doubleValue(); } }); }
From source file:com.github.michalbednarski.intentslab.Utils.java
public static Object getDefaultValueForPrimitveClass(Class<?> aClass) { if (aClass == Boolean.TYPE) { return false; } else if (aClass == Byte.TYPE) { return (byte) 0; } else if (aClass == Character.TYPE) { return 0; } else if (aClass == Short.TYPE) { return (short) 0; } else if (aClass == Integer.TYPE) { return 0; } else if (aClass == Long.TYPE) { return (long) 0; } else if (aClass == Float.TYPE) { return 0; } else if (aClass == Double.TYPE) { return 0; } else {//from w ww .j av a 2 s .c om throw new RuntimeException("Not primitive type"); } }
From source file:com.adobe.acs.commons.data.Variant.java
@SuppressWarnings("squid:S3776") public final <T> void setValue(T val) { if (val == null) { return;/* w w w .ja v a2 s . c om*/ } Class type = val.getClass(); if (type == Variant.class) { Variant v = (Variant) val; longVal = v.longVal; doubleVal = v.doubleVal; stringVal = v.stringVal; booleanVal = v.booleanVal; dateVal = v.dateVal; } else if (type == Byte.TYPE || type == Byte.class) { setLongVal(((Byte) val).longValue()); } else if (type == Integer.TYPE || type == Integer.class) { setLongVal(((Integer) val).longValue()); } else if (type == Long.TYPE || type == Long.class) { setLongVal((Long) val); } else if (type == Short.TYPE || type == Short.class) { setLongVal(((Short) val).longValue()); } else if (type == Float.TYPE || type == Float.class) { setDoubleVal((Double) val); } else if (type == Double.TYPE || type == Double.class) { setDoubleVal((Double) val); } else if (type == Boolean.TYPE || type == Boolean.class) { setBooleanVal((Boolean) val); } else if (type == String.class) { setStringVal((String) val); } else if (type == Date.class) { setDateVal((Date) val); } else if (type == Instant.class) { setDateVal(new Date(((Instant) val).toEpochMilli())); } else if (type == Calendar.class) { setDateVal(((Calendar) val).getTime()); } else { setStringVal(String.valueOf(val)); } }
From source file:net.sf.jrf.domain.PersistentObjectDynaProperty.java
/** Constructs instance and property name and class. * @param name property name.//from ww w . java 2 s. c o m * @param cls value object <code>Class</code>. * @param readMethodName name of the read <code>Method</code> * @param writeMethodName name of the write <code>Method</code> */ public PersistentObjectDynaProperty(String name, Class cls, String readMethodName, String writeMethodName) { super(name, cls); this.readMethodName = readMethodName; this.writeMethodName = writeMethodName; if (cls.isPrimitive()) { if (cls.equals(Boolean.TYPE)) primitiveWrapperClass = Boolean.class; else if (cls.equals(Byte.TYPE)) primitiveWrapperClass = Byte.class; else if (cls.equals(Character.TYPE)) primitiveWrapperClass = Character.class; else if (cls.equals(Double.TYPE)) primitiveWrapperClass = Double.class; else if (cls.equals(Float.TYPE)) primitiveWrapperClass = Float.class; else if (cls.equals(Integer.TYPE)) primitiveWrapperClass = Integer.class; else if (cls.equals(Long.TYPE)) primitiveWrapperClass = Long.class; else if (cls.equals(Short.TYPE)) primitiveWrapperClass = Short.class; } else if (java.util.List.class.isAssignableFrom(cls) || cls.isArray()) { indexed = true; } else if (java.util.Map.class.isAssignableFrom(cls)) { mapped = true; } }
From source file:org.soybeanMilk.SbmUtils.java
/** * ?<code>type</code>?/*from w w w . j a v a 2 s . co m*/ * @param type * @return * @date 2010-12-31 */ public static Type wrapType(Type type) { if (!isClassType(type)) return type; else if (!narrowToClass(type).isPrimitive()) return type; else if (Byte.TYPE.equals(type)) return Byte.class; else if (Short.TYPE.equals(type)) return Short.class; else if (Integer.TYPE.equals(type)) return Integer.class; else if (Long.TYPE.equals(type)) return Long.class; else if (Float.TYPE.equals(type)) return Float.class; else if (Double.TYPE.equals(type)) return Double.class; else if (Boolean.TYPE.equals(type)) return Boolean.class; else if (Character.TYPE.equals(type)) return Character.class; else return type; }
From source file:org.atemsource.atem.impl.common.attribute.primitive.PrimitiveTypeFactory.java
@PostConstruct public void initialize() { classes = new ArrayList<Class>(); classes.add(String.class); classes.add(Boolean.class); classes.add(Boolean.TYPE);//w w w . j av a2 s . c om classes.add(Long.class); classes.add(Long.TYPE); classes.add(Integer.class); classes.add(Integer.TYPE); classes.add(Float.class); classes.add(Float.TYPE); classes.add(Double.TYPE); classes.add(Double.class); classes.add(Character.TYPE); classes.add(Character.TYPE); classes.add(Character.class); classes.add(Byte.TYPE); classes.add(Byte.class); classes.add(Enum.class); classes.add(BigInteger.class); classes.add(BigDecimal.class); Collection<PrimitiveTypeRegistrar> registrars = beanLocator.getInstances(PrimitiveTypeRegistrar.class); for (PrimitiveTypeRegistrar registrar : registrars) { PrimitiveType<?>[] types = registrar.getTypes(); for (PrimitiveType<?> primitiveType : types) { classToType.put(primitiveType.getJavaType(), primitiveType); classes.add(primitiveType.getJavaType()); } } }
From source file:com.netflix.governator.lifecycle.ConfigurationProcessor.java
private Supplier<?> getConfigurationSupplier(final Field field, final ConfigurationKey key, final Class<?> type, Supplier<?> current) { if (String.class.isAssignableFrom(type)) { return configurationProvider.getStringSupplier(key, (String) current.get()); } else if (Boolean.class.isAssignableFrom(type) || Boolean.TYPE.isAssignableFrom(type)) { return configurationProvider.getBooleanSupplier(key, (Boolean) current.get()); } else if (Integer.class.isAssignableFrom(type) || Integer.TYPE.isAssignableFrom(type)) { return configurationProvider.getIntegerSupplier(key, (Integer) current.get()); } else if (Long.class.isAssignableFrom(type) || Long.TYPE.isAssignableFrom(type)) { return configurationProvider.getLongSupplier(key, (Long) current.get()); } else if (Double.class.isAssignableFrom(type) || Double.TYPE.isAssignableFrom(type)) { return configurationProvider.getDoubleSupplier(key, (Double) current.get()); } else if (Date.class.isAssignableFrom(type)) { return configurationProvider.getDateSupplier(key, (Date) current.get()); } else {//from w w w . j av a 2s. co m log.error("Field type not supported: " + type + " (" + field.getName() + ")"); return null; } }