Example usage for java.lang ClassCastException ClassCastException

List of usage examples for java.lang ClassCastException ClassCastException

Introduction

In this page you can find the example usage for java.lang ClassCastException ClassCastException.

Prototype

public ClassCastException(String s) 

Source Link

Document

Constructs a ClassCastException with the specified detail message.

Usage

From source file:com.ericbarnhill.arrayMath.MathArrayDouble2D.java

protected MathArrayDouble2D divideC(Complex g) {
    throw new ClassCastException("Cannot add Complex number to double array");
}

From source file:com.ericbarnhill.arrayMath.MathArrayDouble3D.java

protected MathArrayDouble3D divideC(Complex g) {
    throw new ClassCastException("Cannot add Complex number to double array");
}

From source file:org.jfree.data.xy.OHLCDataItem.java

/**
 * Compares this object with the specified object for order. Returns a
 * negative integer, zero, or a positive integer as this object is less
 * than, equal to, or greater than the specified object.
 *
 * @param object  the object to compare to.
 *
 * @return A negative integer, zero, or a positive integer as this object
 *         is less than, equal to, or greater than the specified object.
 *//*w  w w  .  j a  va2  s.  c o  m*/
@Override
public int compareTo(Object object) {
    if (object instanceof OHLCDataItem) {
        OHLCDataItem item = (OHLCDataItem) object;
        return this.date.compareTo(item.date);
    } else {
        throw new ClassCastException("OHLCDataItem.compareTo().");
    }
}

From source file:cl.smartcities.isci.transportinspector.fragments.ReportMapFragment.java

@Override
public void onAttach(Context activity) {
    super.onAttach(activity);
    try {/*from   w  w w. j  a va 2 s .  co  m*/
        focusListener = (InterfaceFocusListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement InterfaceFocusListener");
    }
}

From source file:info.magnolia.jcr.util.ContentMap.java

@Override
public Object get(Object key) {
    String keyStr;/*from   w  w w  .  j  a  v a2  s.  c om*/
    try {
        keyStr = (String) key;
    } catch (ClassCastException e) {
        throw new ClassCastException(
                "ContentMap accepts only String as a parameters, provided object was of type "
                        + (key == null ? "null" : key.getClass().getName()));
    }

    Object prop = getNodeProperty(keyStr);
    if (prop == null) {
        keyStr = convertDeprecatedProps(keyStr);
        return getSpecialProperty(keyStr);
    }
    return prop;
}

From source file:com.project.framework.dao.BaseDao.java

/**
 * ?Criteria,.//from  w  w  w.  j a v a  2s.com
 */
protected Criteria setPageParameter(final Criteria c, final Page<T> page) {
    if (page.getStartIndex() > Integer.MAX_VALUE)
        throw new ClassCastException("Hibernate can not support startIndex Greater than Integer.Max");

    //hibernatefirstResult??0
    c.setFirstResult((int) page.getStartIndex());
    c.setMaxResults(page.getPageSize());

    //order by ?
    if (page.isOrder()) {
        Map<String, String> orderMap = page.getOrderMap();
        Iterator<String> iterator = orderMap.keySet().iterator();
        while (iterator.hasNext()) {

            String propertyName = iterator.next();
            if (orderMap.get(propertyName).equals(Page.ORDER_ASC)) {
                c.addOrder(Order.asc(propertyName));
            } else {
                c.addOrder(Order.desc(propertyName));
            }
        }
    }
    return c;
}

From source file:com.dabay6.libraries.androidshared.ui.fragments.LoadingFragment.java

/**
 * {@inheritDoc}//  ww w  . j a  va  2 s  .  c  o m
 */
@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    try {
        callback = (OnRetryListener) activity;
    } catch (final ClassCastException ex) {
        throw new ClassCastException(activity.toString() + " must implement OnRetryListener");
    }
}

From source file:br.com.iworkout.dialog.SerieDialog.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    // Verify that the host activity implements the callback interface
    try {//from   w ww. j av a2s .  c om
        // Instantiate the NoticeDialogListener so we can send events to the host
        mListener = (NoticeDialogListener) activity;
    } catch (ClassCastException e) {
        // The activity doesn't implement the interface, throw exception
        throw new ClassCastException(activity.toString() + " must implement NoticeDialogListener");
    }
}

From source file:com.wolvereness.overmapped.OverMapped.java

