List of usage examples for java.lang ClassCastException ClassCastException
public ClassCastException(String s)
ClassCastException
with the specified detail message. From source file:com.andrada.sitracker.ui.fragment.DirectoryChooserFragment.java
@Override public void onAttach(@NotNull Activity activity) { super.onAttach(activity); try {/* w w w . j a v a2 s . c o m*/ mListener = (OnFragmentInteractionListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnFragmentInteractionListener"); } }
From source file:Main.java
/** * Truncate this date, leaving the field specified as the most * significant field./*from w w w.ja va2s. co m*/ * * For example, if you had the datetime of 28 Mar 2002 * 13:45:01.231, if you passed with HOUR, it would return 28 Mar * 2002 13:00:00.000. If this was passed with MONTH, it would * return 1 Mar 2002 0:00:00.000. * * @param date the date to work with, either <code>Date</code> * or <code>Calendar</code> * @param field the field from <code>Calendar</code> * or <code>SEMI_MONTH</code> * @return the rounded date * @throws IllegalArgumentException if the date * is <code>null</code> * @throws ClassCastException if the object type is not a * <code>Date</code> or <code>Calendar</code> * @throws ArithmeticException if the year is over 280 million */ public static Date truncate(Object date, int field) { if (date == null) { throw new IllegalArgumentException("The date must not be null"); } if (date instanceof Date) { return truncate((Date) date, field); } else if (date instanceof Calendar) { return truncate((Calendar) date, field).getTime(); } else { throw new ClassCastException("Could not truncate " + date); } }
From source file:com.andryr.musicplayer.fragments.ArtistFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); mThumbWidth = activity.getResources().getDimensionPixelSize(R.dimen.art_thumbnail_size); mThumbHeight = mThumbWidth;/* w ww .j av a2s .c om*/ try { mActivity = (MainActivity) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnFragmentInteractionListener"); } }
From source file:com.bluecloud.ioc.core.KernelComponentDepender.java
/** * <h3>?</h3>//ww w . ja v a2s . c om * * @param limited * ??? * @param type * * @param size * Component * @param services * ?? * @param context * ??Component? * @return * @throws KernelComponentDependerException * @throws NoSuchMethodException * @throws InvocationTargetException * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException * @throws SecurityException * @throws IllegalArgumentException */ private Object haveLimited(String limited, String type, int size, ServicesMetadata services, ComponentContext context) throws KernelComponentDependerException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException { Class<?> limitedClass = (Class<?>) ClassHandler.getClass(limited, false); if (type.equals("List")) { return this.collectionType(new ArrayList<Object>(size), services, context, limitedClass, limited); } if (type.equals("Set")) { return this.collectionType(new HashSet<Object>(size), services, context, limitedClass, limited); } if (type.equals("Map")) { Map<Object, Object> map = new HashMap<Object, Object>(size); for (ServiceMetadata service : services.getServices()) { Object serviceObject = this.getServiceDepend(service, context); if (limitedClass.isAssignableFrom(serviceObject.getClass())) { if (service.getName() != null) { map.put(service.getName(), serviceObject); } else if (service.getName() == null && service.getBind() != null) { map.put(service.getBind(), serviceObject); } } else { if (log.isErrorEnabled()) { log.error("?" + limited); } throw new ClassCastException(service.getClazz()); } } return map; } if (type.equals("Array")) { Object array = Array.newInstance(limitedClass, size); int index = 0; for (ServiceMetadata service : services.getServices()) { Object serviceObject = this.getServiceDepend(service, context); if (limitedClass.isAssignableFrom(serviceObject.getClass())) { Array.set(array, index, serviceObject); index++; } else { if (log.isErrorEnabled()) { log.error("?" + limited); } throw new ClassCastException(service.getClazz()); } } return array; } return null; }
From source file:org.apache.syncope.core.persistence.beans.user.SyncopeUser.java
@Override public <T extends AbstractVirAttr> boolean addVirtualAttribute(final T virtualAttribute) { if (!(virtualAttribute instanceof UVirAttr)) { throw new ClassCastException( "attribute is expected to be typed UVirAttr: " + virtualAttribute.getClass().getName()); }/*from w ww. ja va 2s .com*/ return virtualAttributes.add((UVirAttr) virtualAttribute); }
From source file:com.p5solutions.core.jpa.orm.EntityParserImpl.java
/** * @see com.p5solutions.core.jpa.orm.EntityParser#findResultsByQuery(java.lang.Class, * com.p5solutions.core.jpa.orm.Query, * com.p5solutions.core.jpa.orm.DependencyJoinFilter) *///w ww . ja va 2 s .c om @Override @SuppressWarnings("unchecked") public <T> List<T> findResultsByQuery(Class<T> entityClass, Query query, DependencyJoinFilter joinFilter) { throwQueryNullException(entityClass, query); String identifier = query.getQueryIdentifier(); if (joinFilter.hasId(identifier)) { JoinFilterItem jf = joinFilter.get(identifier); Object instance = jf.getInstance(); if (instance instanceof List<?>) { return (List<T>) instance; } String error = "Cannot cast object type " + instance + " to a List<" + entityClass + ">"; logger.error(error); throw new ClassCastException(error); } else { String sql = query.getQuery(); RowMapper<T> rowMapper = getRowMapper(entityClass, identifier, joinFilter); SqlParameterSource paramSource = Query.newSQLParameterSource(query, getConversionUtility()); List<T> instances = getJdbcTemplate().query(sql, paramSource, rowMapper); return instances; } }
From source file:ezbake.data.elastic.thrift.FacetResult.java
@Override protected void checkType(_Fields setField, Object value) throws ClassCastException { switch (setField) { case TERMS_FACET_RESULT: if (value instanceof TermsFacetResult) { break; }/*from w ww. j av a 2 s . c o m*/ throw new ClassCastException( "Was expecting value of type TermsFacetResult for field 'termsFacetResult', but got " + value.getClass().getSimpleName()); case RANGE_FACET_RESULT: if (value instanceof RangeFacetResult) { break; } throw new ClassCastException( "Was expecting value of type RangeFacetResult for field 'rangeFacetResult', but got " + value.getClass().getSimpleName()); case DATE_FACET_RESULT: if (value instanceof DateHistogramFacetResult) { break; } throw new ClassCastException( "Was expecting value of type DateHistogramFacetResult for field 'dateFacetResult', but got " + value.getClass().getSimpleName()); case HISTOGRAM_FACET_RESULT: if (value instanceof HistogramFacetResult) { break; } throw new ClassCastException( "Was expecting value of type HistogramFacetResult for field 'histogramFacetResult', but got " + value.getClass().getSimpleName()); case FILTER_FACET_RESULT: if (value instanceof FilterFacetResult) { break; } throw new ClassCastException( "Was expecting value of type FilterFacetResult for field 'filterFacetResult', but got " + value.getClass().getSimpleName()); case TERMS_STATS_FACET_RESULT: if (value instanceof TermsStatsFacetResult) { break; } throw new ClassCastException( "Was expecting value of type TermsStatsFacetResult for field 'termsStatsFacetResult', but got " + value.getClass().getSimpleName()); case STATISTICAL_FACET_RESULT: if (value instanceof StatisticalFacetResult) { break; } throw new ClassCastException( "Was expecting value of type StatisticalFacetResult for field 'statisticalFacetResult', but got " + value.getClass().getSimpleName()); default: throw new IllegalArgumentException("Unknown field id " + setField); } }
From source file:com.graphaware.common.util.PropertyContainerUtils.java
private static int getInt(String pc, String key, Object value) { if (value instanceof Byte) { return ((Byte) value).intValue(); }//from w ww .j a va2s .c om if (value instanceof Integer) { return (Integer) value; } if (value instanceof Long) { return ((Long) value).intValue(); } throw new ClassCastException(value + " is not a number! (" + pc + ", key=" + key + ")"); }
From source file:org.apache.syncope.core.persistence.beans.user.SyncopeUser.java
@Override public <T extends AbstractVirAttr> boolean removeVirtualAttribute(final T virtualAttribute) { if (!(virtualAttribute instanceof UVirAttr)) { throw new ClassCastException( "attribute is expected to be typed UVirAttr: " + virtualAttribute.getClass().getName()); }/* www . j a v a2s .c o m*/ return virtualAttributes.remove((UVirAttr) virtualAttribute); }
From source file:android.com.example.contactslist.ui.ContactsListFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {/* www . j ava 2 s .c om*/ // Assign callback listener which the holding activity must implement. This is used // so that when a contact item is interacted with (selected by the user) the holding // activity will be notified and can take further action such as populating the contact // detail pane (if in multi-pane layout) or starting a new activity with the contact // details (single pane layout). mOnContactSelectedListener = (OnContactsInteractionListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnContactsInteractionListener"); } }