List of usage examples for java.lang ClassCastException ClassCastException
public ClassCastException(String s)
ClassCastException
with the specified detail message. From source file:fiskinfoo.no.sintef.fiskinfoo.MyToolsFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {//from w w w .j ava2 s.co m mListener = (OnFragmentInteractionListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnFragmentInteractionListener"); } }
From source file:com.workplacesystems.utilsj.collections.TransactionalBidiTreeMap.java
/** * check if an object is fit to be proper input ... has to be * Comparable if the comparator has not been set and non-null * * @param o the object being checked//w w w .j ava 2 s .co m * @param index KEY or VALUE (used to put the right word in the * exception message) * * @throws NullPointerException if o is null * @throws ClassCastException if o is not Comparable and the * equivalent comparator has not been set */ private void checkNonNullComparable(final Object o, final int index) { if (o == null) { throw new NullPointerException(dataName[index] + " cannot be null"); } if (comparators[index] == null && !(o instanceof Comparable)) { throw new ClassCastException(dataName[index] + " must be Comparable"); } }
From source file:uk.ac.cam.cl.dtg.segue.api.managers.UserAccountManager.java
/** * Retrieves anonymous user information if it is available. * // w w w. j a v a2s. c o m * @param request * - request containing session information. * @return An anonymous user containing any anonymous question attempts (which could be none) */ private AnonymousUser getAnonymousUserDO(final HttpServletRequest request) { AnonymousUser user; // no session exists so create one. if (request.getSession().getAttribute(ANONYMOUS_USER) == null) { user = new AnonymousUser(request.getSession().getId()); user.setDateCreated(new Date()); // add the user reference to the session request.getSession().setAttribute(ANONYMOUS_USER, user.getSessionId()); this.temporaryUserCache.put(user.getSessionId(), user); } else { // reuse existing one if (request.getSession().getAttribute(ANONYMOUS_USER) instanceof String) { String userId = (String) request.getSession().getAttribute(ANONYMOUS_USER); user = this.temporaryUserCache.getIfPresent(userId); if (null == user) { // the session must have expired. Create a new user and run this method again. // this probably won't happen often as the session expiry and the cache should be timed correctly. request.getSession().removeAttribute(ANONYMOUS_USER); log.warn("Anonymous user session expired so creating a" + " new one - this should not happen often if cache settings are correct."); return this.getAnonymousUserDO(request); } } else { // this means that someone has put the wrong type in to the session variable. throw new ClassCastException("Unable to get AnonymousUser from session."); } } return user; }
From source file:com.clark.func.Functions.java
/** * <p>/*from w ww .j a v a2s .c o m*/ * Round this date, leaving the field specified as the most significant * field. * </p> * * <p> * For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if this * was passed with HOUR, it would return 28 Mar 2002 14:00:00.000. If this * was passed with MONTH, it would return 1 April 2002 0:00:00.000. * </p> * * <p> * For a date in a timezone that handles the change to daylight saving time, * rounding to Calendar.HOUR_OF_DAY will behave as follows. Suppose daylight * saving time begins at 02:00 on March 30. Rounding a date that crosses * this time would produce the following values: * <ul> * <li>March 30, 2003 01:10 rounds to March 30, 2003 01:00</li> * <li>March 30, 2003 01:40 rounds to March 30, 2003 03:00</li> * <li>March 30, 2003 02:10 rounds to March 30, 2003 03:00</li> * <li>March 30, 2003 02:40 rounds to March 30, 2003 04:00</li> * </ul> * </p> * * @param date * the date to work with, either Date or Calendar * @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 roundDateOrCalender(Object date, int field) { if (date == null) { throw new IllegalArgumentException("The date must not be null"); } if (date instanceof Date) { return roundDate((Date) date, field); } else if (date instanceof Calendar) { return roundCalendar((Calendar) date, field).getTime(); } else { throw new ClassCastException("Could not round " + date); } }
From source file:com.clark.func.Functions.java
/** * <p>//from w w w . j ava 2s . c o m * Truncate this date, leaving the field specified as the most significant * field. * </p> * * <p> * 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. * </p> * * @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 truncateDateOrCalender(Object date, int field) { if (date == null) { throw new IllegalArgumentException("The date must not be null"); } if (date instanceof Date) { return truncateDate((Date) date, field); } else if (date instanceof Calendar) { return truncateCalendar((Calendar) date, field).getTime(); } else { throw new ClassCastException("Could not truncate " + date); } }
From source file:com.clark.func.Functions.java
/** * <p>//www .j a v a 2 s . c om * Ceil this date, leaving the field specified as the most significant * field. * </p> * * <p> * 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. * </p> * * @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 * @since 2.5 */ public static Date ceilingDateOrCalender(Object date, int field) { if (date == null) { throw new IllegalArgumentException("The date must not be null"); } if (date instanceof Date) { return ceilingDate((Date) date, field); } else if (date instanceof Calendar) { return ceilingCalendar((Calendar) date, field).getTime(); } else { throw new ClassCastException("Could not find ceiling of for type: " + date.getClass()); } }
From source file:com.clark.func.Functions.java
/** * <p>//from www. j a v a 2s .c om * This constructs an <code>Iterator</code> over each day in a date range * defined by a focus date and range style. * </p> * * <p> * For instance, passing Thursday, July 4, 2002 and a * <code>RANGE_MONTH_SUNDAY</code> will return an <code>Iterator</code> that * starts with Sunday, June 30, 2002 and ends with Saturday, August 3, 2002, * returning a Calendar instance for each intermediate day. * </p> * * @param focus * the date to work with, either <code>Date</code> or * <code>Calendar</code> * @param rangeStyle * the style constant to use. Must be one of the range styles * listed for the {@link #iteratorDateOrCalender(Calendar, int)} * method. * @return the date iterator * @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> */ public static Iterator<?> iteratorDateOrCalender(Object focus, int rangeStyle) { if (focus == null) { throw new IllegalArgumentException("The date must not be null"); } if (focus instanceof Date) { return iteratorCalendar((Date) focus, rangeStyle); } else if (focus instanceof Calendar) { return iteratorDateOrCalender((Calendar) focus, rangeStyle); } else { throw new ClassCastException("Could not iterate based on " + focus); } }