private void process() throws Throwable {
    validateInput();/*from w  w w . j a v  a2s. c om*/

    final MultiProcessor executor = MultiProcessor.newMultiProcessor(cores - 1,
            new ThreadFactoryBuilder().setDaemon(true)
                    .setNameFormat(OverMapped.class.getName() + "-processor-%d")
                    .setUncaughtExceptionHandler(this).build());
    final Future<?> fileCopy = executor.submit(new Callable<Object>() {
        @Override
        public Object call() throws Exception {
            if (original != null) {
                if (original.exists()) {
                    original.delete();
                }
                Files.copy(input, original);
            }
            return null;
        }
    });
    final Future<Iterable<?>> mappings = executor.submit(new Callable<Iterable<?>>() {
        @Override
        public Iterable<?> call() throws Exception {
            final Object yaml = new Yaml().load(Files.toString(maps, Charset.forName("UTF8")));
            if (yaml instanceof Iterable)
                return (Iterable<?>) yaml;
            if (yaml instanceof Map)
                return ImmutableList.of(yaml);
            throw new ClassCastException(String.format("%s (%s) implements neither %s nor %s", yaml,
                    yaml == null ? Object.class : yaml.getClass(), Iterable.class, Map.class));
        }
    });

    final Map<String, ByteClass> byteClasses = newLinkedHashMap();
    final List<Pair<ZipEntry, byte[]>> fileEntries = newArrayList();

    readClasses(executor, byteClasses, fileEntries);

    try {
        reorderEntries(byteClasses);
    } catch (final CircularOrderException ex) {
        final Throwable throwable = new MojoFailureException("Circular class hiearchy detected");
        throwable.initCause(ex);
        throw throwable;
    }

    final Multimap<String, String> depends = processDepends(byteClasses);
    final Multimap<String, String> rdepends = processReverseDepends(depends);

    final BiMap<String, String> nameMaps = HashBiMap.create(byteClasses.size());
    final BiMap<String, String> inverseNameMaps = nameMaps.inverse();

    final BiMap<Signature, Signature> signatureMaps = HashBiMap.create();
    final BiMap<Signature, Signature> inverseSignatureMaps = signatureMaps.inverse();

    final Map<Signature, Integer> flags = newHashMap();

    final Remapper inverseMapper = new Remapper() {
        @Override
        public String map(final String typeName) {
            final String name = inverseNameMaps.get(typeName);
            if (name != null)
                return name;
            return typeName;
        }
    };

    prepareSignatures(byteClasses, rdepends, nameMaps, signatureMaps);

    final Signature.MutableSignature signature = Signature.newMutableSignature("", "", "");
    final Set<String> searchCache = newHashSet();

    for (final Object mapping : mappings.get()) {
        final Map<?, ?> map = (Map<?, ?>) mapping;

        for (final SubRoutine subRoutine : SubRoutine.SUB_ROUTINES) {
            try {
                subRoutine.invoke(this, byteClasses, depends, rdepends, nameMaps, inverseNameMaps,
                        signatureMaps, inverseSignatureMaps, inverseMapper, signature, searchCache, flags, map);
            } catch (final Exception ex) {
                final Throwable throwable = new MojoFailureException("Failed to parse mappings in " + mapping);
                throwable.initCause(ex);
                throw throwable;
            }
        }
    }

    try {
        fileCopy.get();
    } catch (final ExecutionException ex) {
        throw new MojoFailureException(String.format("Could not copy `%s' to `%s'", input, original));
    }

    writeToFile(executor, byteClasses, fileEntries, nameMaps, signatureMaps, flags);

    executor.shutdown();

    final Pair<Thread, Throwable> uncaught = this.uncaught;
    if (uncaught != null)
        throw new MojoExecutionException(String.format("Uncaught exception in %s", uncaught.getLeft()),
                uncaught.getRight());
}

From source file:backtype.storm.generated.ExecutorSpecificStats.java

@Override
protected void checkType(_Fields setField, Object value) throws ClassCastException {
    switch (setField) {
    case BOLT:/*  w ww  .  j a v a 2 s  .  c o m*/
        if (value instanceof BoltStats) {
            break;
        }
        throw new ClassCastException("Was expecting value of type BoltStats for field 'bolt', but got "
                + value.getClass().getSimpleName());
    case SPOUT:
        if (value instanceof SpoutStats) {
            break;
        }
        throw new ClassCastException("Was expecting value of type SpoutStats for field 'spout', but got "
                + value.getClass().getSimpleName());
    default:
        throw new IllegalArgumentException("Unknown field id " + setField);
    }
}