List of usage examples for java.lang Boolean TYPE
Class TYPE
To view the source code for java.lang Boolean TYPE.
Click Source Link
From source file:org.liveSense.api.beanprocessors.DbStandardBeanProcessor.java
/** * ResultSet.getObject() returns an Integer object for an INT column. The * setter method for the property might take an Integer or a primitive int. * This method returns true if the value can be successfully passed into * the setter method. Remember, Method.invoke() handles the unwrapping * of Integer into an int./* ww w .j av a 2 s .c om*/ * * @param value The value to be passed into the setter method. * @param type The setter's parameter type. * @return boolean True if the value is compatible. */ private boolean isCompatibleType(Object value, Class<?> type) { // Do object check first, then primitives if (value == null || type.isInstance(value)) { return true; } else if (type.equals(Integer.TYPE) && Integer.class.isInstance(value)) { return true; } else if (type.equals(Long.TYPE) && Long.class.isInstance(value)) { return true; } else if (type.equals(Double.TYPE) && Double.class.isInstance(value)) { return true; } else if (type.equals(Float.TYPE) && Float.class.isInstance(value)) { return true; } else if (type.equals(Short.TYPE) && Short.class.isInstance(value)) { return true; } else if (type.equals(Byte.TYPE) && Byte.class.isInstance(value)) { return true; } else if (type.equals(Character.TYPE) && Character.class.isInstance(value)) { return true; } else if (type.equals(Boolean.TYPE) && Boolean.class.isInstance(value)) { return true; } else { return false; } }
From source file:com.nway.spring.jdbc.bean.JavassistBeanProcessor.java
private Object processColumn(ResultSet rs, int index, Class<?> propType, String writer, StringBuilder handler) throws SQLException { if (propType.equals(String.class)) { handler.append("bean.").append(writer).append("(").append("$1.getString(").append(index).append("));"); return rs.getString(index); } else if (propType.equals(Integer.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getInt(").append(index).append("));"); return rs.getInt(index); } else if (propType.equals(Integer.class)) { handler.append("bean.").append(writer).append("(").append("integerValue($1.getInt(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Integer.class); } else if (propType.equals(Long.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getLong(").append(index).append("));"); return rs.getLong(index); } else if (propType.equals(Long.class)) { handler.append("bean.").append(writer).append("(").append("longValue($1.getLong(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Long.class); } else if (propType.equals(java.sql.Date.class)) { handler.append("bean.").append(writer).append("(").append("$1.getDate(").append(index).append("));"); return rs.getDate(index); } else if (propType.equals(java.util.Date.class) || propType.equals(Timestamp.class)) { handler.append("bean.").append(writer).append("(").append("$1.getTimestamp(").append(index) .append("));"); return rs.getTimestamp(index); } else if (propType.equals(Double.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getDouble(").append(index).append("));"); return rs.getDouble(index); } else if (propType.equals(Double.class)) { handler.append("bean.").append(writer).append("(").append("doubleValue($1.getDouble(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Double.class); } else if (propType.equals(Float.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getFloat(").append(index).append("));"); return rs.getFloat(index); } else if (propType.equals(Float.class)) { handler.append("bean.").append(writer).append("(").append("floatValue($1.getFloat(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Float.class); } else if (propType.equals(Time.class)) { handler.append("bean.").append(writer).append("(").append("$1.getTime(").append(index).append("));"); return rs.getTime(index); } else if (propType.equals(Boolean.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getBoolean(").append(index).append("));"); return rs.getBoolean(index); } else if (propType.equals(Boolean.class)) { handler.append("bean.").append(writer).append("(").append("booleanValue($1.getBoolean(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Boolean.class); } else if (propType.equals(byte[].class)) { handler.append("bean.").append(writer).append("(").append("$1.getBytes(").append(index).append("));"); return rs.getBytes(index); } else if (BigDecimal.class.equals(propType)) { handler.append("bean.").append(writer).append("(").append("$1.getBigDecimal(").append(index) .append("));"); return rs.getBigDecimal(index); } else if (Blob.class.equals(propType)) { handler.append("bean.").append(writer).append("(").append("$1.getBlob(").append(index).append("));"); return rs.getBlob(index); } else if (Clob.class.equals(propType)) { handler.append("bean.").append(writer).append("(").append("$1.getClob(").append(index).append("));"); return rs.getClob(index); } else if (propType.equals(Short.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getShort(").append(index).append("));"); return rs.getShort(index); } else if (propType.equals(Short.class)) { handler.append("bean.").append(writer).append("(").append("shortValue($1.getShort(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Short.class); } else if (propType.equals(Byte.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getByte(").append(index).append("));"); return rs.getByte(index); } else if (propType.equals(Byte.class)) { handler.append("bean.").append(writer).append("(").append("byteValue($1.getByte(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Byte.class); } else {//from w w w.j a va 2 s. c o m handler.append("bean.").append(writer).append("(").append("(").append(propType.getName()).append(")") .append("$1.getObject(").append(index).append("));"); return rs.getObject(index); } }
From source file:Main.java
/** * <p>Inserts the specified element at the specified position in the array. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices).</p> * * <p>This method returns a new array with the same elements of the input * array plus the given element on the specified position. The component * type of the returned array is always the same as that of the input * array.</p>/*ww w . j av a 2s . co m*/ * * <p>If the input array is {@code null}, a new one element array is returned * whose component type is the same as the element.</p> * * <pre> * ArrayUtils.add(null, 0, true) = [true] * ArrayUtils.add([true], 0, false) = [false, true] * ArrayUtils.add([false], 1, true) = [false, true] * ArrayUtils.add([true, false], 1, true) = [true, true, false] * </pre> * * @param array the array to add the element to, may be {@code null} * @param index the position of the new object * @param element the object to add * @return A new array containing the existing elements and the new element * @throws IndexOutOfBoundsException if the index is out of range * (index < 0 || index > array.length). */ public static boolean[] add(final boolean[] array, final int index, final boolean element) { return (boolean[]) add(array, index, Boolean.valueOf(element), Boolean.TYPE); }
From source file:com.qmetry.qaf.automation.data.BaseDataBean.java
/** * This will fill random data except those properties which has skip=true in * {@link Randomizer} annotation. Use {@link Randomizer} annotation to * specify data value to be generated for specific property. * //from ww w. j a v a2s.c om * @see Randomizer */ public void fillRandomData() { Field[] fields = getFields(); for (Field field : fields) { logger.debug("NAME :: " + field.getName()); if (!(Modifier.isFinal(field.getModifiers()))) { RandomizerTypes type = RandomizerTypes.MIXED; int len = 10; long min = 0, max = 0; String prefix = "", suffix = ""; String format = ""; String[] list = {}; Randomizer randomizer = field.getAnnotation(Randomizer.class); if (randomizer != null) { if (randomizer.skip()) { continue; } type = field.getType() == Date.class ? RandomizerTypes.DIGITS_ONLY : randomizer.type(); len = randomizer.length(); prefix = randomizer.prefix(); suffix = randomizer.suffix(); min = randomizer.minval(); max = min > randomizer.maxval() ? min : randomizer.maxval(); format = randomizer.format(); list = randomizer.dataset(); } else { // @Since 2.1.2 randomizer annotation is must for random // value // generation continue; } String str = ""; if ((list == null) || (list.length == 0)) { str = StringUtil.isBlank(format) ? RandomStringUtils.random(len, !type.equals(RandomizerTypes.DIGITS_ONLY), !type.equals(RandomizerTypes.LETTERS_ONLY)) : StringUtil.getRandomString(format); } else { str = getRandomValue(list); } try { // deal with IllegalAccessException field.setAccessible(true); Method setter = null; try { setter = this.getClass().getMethod("set" + StringUtil.getTitleCase(field.getName()), String.class); } catch (Exception e) { } if ((field.getType() == String.class) || (null != setter)) { if ((list == null) || (list.length == 0)) { if ((min == max) && (min == 0)) { str = StringUtil.isBlank(format) ? RandomStringUtils.random(len, !type.equals(RandomizerTypes.DIGITS_ONLY), !type.equals(RandomizerTypes.LETTERS_ONLY)) : StringUtil.getRandomString(format); } else { str = String.valueOf((int) (Math.random() * ((max - min) + 1)) + min); } } String rStr = prefix + str + suffix; if (null != setter) { setter.setAccessible(true); setter.invoke(this, rStr); } else { field.set(this, rStr); } } else { String rStr = ""; if ((min == max) && (min == 0)) { rStr = RandomStringUtils.random(len, false, true); } else { rStr = String.valueOf((int) (Math.random() * ((max - min) + 1)) + min); } if (field.getType() == Integer.TYPE) { field.setInt(this, Integer.parseInt(rStr)); } else if (field.getType() == Float.TYPE) { field.setFloat(this, Float.parseFloat(rStr)); } else if (field.getType() == Double.TYPE) { field.setDouble(this, Double.parseDouble(rStr)); } else if (field.getType() == Long.TYPE) { field.setLong(this, Long.parseLong(rStr)); } else if (field.getType() == Short.TYPE) { field.setShort(this, Short.parseShort(rStr)); } else if (field.getType() == Date.class) { logger.info("filling date " + rStr); int days = Integer.parseInt(rStr); field.set(this, DateUtil.getDate(days)); } else if (field.getType() == Boolean.TYPE) { field.setBoolean(this, RandomUtils.nextBoolean()); } } } catch (IllegalArgumentException e) { logger.error("Unable to fill random data in field " + field.getName(), e); } catch (IllegalAccessException e) { logger.error("Unable to Access " + field.getName(), e); } catch (InvocationTargetException e) { logger.error("Unable to Access setter for " + field.getName(), e); } } } }
From source file:at.alladin.rmbt.shared.hstoreparser.HstoreParser.java
/** * //from w w w.j a v a2 s. com * @param json * @param key * @param toField * @return * @throws JSONException */ public static Object getFromJsonByField2(JSONObject json, String key, Field toField) throws JSONException { final Object o = json.get(key); final Class<?> fieldType = toField.getType(); if (o != JSONObject.NULL) { if (fieldType.equals(Integer.class) || fieldType.equals(Integer.TYPE)) { return json.getInt(key); } else if (fieldType.equals(String.class)) { return o; } else if (fieldType.equals(Long.class) || fieldType.equals(Long.TYPE)) { return json.getLong(key); } else if (fieldType.equals(Boolean.class) || fieldType.equals(Boolean.TYPE)) { return json.getBoolean(key); } else if (fieldType.equals(Float.class) || fieldType.equals(Float.TYPE)) { return (float) json.getDouble(key); } else if (fieldType.equals(Double.class) || fieldType.equals(Double.TYPE)) { return json.getDouble(key); } else { return o; } } return JSONObject.NULL; }
From source file:com.liferay.tool.datamanipulator.handler.BaseHandler.java
private Object[] _getArgs(String[] argNames, Class<?>[] argClazzs, RequestContext requestContext, Map<String, Object> entrySpecifiedArgs) throws Exception { long companyId = requestContext.getCompanyId(); long groupId = requestContext.getGroupId(); long userId = requestContext.getUserId(); Date now = new Date(); ServiceContext serviceContext = HandlerUtil.getServiceContext(groupId, userId); Map<String, Calendar> dateMap = new HashMap<String, Calendar>(entryDateFields.size()); for (String entryDateField : entryDateFields) { String dateVarName = entryDateField + "Date"; String dateKeyName = entryDateField + "-date"; Date serviceContextDate = (Date) BeanUtil.getPropertySilently(serviceContext, dateVarName); Calendar dateVarValue;//from w w w .ja v a 2s . c o m if (requestContext.contains(dateKeyName + "-from") && requestContext.contains(dateKeyName + "-to")) { dateVarValue = requestContext.getBetweenCalendar(dateKeyName); } else if (Validator.isNotNull(serviceContextDate)) { dateVarValue = Calendar.getInstance(); dateVarValue.setTime(serviceContextDate); } else { dateVarValue = Calendar.getInstance(); dateVarValue.setTime(now); } dateMap.put(dateVarName, dateVarValue); } StringBuilder sb = new StringBuilder(); sb.append(_entryName); sb.append(requestContext.getString("entryCount")); sb.append(" ${fieldName} "); if (requestContext.contains("editCount")) { sb.append("Edited "); sb.append(requestContext.getString("editCount")); sb.append(" times "); } sb.append(requestContext.getRandomString()); String entryTemplate = sb.toString(); User user = UserLocalServiceUtil.fetchUser(userId); List<Object> argValues = new ArrayList<Object>(argNames.length); for (int i = 0; i < argNames.length; i++) { String argName = argNames[i]; Class<?> argClazz = argClazzs[i]; if (entrySpecifiedArgs.containsKey(argName)) { argValues.add(entrySpecifiedArgs.get(argName)); } else if (argName.equals(Field.COMPANY_ID)) { argValues.add(companyId); } else if (argName.matches(".*Date.*")) { int x = argName.indexOf("Date") + 4; String dateKey = argName.substring(0, x); Calendar calendar = dateMap.get(dateKey); String calendarFieldName = argName.substring(x).toUpperCase(); if (calendarFieldName.equals("DAY")) { calendarFieldName = "DATE"; } int calendarFieldValue = (Integer) GetterUtil.getFieldValue(Calendar.class.getName(), calendarFieldName); argValues.add(calendar.get(calendarFieldValue)); } else if (entryStringFields.contains(argName)) { Map<String, String> context = new HashMap<String, String>(1); context.put("fieldName", argName); String content = StringUtil.getStringFieldValue(argName, context, entryTemplate); argValues.add(content); } else if (entryMapFields.contains(argName)) { argName = argName.substring(0, (argName.length() - 3)); Map<String, String> context = new HashMap<String, String>(1); context.put("fieldName", argName); String content = StringUtil.getStringFieldValue(argName, context, entryTemplate); argValues.add(StringUtil.getLocalizationMap(content)); } else if (argName.equals("friendlyURL")) { Map<String, String> context = new HashMap<String, String>(1); context.put("fieldName", "name"); String friendlyURL = StringUtil.getStringFieldValue(argName, context, entryTemplate); friendlyURL = StringPool.SLASH + FriendlyURLNormalizerUtil.normalize(friendlyURL); argValues.add(friendlyURL); } else if (argName.equals(Field.GROUP_ID)) { argValues.add(groupId); } else if (argName.equals(getParentClassPKName())) { argValues.add(Long.valueOf(_getParentClassPK(requestContext))); } else if (argName.equals("locale")) { argValues.add(LocaleUtil.getDefault()); } else if (argName.equals("serviceContext")) { argValues.add(serviceContext); } else if (argName.equals(Field.USER_ID)) { argValues.add(userId); } else if (argName.equals(Field.USER_NAME)) { argValues.add(user.getFullName()); } else if (requestContext.contains(argName)) { argValues.add(requestContext.get(argName)); } else { Object argValue = null; try { Object object = argClazz.newInstance(); if (object instanceof String) { argValue = StringPool.BLANK; } } catch (InstantiationException e) { Type type = argClazz; if (type.equals(Boolean.TYPE)) { argValue = false; } else if (type.equals(Integer.TYPE)) { argValue = (int) 0; } else if (type.equals(List.class)) { argValue = new ArrayList<Object>(0); } else if (type.equals(Long.TYPE)) { argValue = (long) 0; } } argValues.add(argValue); } } return (Object[]) argValues.toArray(new Object[argValues.size()]); }
From source file:org.crank.javax.faces.component.MenuRenderer.java
protected Object convertSelectManyValues(FacesContext context, UISelectMany uiSelectMany, Class<?> arrayClass, String[] newValues) throws ConverterException { Object result = null;/*from w w w. j a v a 2 s. c o m*/ Converter converter = null; int len = (null != newValues ? newValues.length : 0); Class<?> elementType = arrayClass.getComponentType(); // Optimization: If the elementType is String, we don't need // conversion. Just return newValues. if (elementType.equals(String.class)) { return newValues; } try { result = Array.newInstance(elementType, len); } catch (Exception e) { throw new ConverterException(e); } // bail out now if we have no new values, returning our // oh-so-useful zero-length array. if (null == newValues) { return result; } // obtain a converter. // attached converter takes priority if (null == (converter = uiSelectMany.getConverter())) { // Otherwise, look for a by-type converter if (null == (converter = Util.getConverterForClass(elementType, context))) { // if that fails, and the attached values are of Object type, // we don't need conversion. if (elementType.equals(Object.class)) { return newValues; } StringBuffer valueStr = new StringBuffer(); for (int i = 0; i < len; i++) { if (i == 0) { valueStr.append(newValues[i]); } else { valueStr.append(' ').append(newValues[i]); } } Object[] params = { valueStr.toString(), "null Converter" }; throw new ConverterException( MessageUtils.getExceptionMessage(MessageUtils.CONVERSION_ERROR_MESSAGE_ID, params)); } } assert (null != result); if (elementType.isPrimitive()) { for (int i = 0; i < len; i++) { if (elementType.equals(Boolean.TYPE)) { Array.setBoolean(result, i, ((Boolean) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Byte.TYPE)) { Array.setByte(result, i, ((Byte) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Double.TYPE)) { Array.setDouble(result, i, ((Double) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Float.TYPE)) { Array.setFloat(result, i, ((Float) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Integer.TYPE)) { Array.setInt(result, i, ((Integer) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Character.TYPE)) { Array.setChar(result, i, ((Character) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Short.TYPE)) { Array.setShort(result, i, ((Short) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Long.TYPE)) { Array.setLong(result, i, ((Long) converter.getAsObject(context, uiSelectMany, newValues[i]))); } } } else { for (int i = 0; i < len; i++) { if (logger.isLoggable(Level.FINE)) { Object converted = converter.getAsObject(context, uiSelectMany, newValues[i]); logger.fine("String value: " + newValues[i] + " converts to : " + converted.toString()); } Array.set(result, i, converter.getAsObject(context, uiSelectMany, newValues[i])); } } return result; }
From source file:net.dmulloy2.ultimatearena.types.ArenaZone.java
/** * {@inheritDoc}// w w w . j a v a 2 s .c o m */ @Override public Map<String, Object> serialize() { Map<String, Object> data = new LinkedHashMap<>(); for (java.lang.reflect.Field field : ArenaZone.class.getDeclaredFields()) { if (Modifier.isTransient(field.getModifiers())) continue; try { boolean accessible = field.isAccessible(); field.setAccessible(true); if (field.getType().equals(Integer.TYPE)) { if (field.getInt(this) != 0) data.put(field.getName(), field.getInt(this)); } else if (field.getType().equals(Long.TYPE)) { if (field.getLong(this) != 0) data.put(field.getName(), field.getLong(this)); } else if (field.getType().equals(Boolean.TYPE)) { if (field.getBoolean(this)) data.put(field.getName(), field.getBoolean(this)); } else if (field.getType().isAssignableFrom(Collection.class)) { if (!((Collection<?>) field.get(this)).isEmpty()) data.put(field.getName(), field.get(this)); } else if (field.getType().isAssignableFrom(String.class)) { if ((String) field.get(this) != null) data.put(field.getName(), field.get(this)); } else if (field.getType().isAssignableFrom(Map.class)) { if (!((Map<?, ?>) field.get(this)).isEmpty()) data.put(field.getName(), field.get(this)); } else { if (field.get(this) != null) data.put(field.getName(), field.get(this)); } field.setAccessible(accessible); } catch (Throwable ex) { } } data.put("version", CURRENT_VERSION); return data; }
From source file:com.hablutzel.cmdline.CommandLineApplication.java
/** * Validate a Method to be a command line option methods. * * Methods with more than 1 argument are not allowed. Methods with return types * other than boolean are not allowed. Methods that throw an exception other than * org.apache.commons.cli.CommandLineException are not allowed, * * @param method the method to validate//from w ww . j a v a 2s . com * @param commandLineOption the options on that method * @return A new method helper for the method */ private CommandLineMethodHelper getHelperForCommandOption(Method method, CommandLineOption commandLineOption) throws CommandLineException { // Validate that the return type is a boolean or void if (!method.getReturnType().equals(Boolean.TYPE) && !method.getReturnType().equals(Void.TYPE)) { throw new CommandLineException( "For method " + method.getName() + ", the return type is not boolean or void"); } // Validate the exceptions throws by the method for (Class<?> clazz : method.getExceptionTypes()) { if (!clazz.equals(CommandLineException.class)) { throw new CommandLineException("For method " + method.getName() + ", there is an invalid exception class " + clazz.getName()); } } // In order to get ready to create the configuration instance, // we will need to know the command line option type // and the element type. Class<?> elementClass = null; MethodType methodType; Converter converter; // Get the parameters of the method. We'll use these to // determine what type of option we have - scalar, boolean, etc. Class<?> parameterClasses[] = method.getParameterTypes(); // See what the length tells us switch (parameterClasses.length) { case 0: methodType = MethodType.Boolean; converter = null; break; case 1: { // For a method with one argument, we have to look // more closely at the argument. It has to be a simple // scalar object, an array, or a list. Class<?> parameterClass = parameterClasses[0]; if (parameterClass.isArray()) { // For an array, we get the element class based on the // underlying component type methodType = MethodType.Array; elementClass = parameterClass.getComponentType(); } else if (List.class.isAssignableFrom(parameterClass)) { // For a list, we get the element class from the command // line options annotation methodType = MethodType.List; elementClass = commandLineOption.argumentType(); } else { // For a scalar, we get the element type from the // type of the parameter. methodType = MethodType.Scalar; elementClass = parameterClass.getClass(); } // Now that we have the element type, make sure it's convertable converter = ConvertUtils.lookup(String.class, elementClass); if (converter == null) { throw new CommandLineException("Cannot find a conversion from String to " + elementClass.getName() + " for method " + method.getName()); } break; } default: { // Other method types not allowed. throw new CommandLineException("Method " + method.getName() + " has too many arguments"); } } // Now we can return the configuration for this method return new CommandLineMethodHelper(method, methodType, elementClass, converter); }