List of usage examples for java.lang Integer TYPE
Class TYPE
To view the source code for java.lang Integer TYPE.
Click Source Link
From source file:com.sf.ddao.ops.InsertAndGetGeneratedKeySqlOperation.java
public boolean execute(Context context) throws Exception { try {/*from w ww.j a v a2s . com*/ final MethodCallCtx callCtx = CtxHelper.get(context, MethodCallCtx.class); PreparedStatement preparedStatement = statementFactory.createStatement(context, true); Object res = null; preparedStatement.executeUpdate(); ResultSet resultSet = preparedStatement.getGeneratedKeys(); if (resultSet.next()) { if (method.getReturnType() == Integer.TYPE || method.getReturnType() == Integer.class) { res = resultSet.getInt(1); } else if (method.getReturnType() == Long.TYPE || method.getReturnType() == Long.class) { res = resultSet.getLong(1); } else if (method.getReturnType() == BigDecimal.class) { res = resultSet.getBigDecimal(1); } } resultSet.close(); preparedStatement.close(); callCtx.setLastReturn(res); return CONTINUE_PROCESSING; } catch (Exception t) { throw new DaoException("Failed to execute sql operation for " + method, t); } }
From source file:org.apache.lens.ml.TrainerArgParser.java
/** * Extracts feature names. If the trainer has any parameters associated with @TrainerParam annotation, those are set * as well./*from ww w . ja v a2s . c om*/ * * @param trainer * the trainer * @param args * the args * @return List of feature column names. */ public static List<String> parseArgs(MLTrainer trainer, String[] args) { List<String> featureColumns = new ArrayList<String>(); Class<? extends MLTrainer> trainerClass = trainer.getClass(); // Get param fields Map<String, Field> fieldMap = new HashMap<String, Field>(); for (Field fld : trainerClass.getDeclaredFields()) { fld.setAccessible(true); TrainerParam paramAnnotation = fld.getAnnotation(TrainerParam.class); if (paramAnnotation != null) { fieldMap.put(paramAnnotation.name(), fld); } } for (int i = 0; i < args.length; i += 2) { String key = args[i].trim(); String value = args[i + 1].trim(); try { if ("feature".equalsIgnoreCase(key)) { featureColumns.add(value); } else if (fieldMap.containsKey(key)) { Field f = fieldMap.get(key); if (String.class.equals(f.getType())) { f.set(trainer, value); } else if (Integer.TYPE.equals(f.getType())) { f.setInt(trainer, Integer.parseInt(value)); } else if (Double.TYPE.equals(f.getType())) { f.setDouble(trainer, Double.parseDouble(value)); } else if (Long.TYPE.equals(f.getType())) { f.setLong(trainer, Long.parseLong(value)); } else { // check if the trainer provides a deserializer for this param String customParserClass = trainer.getConf().getProperties().get("lens.ml.args." + key); if (customParserClass != null) { Class<? extends CustomArgParser<?>> clz = (Class<? extends CustomArgParser<?>>) Class .forName(customParserClass); CustomArgParser<?> parser = clz.newInstance(); f.set(trainer, parser.parse(value)); } else { LOG.warn("Ignored param " + key + "=" + value + " as no parser found"); } } } } catch (Exception exc) { LOG.error("Error while setting param " + key + " to " + value + " for trainer " + trainer); } } return featureColumns; }
From source file:org.jcommon.com.util.config.ConfigLoader.java
/** * // w ww .j a v a2 s. c om * @param conn * @param config * @param table{key,value,map,list} */ public static void loadConf4db(Connection conn, PreparedStatement ps, BaseConfigMBean config, String[] table) { ResultSet rs = null; String key_ = table[0]; String value_ = table[1]; try { rs = ps.executeQuery(); Class<?> type = null; String name; String value; while (rs.next()) { name = rs.getString(key_); value = rs.getString(value_); java.lang.reflect.Field f = null; try { f = config.getClass().getDeclaredField(name); } catch (java.lang.NoSuchFieldException e) { continue; } if (f != null) type = f.getType(); Object args = null; java.lang.reflect.Method m = getMethod(config.getClass(), "set" + name); if (m != null && notNull(value) && type != null) { 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 { logger.info("not map Class:" + type); } m.invoke(config, args); logger.info(name + ":" + value); } else if (notNull(value)) logger.warn("can't find element:" + value); } } catch (Exception e) { logger.error("load config error:", e); } finally { try { conn.close(); ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block logger.error("load config error:", e); } conn = null; } }
From source file:org.ocelotds.cache.JsCacheRemovesInterceptorTest.java
/** * Test of processJsCacheRemoves method, of class JsCacheRemovesInterceptor. * @throws java.lang.Exception//from www. java 2 s . com */ @Test public void testProcessJsCacheRemoves() throws Exception { System.out.println("processJsCacheRemoves"); InvocationContext ctx = mock(InvocationContext.class); Method method = CacheAnnotedClass.class.getDeclaredMethod("jsCacheRemovesAnnotatedMethod", Integer.TYPE, CacheManagerTest.Result.class); when(ctx.getMethod()).thenReturn(method); instance.processJsCacheRemoves(ctx); verify(jsCacheAnnotationServices, times(2)).processJsCacheRemove(any(JsCacheRemove.class), anyList(), anyList()); verify(ctx).proceed(); }
From source file:org.ocelotds.cache.JsCacheRemoveInterceptorTest.java
/** * Test of processJsCacheRemoves method, of class JsCacheRemovesInterceptor. * @throws java.lang.Exception/* ww w . j av a 2 s . c o m*/ */ @Test public void testProcessJsCacheRemove() throws Exception { System.out.println("processJsCacheRemove"); InvocationContext ctx = mock(InvocationContext.class); Method method = CacheAnnotedClass.class.getDeclaredMethod("jsCacheRemoveAnnotatedMethodWithAllArgs", Integer.TYPE, String.class); when(ctx.getMethod()).thenReturn(method); instance.processJsCacheRemove(ctx); verify(jsCacheAnnotationServices).processJsCacheRemove(any(JsCacheRemove.class), anyList(), anyList()); verify(ctx).proceed(); }
From source file:loon.LGame.java
private static Class<?> getType(Object o) { if (o instanceof Integer) { return Integer.TYPE; } else if (o instanceof Float) { return Float.TYPE; } else if (o instanceof Double) { return Double.TYPE; } else if (o instanceof Long) { return Long.TYPE; } else if (o instanceof Short) { return Short.TYPE; } else if (o instanceof Short) { return Short.TYPE; } else if (o instanceof Boolean) { return Boolean.TYPE; } else {//from www . j a v a 2 s.c o m return o.getClass(); } }
From source file:org.ebayopensource.turmeric.tools.codegen.util.IntrospectUtilTest.java
@Test public void isCollectionTypeInteger() throws Exception { Assert.assertFalse(IntrospectUtil.isCollectionType(Integer.TYPE.getClass())); }
From source file:io.github.benas.jpopulator.impl.DefaultRandomizer.java
/** * Generate a random value for the given type. * * @param type the type for which a random value will be generated * @return a random value for the given type or null if the type is not supported *///from ww w. j av a2 s . com public static Object getRandomValue(final Class type) { /* * String and Character types */ if (type.equals(String.class)) { return RandomStringUtils.randomAlphabetic(ConstantsUtil.DEFAULT_STRING_LENGTH); } if (type.equals(Character.TYPE) || type.equals(Character.class)) { return RandomStringUtils.randomAlphabetic(1).charAt(0); } /* * Boolean type */ if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) { return ConstantsUtil.RANDOM.nextBoolean(); } /* * Numeric types */ if (type.equals(Byte.TYPE) || type.equals(Byte.class)) { return (byte) (ConstantsUtil.RANDOM.nextInt()); } if (type.equals(Short.TYPE) || type.equals(Short.class)) { return (short) (ConstantsUtil.RANDOM.nextInt()); } if (type.equals(Integer.TYPE) || type.equals(Integer.class)) { return ConstantsUtil.RANDOM.nextInt(); } if (type.equals(Long.TYPE) || type.equals(Long.class)) { return ConstantsUtil.RANDOM.nextLong(); } if (type.equals(Double.TYPE) || type.equals(Double.class)) { return ConstantsUtil.RANDOM.nextDouble(); } if (type.equals(Float.TYPE) || type.equals(Float.class)) { return ConstantsUtil.RANDOM.nextFloat(); } if (type.equals(BigInteger.class)) { return new BigInteger( Math.abs(ConstantsUtil.RANDOM.nextInt(ConstantsUtil.DEFAULT_BIG_INTEGER_NUM_BITS_LENGTH)), ConstantsUtil.RANDOM); } if (type.equals(BigDecimal.class)) { return new BigDecimal(ConstantsUtil.RANDOM.nextDouble()); } if (type.equals(AtomicLong.class)) { return new AtomicLong(ConstantsUtil.RANDOM.nextLong()); } if (type.equals(AtomicInteger.class)) { return new AtomicInteger(ConstantsUtil.RANDOM.nextInt()); } /* * Date and time types */ if (type.equals(java.util.Date.class)) { return ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue(); } if (type.equals(java.sql.Date.class)) { return new java.sql.Date(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(java.sql.Time.class)) { return new java.sql.Time(ConstantsUtil.RANDOM.nextLong()); } if (type.equals(java.sql.Timestamp.class)) { return new java.sql.Timestamp(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(Calendar.class)) { return Calendar.getInstance(); } if (type.equals(org.joda.time.DateTime.class)) { return new org.joda.time.DateTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(org.joda.time.LocalDate.class)) { return new org.joda.time.LocalDate(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(org.joda.time.LocalTime.class)) { return new org.joda.time.LocalTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(org.joda.time.LocalDateTime.class)) { return new org.joda.time.LocalDateTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(org.joda.time.Duration.class)) { return new org.joda.time.Duration(Math.abs(ConstantsUtil.RANDOM.nextLong())); } if (type.equals(org.joda.time.Period.class)) { return new org.joda.time.Period(Math.abs(ConstantsUtil.RANDOM.nextInt())); } if (type.equals(org.joda.time.Interval.class)) { long startDate = Math.abs(ConstantsUtil.RANDOM.nextInt()); long endDate = startDate + Math.abs(ConstantsUtil.RANDOM.nextInt()); return new org.joda.time.Interval(startDate, endDate); } /* * Enum type */ if (type.isEnum() && type.getEnumConstants().length > 0) { Object[] enumConstants = type.getEnumConstants(); return enumConstants[ConstantsUtil.RANDOM.nextInt(enumConstants.length)]; } /* * Return null for any unsupported type */ return null; }
From source file:com.textuality.lifesaver2.Columns.java
public Columns(Context context, String[] names, Class<?>[] classes, String key1, String key2) { this.mNames = names; mTypes = new Type[names.length]; mKey1 = key1;/*from w ww . ja va2s .c o m*/ mKey2 = key2; mNameFinder = new NameFinder(context); for (int i = 0; i < names.length; i++) { if (classes[i] == String.class) mTypes[i] = Type.STRING; else if (classes[i] == Integer.TYPE || classes[i] == Integer.class) mTypes[i] = Type.INT; else if (classes[i] == Long.TYPE || classes[i] == Long.class) mTypes[i] = Type.LONG; else if (classes[i] == Float.TYPE || classes[i] == Float.class) mTypes[i] = Type.FLOAT; else if (classes[i] == Double.TYPE || classes[i] == Double.class) mTypes[i] = Type.DOUBLE; } }
From source file:net.sf.ij_plugins.util.DialogUtil.java
/** * Utility to automatically create ImageJ's GenericDialog for editing bean properties. It uses BeanInfo to extract * display names for each field. If a fields type is not supported irs name will be displayed with a tag * "[Unsupported type: class_name]".//from w w w . jav a 2 s . co m * * @param bean * @return <code>true</code> if user closed bean dialog using OK button, <code>false</code> otherwise. */ static public boolean showGenericDialog(final Object bean, final String title) { final BeanInfo beanInfo; try { beanInfo = Introspector.getBeanInfo(bean.getClass()); } catch (IntrospectionException e) { throw new IJPluginsRuntimeException("Error extracting bean info.", e); } final GenericDialog genericDialog = new GenericDialog(title); // Create generic dialog fields for each bean's property final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); try { for (int i = 0; i < propertyDescriptors.length; i++) { final PropertyDescriptor pd = propertyDescriptors[i]; final Class type = pd.getPropertyType(); if (type.equals(Class.class) && "class".equals(pd.getName())) { continue; } final Object o = PropertyUtils.getSimpleProperty(bean, pd.getName()); if (type.equals(Boolean.TYPE)) { boolean value = ((Boolean) o).booleanValue(); genericDialog.addCheckbox(pd.getDisplayName(), value); } else if (type.equals(Integer.TYPE)) { int value = ((Integer) o).intValue(); genericDialog.addNumericField(pd.getDisplayName(), value, 0); } else if (type.equals(Float.TYPE)) { double value = ((Float) o).doubleValue(); genericDialog.addNumericField(pd.getDisplayName(), value, 6, 10, ""); } else if (type.equals(Double.TYPE)) { double value = ((Double) o).doubleValue(); genericDialog.addNumericField(pd.getDisplayName(), value, 6, 10, ""); } else { genericDialog.addMessage(pd.getDisplayName() + "[Unsupported type: " + type + "]"); } } } catch (IllegalAccessException e) { throw new IJPluginsRuntimeException(e); } catch (InvocationTargetException e) { throw new IJPluginsRuntimeException(e); } catch (NoSuchMethodException e) { throw new IJPluginsRuntimeException(e); } // final Panel helpPanel = new Panel(); // helpPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0)); // final Button helpButton = new Button("Help"); //// helpButton.addActionListener(this); // helpPanel.add(helpButton); // genericDialog.addPanel(helpPanel, GridBagConstraints.EAST, new Insets(15,0,0,0)); // Show modal dialog genericDialog.showDialog(); if (genericDialog.wasCanceled()) { return false; } // Read fields from generic dialog into bean's properties. try { for (int i = 0; i < propertyDescriptors.length; i++) { final PropertyDescriptor pd = propertyDescriptors[i]; final Class type = pd.getPropertyType(); final Object propertyValue; if (type.equals(Boolean.TYPE)) { boolean value = genericDialog.getNextBoolean(); propertyValue = Boolean.valueOf(value); } else if (type.equals(Integer.TYPE)) { int value = (int) Math.round(genericDialog.getNextNumber()); propertyValue = new Integer(value); } else if (type.equals(Float.TYPE)) { double value = genericDialog.getNextNumber(); propertyValue = new Float(value); } else if (type.equals(Double.TYPE)) { double value = genericDialog.getNextNumber(); propertyValue = new Double(value); } else { continue; } PropertyUtils.setProperty(bean, pd.getName(), propertyValue); } } catch (IllegalAccessException e) { throw new IJPluginsRuntimeException(e); } catch (InvocationTargetException e) { throw new IJPluginsRuntimeException(e); } catch (NoSuchMethodException e) { throw new IJPluginsRuntimeException(e); } return true; }