List of usage examples for java.lang Class equals
public boolean equals(Object obj)
From source file:ClassComparator.java
/** * Compares its two arguments for order. Returns a negative integer, zero, or * a positive integer as the first argument is less than, equal to, or greater * than the second.// w w w . j a va2 s . c om * <p> * <P> * Note: throws ClassCastException if the arguments' types prevent them from * being compared by this Comparator. And IllegalArgumentException if the * classes share no relation. * * The implementor must ensure that <tt>sgn(compare(x, y)) == * -sgn(compare(y, x))</tt> * for all <tt>x</tt> and <tt>y</tt>. (This implies that * <tt>compare(x, y)</tt> must throw an exception if and only if * <tt>compare(y, x)</tt> throws an exception.) * <p> * * The implementor must also ensure that the relation is transitive: * <tt>((compare(x, y)>0) && (compare(y, z)>0))</tt> implies * <tt>compare(x, z)>0</tt>. * <p> * * Finally, the implementer must ensure that <tt>compare(x, y)==0</tt> * implies that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all * <tt>z</tt>. * <p> * * It is generally the case, but <i>not</i> strictly required that * <tt>(compare(x, y)==0) == (x.equals(y))</tt>. Generally speaking, any * comparator that violates this condition should clearly indicate this fact. * The recommended language is "Note: this comparator imposes orderings that * are inconsistent with equals." * * @param o1 * the first object to be compared. * @param o2 * the second object to be compared. * @return a negative integer, zero, or a positive integer as the first * argument is less than, equal to, or greater than the second. */ public int compare(final Object o1, final Object o2) { final Class c1 = (Class) o1; final Class c2 = (Class) o2; if (c1.equals(o2)) { return 0; } if (c1.isAssignableFrom(c2)) { return -1; } else { if (!c2.isAssignableFrom(c2)) { throw new IllegalArgumentException("The classes share no relation"); } return 1; } }
From source file:org.sakaiproject.poll.tool.validators.VoteValidator.java
public boolean supports(Class clazz) { // TODO Auto-generated method stub return clazz.equals(VoteCollection.class); }
From source file:com.google.gplus.processor.GooglePlusTypeConverter.java
private Object deserializeItem(Object item) { try {/*from ww w . j av a 2 s . c o m*/ Class klass = GPlusEventClassifier.detectClass((String) item); if (klass.equals(Person.class)) { item = mapper.readValue((String) item, Person.class); } else if (klass.equals(com.google.api.services.plus.model.Activity.class)) { item = mapper.readValue((String) item, com.google.api.services.plus.model.Activity.class); } } catch (Exception e) { LOGGER.error("Exception while trying to deserializeItem: {}", e); } return item; }
From source file:org.dawnsci.persistence.json.function.FunctionBean.java
/** * Method that converts a function bean to an IFunction using reflection * /* w w w . ja v a 2s . co m*/ * @return IFunction * @throws ClassNotFoundException * @throws SecurityException * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalArgumentException * @throws IllegalAccessException * @throws InstantiationException */ @JsonIgnore public IFunction getIFunction() throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { IFunction function = null; IParameter[] params = getParameters(); Class<?> clazz = Class.forName(getType()); // If a Jexl expression if (clazz.equals(JexlExpressionFunction.class)) { Constructor<?> constructor = clazz.getConstructor(String.class); function = (IFunction) constructor.newInstance((String) getName()); for (int i = 0; i < params.length; i++) { ((JexlExpressionFunction) function).setParameter(i, params[i]); } } else { // For all other cases try to return an instance of IFunction with parameters Constructor<?> constructor = clazz.getConstructor(IParameter[].class); function = (IFunction) constructor.newInstance((Object) params); } return function; }
From source file:com.vrem.wifianalyzer.MainContextHelper.java
public void restore() { IterableUtils.forEach(saved.keySet(), new Closure<Class>() { @Override//from ww w . j a va 2 s . c o m public void execute(Class input) { Object result = saved.get(input); if (input.equals(Settings.class)) { mainContext.setSettings((Settings) result); } else if (input.equals(VendorService.class)) { mainContext.setVendorService((VendorService) result); } else if (input.equals(Scanner.class)) { mainContext.setScanner((Scanner) result); } else if (input.equals(MainActivity.class)) { mainContext.setMainActivity((MainActivity) result); } else if (input.equals(Database.class)) { mainContext.setDatabase((Database) result); } else if (input.equals(Configuration.class)) { mainContext.setConfiguration((Configuration) result); } else if (input.equals(FilterAdapter.class)) { mainContext.setFilterAdapter((FilterAdapter) result); } else { throw new IllegalArgumentException(input.getName()); } } }); saved.clear(); }
From source file:eu.dime.ps.dto.Profile.java
@Override public <T extends org.ontoware.rdfreactor.schema.rdfs.Resource> T asResource(Class<T> returnType, URI me) { if (!returnType.equals(PersonContact.class)) { throw new IllegalArgumentException("Only PersonContact class is allowed!"); }/*from ww w. jav a 2s .c om*/ return (T) asResource(URIGenerator.createNewRandomUniqueURI(), me); }
From source file:eu.dime.ps.dto.Profile.java
public <T extends org.ontoware.rdfreactor.schema.rdfs.Resource> T asResource(URI resourceUri, Class<T> returnType, URI me) { if (!returnType.equals(PersonContact.class)) { throw new IllegalArgumentException("Only PersonContact class is allowed!"); }/*w w w . ja v a 2 s.c o m*/ return (T) asResource(resourceUri, me); }
From source file:de.perdian.commons.lang.conversion.impl.converters.StringToDateConverter.java
@Override protected Date convertUsingFormat(DateFormat dateFormat, String source) { Date utilDateValue = this.parseUsingFormat(dateFormat, source); Class<? extends Date> targetDateClass = this.getTargetDateClass(); if (targetDateClass == null || targetDateClass.equals(java.util.Date.class)) { return utilDateValue; } else if (targetDateClass.equals(java.sql.Date.class)) { return new java.sql.Date(utilDateValue.getTime()); } else if (targetDateClass.equals(java.sql.Timestamp.class)) { return new java.sql.Timestamp(utilDateValue.getTime()); } else if (targetDateClass.equals(java.sql.Time.class)) { return new java.sql.Time(utilDateValue.getTime()); } else {/*from www . j a v a 2s . c om*/ throw new IllegalArgumentException( "Cannot convert date into target object of class: " + targetDateClass.getName()); } }
From source file:uapi.service.JsonStringCodec.java
@Override public String decode(final Object value, final Class type) throws KernelException { ArgumentChecker.required(value, "value"); ArgumentChecker.required(type, "type"); if (type.equals(String.class) && value instanceof String) { return value.toString(); }// w w w . j a v a2 s. co m try { return JSON.std.asString(value); } catch (Exception ex) { throw new KernelException(ex); } }