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.briljantframework.data.resolver.Resolve.java
private static Resolver<Double> initializeDoubleResolver() { Resolver<Double> doubleResolver = new Resolver<>(Double.class); doubleResolver.put(Number.class, Number::doubleValue); doubleResolver.put(Double.class, Number::doubleValue); doubleResolver.put(Double.TYPE, Number::doubleValue); doubleResolver.put(Float.class, Number::doubleValue); doubleResolver.put(Float.TYPE, Number::doubleValue); doubleResolver.put(Long.class, Number::doubleValue); doubleResolver.put(Long.TYPE, Number::doubleValue); doubleResolver.put(Integer.class, Number::doubleValue); doubleResolver.put(Integer.TYPE, Number::doubleValue); doubleResolver.put(Short.class, Number::doubleValue); doubleResolver.put(Short.TYPE, Number::doubleValue); doubleResolver.put(Byte.class, Number::doubleValue); doubleResolver.put(Byte.TYPE, Number::doubleValue); doubleResolver.put(String.class, s -> { Number n = toNumber(s);/* ww w . j a va 2 s. co m*/ return n != null ? n.doubleValue() : Na.BOXED_DOUBLE; }); return doubleResolver; }
From source file:candr.yoclip.option.OptionField.java
@Override public void setOption(final T bean, final String value) { final Class<?> fieldType = getField().getType(); try {//from www. j a v a 2 s .com if (Boolean.TYPE.equals(fieldType) || Boolean.class.isAssignableFrom(fieldType)) { setBooleanOption(bean, value); } else if (Byte.TYPE.equals(fieldType) || Byte.class.isAssignableFrom(fieldType)) { setByteOption(bean, value); } else if (Short.TYPE.equals(fieldType) || Short.class.isAssignableFrom(fieldType)) { setShortOption(bean, value); } else if (Integer.TYPE.equals(fieldType) || Integer.class.isAssignableFrom(fieldType)) { setIntegerOption(bean, value); } else if (Long.TYPE.equals(fieldType) || Long.class.isAssignableFrom(fieldType)) { setLongOption(bean, value); } else if (Character.TYPE.equals(fieldType) || Character.class.isAssignableFrom(fieldType)) { setCharacterOption(bean, value); } else if (Float.TYPE.equals(fieldType) || Float.class.isAssignableFrom(fieldType)) { setFloatOption(bean, value); } else if (Double.TYPE.equals(fieldType) || Double.class.isAssignableFrom(fieldType)) { setDoubleOption(bean, value); } else if (String.class.isAssignableFrom(fieldType)) { setStringOption(bean, value); } else { final String supportedTypes = "boolean, byte, short, int, long, char, float, double, and String"; throw new OptionsParseException( String.format("OldOptionsParser only support %s types", supportedTypes)); } } catch (NumberFormatException e) { final String error = String.format("Error converting '%s' to %s", value, fieldType); throw new OptionsParseException(error, e); } }
From source file:org.openflexo.antar.binding.TypeUtils.java
public static boolean isLong(Type type) { if (type == null) { return false; }//from w w w.ja v a 2s.c o m return type.equals(Long.class) || type.equals(Long.TYPE); }
From source file:sf.net.experimaestro.scheduler.Scheduler.java
/** * Initialise the task manager//from w w w . j a v a 2 s . c om * * @param baseDirectory The directory where the XPM database will be stored */ public Scheduler(File baseDirectory) throws IOException { if (INSTANCE != null) { throw new XPMRuntimeException("Only one scheduler instance should be created"); } INSTANCE = this; // Initialise the database LOGGER.info("Initialising database in directory %s", baseDirectory); HashMap<String, Object> properties = new HashMap<>(); properties.put("hibernate.connection.url", format("jdbc:hsqldb:file:%s/xpm;shutdown=true;hsqldb.tx=mvcc", baseDirectory)); properties.put("hibernate.connection.username", ""); properties.put("hibernate.connection.password", ""); /* From HSQLDB http://hsqldb.org/doc/guide/sessions-chapt.html#snc_tx_mvcc In MVCC mode - locks are at the row level - no shared (i.e. read) locks - in TRANSACTION_READ_COMMITTED mode: if a session wants to read/write a row that was written by another one => wait - in TRANSACTION_REPEATABLE_READ: if a session wants to write the same row than another one => exception */ properties.put("hibernate.connection.isolation", String.valueOf(Connection.TRANSACTION_READ_COMMITTED)); ArrayList<Class<?>> loadedClasses = new ArrayList<>(); ServiceLoader<PersistentClassesAdder> services = ServiceLoader.load(PersistentClassesAdder.class); for (PersistentClassesAdder service : services) { service.add(loadedClasses); } properties.put(org.hibernate.jpa.AvailableSettings.LOADED_CLASSES, loadedClasses); entityManagerFactory = Persistence.createEntityManagerFactory("net.bpiwowar.experimaestro", properties); // Add a shutdown hook Runtime.getRuntime().addShutdownHook(new Thread(Scheduler.this::close)); // Create reused criteria queries CriteriaBuilder builder = entityManagerFactory.getCriteriaBuilder(); readyJobsQuery = builder.createQuery(Long.TYPE); Root<Job> root = readyJobsQuery.from(Job.class); readyJobsQuery.orderBy(builder.desc(root.get("priority"))); readyJobsQuery.where(root.get("state").in(ResourceState.READY)); readyJobsQuery.select(root.get(Resource_.resourceID)); // Initialise the running resources so that they can retrieve their state EntityManager entityManager = entityManagerFactory.createEntityManager(); TypedQuery<Resource> query = entityManager.createQuery("from resources r where r.state = :state", Resource.class); query.setParameter("state", ResourceState.RUNNING); for (Resource resource : query.getResultList()) { LOGGER.info("Job %s is running: starting a watcher", resource); Job job = (Job) resource; if (job.process != null) { job.process.init(job); } else { Transaction.run(em -> { // Set the job state to ERROR (and update the state in case it was finished) // The job should take care of setting a new process if the job is still running Job _job = em.find(Job.class, job.getId()); _job.setState(ResourceState.ERROR); _job.updateStatus(); LOGGER.error("No process attached to a running job. New status is: %s", _job.getState()); }); } resource.updateStatus(); } // Start the thread that notify dependencies LOGGER.info("Starting the notifier thread"); notifier = new Notifier(); notifier.start(); runningThreadsCounter.add(); // Start the thread that notify dependencies LOGGER.info("Starting the messager thread"); messengerThread = new MessengerThread(); messengerThread.start(); runningThreadsCounter.add(); // Start the thread that start the jobs LOGGER.info("Starting the job runner thread"); readyJobSemaphore.setValue(true); runner = new JobRunner("JobRunner"); runner.start(); runningThreadsCounter.add(); executorService = Executors.newFixedThreadPool(1); LOGGER.info("Done - ready status work now"); }
From source file:in.hatimi.nosh.support.CmdLineManager.java
private boolean injectString(Object target, Field field, String value) { if (field.getType().equals(Boolean.class) || field.getType().equals(Boolean.TYPE)) { Boolean vobj = new Boolean(value); return injectImpl(target, field, vobj); }//from w w w. j av a 2s. c o m if (field.getType().equals(Double.class) || field.getType().equals(Double.TYPE)) { Double vobj = Double.valueOf(value); return injectImpl(target, field, vobj); } if (field.getType().equals(Float.class) || field.getType().equals(Float.TYPE)) { Float vobj = Float.valueOf(value); return injectImpl(target, field, vobj); } if (field.getType().equals(Long.class) || field.getType().equals(Long.TYPE)) { Long vobj = Long.valueOf(value); return injectImpl(target, field, vobj); } if (field.getType().equals(Integer.class) || field.getType().equals(Integer.TYPE)) { Integer vobj = Integer.valueOf(value); return injectImpl(target, field, vobj); } if (field.getType().equals(String.class)) { return injectImpl(target, field, value); } if (field.getType().equals(byte[].class)) { return injectImpl(target, field, value.getBytes()); } if (field.getType().equals(char[].class)) { return injectImpl(target, field, value.toCharArray()); } return false; }
From source file:com.nonninz.robomodel.RoboModel.java
private void loadField(Field field, Cursor query) throws DatabaseNotUpToDateException { final Class<?> type = field.getType(); final boolean wasAccessible = field.isAccessible(); final int columnIndex = query.getColumnIndex(field.getName()); field.setAccessible(true);// w w w .j a v a2 s. co m /* * TODO: There is the potential of a problem here: * What happens if the developer changes the type of a field between releases? * * If he saves first, then the column type will be changed (In the future). * If he loads first, we don't know if an Exception will be thrown if the * types are incompatible, because it's undocumented in the Cursor documentation. */ try { if (type == String.class) { field.set(this, query.getString(columnIndex)); } else if (type == Boolean.TYPE) { final boolean value = query.getInt(columnIndex) == 1 ? true : false; field.setBoolean(this, value); } else if (type == Byte.TYPE) { field.setByte(this, (byte) query.getShort(columnIndex)); } else if (type == Double.TYPE) { field.setDouble(this, query.getDouble(columnIndex)); } else if (type == Float.TYPE) { field.setFloat(this, query.getFloat(columnIndex)); } else if (type == Integer.TYPE) { field.setInt(this, query.getInt(columnIndex)); } else if (type == Long.TYPE) { field.setLong(this, query.getLong(columnIndex)); } else if (type == Short.TYPE) { field.setShort(this, query.getShort(columnIndex)); } else if (type.isEnum()) { final String string = query.getString(columnIndex); if (string != null && string.length() > 0) { final Object[] constants = type.getEnumConstants(); final Method method = type.getMethod("valueOf", Class.class, String.class); final Object value = method.invoke(constants[0], type, string); field.set(this, value); } } else { // Try to de-json it (db column must be of type text) try { final Object value = mMapper.readValue(query.getString(columnIndex), field.getType()); field.set(this, value); } catch (final Exception e) { final String msg = String.format("Type %s is not supported for field %s", type, field.getName()); Ln.w(e, msg); throw new IllegalArgumentException(msg); } } } catch (final IllegalAccessException e) { final String msg = String.format("Field %s is not accessible", type, field.getName()); throw new IllegalArgumentException(msg); } catch (final NoSuchMethodException e) { // Should not happen throw new RuntimeException(e); } catch (final InvocationTargetException e) { // Should not happen throw new RuntimeException(e); } catch (IllegalStateException e) { // This is when there is no column in db, but there is in the model throw new DatabaseNotUpToDateException(e); } finally { field.setAccessible(wasAccessible); } }
From source file:org.opensaas.jaudit.test.BeanTest.java
/** * Returns a new Map of default test class to test values types useful in * testing getters/setters./*from w w w. j a va2s.c o m*/ * * @return Map of supported types and associated values. */ protected static Map<Class<?>, Object[]> newClassToValues() { final Map<Class<?>, Object[]> ctov = new HashMap<Class<?>, Object[]>(); ctov.put(Boolean.class, new Object[] { Boolean.TRUE, Boolean.FALSE, null }); ctov.put(Boolean.TYPE, new Object[] { Boolean.TRUE, Boolean.FALSE }); ctov.put(Date.class, new Object[] { new Date(), new Date(0L), new Date(1000L), null }); ctov.put(Double.class, new Object[] { 0d, Double.MAX_VALUE, Double.MIN_VALUE, null }); ctov.put(Double.TYPE, new Object[] { 0d, Double.MAX_VALUE, Double.MIN_VALUE }); ctov.put(Integer.class, new Object[] { 0, Integer.MAX_VALUE, Integer.MIN_VALUE, null }); ctov.put(Integer.TYPE, new Object[] { 0, Integer.MAX_VALUE, Integer.MIN_VALUE }); ctov.put(Long.class, new Object[] { 0L, Long.MAX_VALUE, Long.MIN_VALUE, null }); ctov.put(Long.TYPE, new Object[] { 0L, Long.MAX_VALUE, Long.MIN_VALUE }); ctov.put(String.class, new Object[] { "", " ", "Texas Fight!", UUID.randomUUID().toString(), null }); return Collections.unmodifiableMap(ctov); }
From source file:org.kuali.kfs.sys.context.DocumentSerializabilityTest.java
/** * Determines if the given class represents one of the eight Java primitives * @param clazz the class to check//w ww. j a v a 2 s .c om * @return true if the class represents a byte, short, int, long, char, double, float, or boolean; false otherwise */ protected boolean isPrimitive(Class<?> clazz) { return Byte.TYPE.isAssignableFrom(clazz) || Short.TYPE.isAssignableFrom(clazz) || Integer.TYPE.isAssignableFrom(clazz) || Long.TYPE.isAssignableFrom(clazz) || Float.TYPE.isAssignableFrom(clazz) || Double.TYPE.isAssignableFrom(clazz) || Character.TYPE.isAssignableFrom(clazz) || Boolean.TYPE.isAssignableFrom(clazz); }
From source file:org.hyperic.lather.util.Latherize.java
public void latherize(boolean xDocletStyle, String outPackage, Class fClass, OutputStream os) throws LatherizeException, IOException { final String INDENT = " "; PrintWriter pWriter;// ww w . j a v a 2 s. c om DynaProperty[] dProps; WrapDynaBean dBean; DynaClass dClass; Object beanInstance; String className, lClassName; try { beanInstance = fClass.newInstance(); } catch (IllegalAccessException exc) { throw new LatherizeException("Illegal access trying to create " + "new instance"); } catch (InstantiationException exc) { throw new LatherizeException("Unable to instantiate: " + exc.getMessage()); } dBean = new WrapDynaBean(beanInstance); dClass = dBean.getDynaClass(); dProps = dClass.getDynaProperties(); pWriter = new PrintWriter(os); className = fClass.getName(); className = className.substring(className.lastIndexOf(".") + 1); lClassName = "Lather" + className; pWriter.println("package " + outPackage + ";"); pWriter.println(); pWriter.println("import " + LatherValue.class.getName() + ";"); pWriter.println("import " + LatherRemoteException.class.getName() + ";"); pWriter.println("import " + LatherKeyNotFoundException.class.getName() + ";"); pWriter.println("import " + fClass.getName() + ";"); pWriter.println(); pWriter.println("public class " + lClassName); pWriter.println(" extends LatherValue"); pWriter.println("{"); for (int i = 0; i < dProps.length; i++) { pWriter.print(" "); if (!this.isLatherStyleProp(dProps[i])) { pWriter.print("// "); } pWriter.println("private static final String " + this.makePropVar(dProps[i]) + " = \"" + dProps[i].getName() + "\";"); } pWriter.println(); pWriter.println(" public " + lClassName + "(){"); pWriter.println(" super();"); pWriter.println(" }"); pWriter.println(); pWriter.println(" public " + lClassName + "(" + className + " v){"); pWriter.println(" super();"); pWriter.println(); for (int i = 0; i < dProps.length; i++) { String propVar = this.makePropVar(dProps[i]); String getter = "v." + this.makeGetter(dProps[i]) + "()"; if (!this.isLatherStyleProp(dProps[i])) { continue; } if (xDocletStyle) { String lName; lName = dProps[i].getName(); lName = lName.substring(0, 1).toLowerCase() + lName.substring(1); pWriter.println(INDENT + "if(v." + lName + "HasBeenSet()){"); pWriter.print(" "); } if (dProps[i].getType().equals(String.class)) { pWriter.println(INDENT + "this.setStringValue(" + propVar + ", " + getter + ");"); } else if (dProps[i].getType().equals(Integer.TYPE)) { pWriter.println(INDENT + "this.setIntValue(" + propVar + ", " + getter + ");"); } else if (dProps[i].getType().equals(Integer.class)) { pWriter.println(INDENT + "this.setIntValue(" + propVar + ", " + getter + ".intValue());"); } else if (dProps[i].getType().equals(Long.TYPE)) { pWriter.println(INDENT + "this.setDoubleValue(" + propVar + ", (double)" + getter + ");"); } else if (dProps[i].getType().equals(Long.class)) { pWriter.println( INDENT + "this.setDoubleValue(" + propVar + ", (double)" + getter + ".longValue());"); } else if (dProps[i].getType().equals(Boolean.TYPE)) { pWriter.println(INDENT + "this.setIntValue(" + propVar + ", " + getter + " ? 1 : 0);"); } else if (dProps[i].getType().equals(Boolean.class)) { pWriter.println( INDENT + "this.setIntValue(" + propVar + ", " + getter + ".booleanValue() ? 1 : 0);"); } else if (dProps[i].getType().equals(Double.TYPE)) { pWriter.println(INDENT + "this.setDoubleValue(" + propVar + ", " + getter + ");"); } else if (dProps[i].getType().equals(Double.class)) { pWriter.println(INDENT + "this.setDoubleValue(" + propVar + ", " + getter + ".doubleValue());"); } else if (dProps[i].getType().equals(byte[].class)) { pWriter.println(INDENT + "this.setByteAValue(" + propVar + ", " + getter + ");"); } else { pWriter.println(INDENT + "this.setObjectValue(" + "DONT KNOW HOW TO HANDLE THIS, " + getter + ");"); } if (xDocletStyle) { pWriter.println(INDENT + "}"); pWriter.println(); } } pWriter.println(" }"); pWriter.println(); pWriter.println(" public " + className + " get" + className + "(){"); pWriter.println(INDENT + className + " r = new " + className + "();"); pWriter.println(); for (int i = 0; i < dProps.length; i++) { String propVar = this.makePropVar(dProps[i]); String setter = "r." + this.makeSetter(dProps[i]) + "("; if (!this.isLatherStyleProp(dProps[i])) { continue; } if (xDocletStyle) { pWriter.println(INDENT + "try {"); pWriter.print(" "); } pWriter.print(INDENT + setter); if (dProps[i].getType().equals(String.class)) { pWriter.println("this.getStringValue(" + propVar + "));"); } else if (dProps[i].getType().equals(Integer.TYPE)) { pWriter.println("this.getIntValue(" + propVar + "));"); } else if (dProps[i].getType().equals(Integer.class)) { pWriter.println("new Integer(this.getIntValue(" + propVar + ")));"); } else if (dProps[i].getType().equals(Long.TYPE)) { pWriter.println("(long)this.getDoubleValue(" + propVar + "));"); } else if (dProps[i].getType().equals(Long.class)) { pWriter.println("new Long((long)this.getDoubleValue(" + propVar + ")));"); } else if (dProps[i].getType().equals(Boolean.TYPE)) { pWriter.println("this.getIntValue(" + propVar + ") == 1 ? " + "true : false);"); } else if (dProps[i].getType().equals(Boolean.class)) { pWriter.println("this.getIntValue(" + propVar + ") == 1 ? " + "Boolean.TRUE : Boolean.FALSE);"); } else if (dProps[i].getType().equals(Double.TYPE)) { pWriter.println("this.getDoubleValue(" + propVar + "));"); } else if (dProps[i].getType().equals(Double.class)) { pWriter.println("new Double(this.getDoubleValue(" + propVar + ")));"); } else if (dProps[i].getType().equals(byte[].class)) { pWriter.println("this.getByteAValue(" + propVar + "));"); } else { pWriter.println("DONT KNOW HOW TO HANDLE " + propVar + "));"); } if (xDocletStyle) { pWriter.println(INDENT + "} catch(LatherKeyNotFoundException " + "exc){}"); pWriter.println(); } } pWriter.println(INDENT + "return r;"); pWriter.println(" }"); pWriter.println(); pWriter.println(" protected void validate()"); pWriter.println(" throws LatherRemoteException"); pWriter.println(" {"); if (!xDocletStyle) { pWriter.println(" try { "); pWriter.println(" this.get" + className + "();"); pWriter.println(" } catch(LatherKeyNotFoundException e){"); pWriter.println(" throw new LatherRemoteException(\"" + "All values not set\");"); pWriter.println(" }"); } pWriter.println(" }"); pWriter.println("}"); pWriter.flush(); }
From source file:com.adobe.acs.commons.mcp.util.AnnotatedFieldDeserializer.java
@SuppressWarnings("squid:S3776") private static Object convertPrimitiveValue(String value, Class<?> type) throws ParseException { if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) { return value.toLowerCase().trim().equals("true"); } else {/*from www . ja va 2 s .c o m*/ NumberFormat numberFormat = NumberFormat.getNumberInstance(); Number num = numberFormat.parse(value); if (type.equals(Byte.class) || type.equals(Byte.TYPE)) { return num.byteValue(); } else if (type.equals(Double.class) || type.equals(Double.TYPE)) { return num.doubleValue(); } else if (type.equals(Float.class) || type.equals(Float.TYPE)) { return num.floatValue(); } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) { return num.intValue(); } else if (type.equals(Long.class) || type.equals(Long.TYPE)) { return num.longValue(); } else if (type.equals(Short.class) || type.equals(Short.TYPE)) { return num.shortValue(); } else { return null; } } }