List of usage examples for java.lang ClassCastException ClassCastException
public ClassCastException(String s)
ClassCastException
with the specified detail message. From source file:org.apache.solr.kelvin.SimpleClassRegistry.java
public void addMappingsFromClasses(Map<String, Class<?>> mappings) throws ClassNotFoundException { for (Map.Entry<String, Class<?>> entry : mappings.entrySet()) { Class<?> target = entry.getValue(); if (!requiredClass.isAssignableFrom(target)) { throw new ClassCastException( String.format("%s does not implements %s", target.getName(), requiredClass.getName())); }/*from ww w. jav a 2 s .com*/ map.put(entry.getKey(), target); } }
From source file:com.sawyer.advadapters.app.adapters.jsonadapter.JSONAdapterFragment.java
@Override public void setListAdapter(ListAdapter adapter) { if (adapter instanceof MovieJSONAdapter) { super.setListAdapter(adapter); } else {/*from w ww. ja v a2 s . com*/ throw new ClassCastException("Adapter must be of type " + MovieJSONAdapter.class.getSimpleName()); } }
From source file:br.com.bioscada.apps.biotracks.fragments.ChooseAccountDialogFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {/*from w w w .jav a 2 s.c o m*/ caller = (ChooseAccountCaller) activity; } catch (ClassCastException e) { throw new ClassCastException( activity.toString() + " must implement " + ChooseAccountCaller.class.getSimpleName()); } }
From source file:com.sawyer.advadapters.app.adapters.jsonadapter.UnitTestJSONArrayFragment.java
@Override public void setListAdapter(ListAdapter adapter) { if (adapter instanceof UnitTestMovieAdapter) { super.setListAdapter(adapter); } else {/*from w w w .j a v a2 s .co m*/ throw new ClassCastException("Adapter must be of type " + UnitTestMovieAdapter.class.getSimpleName()); } }
From source file:com.digi.android.wva.fragments.ConnectionErrorDialog.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); if (!(activity instanceof ErrorDialogListener)) { throw new ClassCastException(activity.toString() + " must implement ErrorDialogListener!"); }//from w w w . ja v a2 s .c o m }
From source file:com.almende.util.TypeUtil.java
/** * Inject./*from www . jav a2s . c o m*/ * * @param <T> the generic type * @param value the value * @param fullType the full type * @return the t */ @SuppressWarnings("unchecked") public static <T> T inject(final Object value, final JavaType fullType) { if (value == null) { return null; } if (fullType.hasRawClass(Void.class)) { return null; } final ObjectMapper mapper = JOM.getInstance(); if (value instanceof JsonNode) { if (((JsonNode) value).isNull()) { return null; } try { return mapper.convertValue(value, fullType); } catch (final Exception e) { ClassCastException cce = new ClassCastException( "Failed to convert value:" + value + " -----> " + fullType); cce.initCause(e); throw cce; } } if (fullType.getRawClass().isAssignableFrom(value.getClass())) { return (T) value; } else { throw new ClassCastException(value.getClass().getCanonicalName() + " can't be converted to: " + fullType.getRawClass().getCanonicalName()); } }
From source file:dtu.ds.warnme.app.dialog.LoginDialog.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); try {//from w ww . ja v a 2s. c o m listener = (LoginDialogListener) activity; } catch (ClassCastException ex) { throw new ClassCastException(activity.toString() + " must implement LoginDialogListener"); } }
From source file:com.github.neio.filesystem.paths.AbstractPath.java
@SuppressWarnings("unchecked") @Override// w w w. ja va 2 s .c o m public int compareTo(Path o) { if (o != null) { if (ClassUtils.isAssignable(o.getClass(), clazz)) { return howDoICompare((P) o); } else { throw new ClassCastException(o.getClass() + " was not comparable with " + clazz.getName()); } } else { throw new NullPointerException("Path being compared was null"); } }
From source file:edu.wisc.my.stats.web.filter.RelativeDateQueryFilter.java
/** * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) *//*from ww w.j ava2 s . c om*/ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest)) { throw new ClassCastException("RelativeDateQueryFilter can only filter HttpServletRequests"); } boolean useWrapper = false; final WritableHttpServletRequestWrapper wrappedRequestWrapper = new WritableHttpServletRequestWrapper( (HttpServletRequest) request); for (final String dateParameter : this.dateParameters) { final String value = request.getParameter(dateParameter); if (StringUtils.isBlank(value)) { continue; } try { final int dayOffset = Integer.parseInt(value); final Calendar now = Calendar.getInstance(); now.add(Calendar.DAY_OF_YEAR, -1 * dayOffset); final String newValue = this.dateFormat.format(now.getTime()); useWrapper = true; wrappedRequestWrapper.putParameter(dateParameter, newValue); } catch (NumberFormatException nfe) { //Isn't a single number, assume it is a valid Date and just ignore it. } } if (useWrapper) { chain.doFilter(wrappedRequestWrapper, response); } else { chain.doFilter(request, response); } }
From source file:com.sap.core.odata.core.debug.DebugInfoBody.java
@Override public void appendJson(final JsonStreamWriter jsonStreamWriter) throws IOException { final String contentType = response.getContentHeader(); if (contentType.startsWith("image/")) { if (response.getEntity() instanceof InputStream) { jsonStreamWriter.stringValueRaw( Base64.encodeBase64String(getBinaryFromInputStream((InputStream) response.getEntity()))); } else if (response.getEntity() instanceof String) { jsonStreamWriter.stringValueRaw(getContentString()); } else {/* www.j a v a 2s.c om*/ throw new ClassCastException( "Unsupported content entity class: " + response.getEntity().getClass().getName()); } } else if (contentType.startsWith(HttpContentType.APPLICATION_JSON)) { jsonStreamWriter.unquotedValue(getContentString()); } else { jsonStreamWriter.stringValue(getContentString()); } }