Java 类java.lang.ClassCastException 实例源码

项目:NetSim    文件:EdgeImp.java   
/**
 * Creates an instance of EdgeImp from a template edge. This template edge
 * must be an instance of <code>Repairable</code> so that the properties 
 * for this edge, such as the probability of failure and the threshold, 
 * and the required generations for repair, can be copied. Other 
 * properties such as capacity, efficiency and cost (properties of 
 * <code>Usable</code> object) are also copied.<p>
 * 
 * Having all relevant properties copied, a complete edge is created by
 * connecting it to the <code>from</code> node and <code>to</code> node,
 * and assigning a label <code>l</code> to it.
 *
 * @param   from FromNode of this edge.
 * @param   to ToNode of this edge.
 * @param   l The label indicating type of this edge
 * @param   e The repairable edge template for this edge. That is
 *          <code>e</code> inherits from <code>Repairable</code>.
 * @throws  ClassCastException If <code>e</code> is not an instance of
 *          <code>Repairable</code>.
 * @throws  PreconditionException If <code>from</code> or <code>to</code>
 *          is Null.
 * @throws  PreconditionException If <code>l</code> is Null.
 * @see     Repairable
 */          
public EdgeImp (Node from, Node to, String l, Edge e)
throws PreconditionException, ClassCastException {
    /**
     * call super class constructor with appropriate parameters obtained
     * from the template edge
     */
    super( ((Repairable) e).getAvgRepGen(),
           ((Repairable) e).getFailureProb(),
           ((Repairable) e).getThreshold(),
           ((Repairable) e).activated() );
    // check preconditions
    Assertion.pre( from != null, "FromNode is not \"null\"",
                                 "FromNode must not be null");
    Assertion.pre( to != null, "ToNode is not \"null\"",
                               "ToNode must not be null");        
    Assertion.pre( l != null, "Label to be set is " + l,
                              "Label to be set must not be null");

    fromNode   = from;                // store the origin node
    toNode     = to;                  // store the end node
    label      = new String(l);       // store the label
    capacity   = e.getMaxCapacity();  // obtain and store values from "e"
    efficiency = e.getEfficiency();
    edgeCost   = e.getCost();
}
项目:pluotsorbet    文件:constructor.java   
/**
 * Runs the test using the specified harness.
 *
 * @param harness  the test harness (<code>null</code> not permitted).
 */
public void test(TestHarness harness)
{
    ClassCastException object1 = new ClassCastException();
    harness.check(object1 != null);
    harness.check(object1.toString(), "java.lang.ClassCastException");

    ClassCastException object2 = new ClassCastException("nothing happens");
    harness.check(object2 != null);
    harness.check(object2.toString(), "java.lang.ClassCastException: nothing happens");

    ClassCastException object3 = new ClassCastException(null);
    harness.check(object3 != null);
    harness.check(object3.toString(), "java.lang.ClassCastException");

}
项目:jmxfetch    文件:Instance.java   
/**
 * Format the instance tags defined in the YAML configuration file to a `LinkedHashMap`.
 * Supported inputs: `List`, `Map`.
 */
private static LinkedHashMap<String, String> getTagsMap(Object tagsMap){
    try {
        // Input has `Map` format
        return (LinkedHashMap<String, String>) tagsMap;
    }
    catch (ClassCastException e){
        // Input has `List` format
        LinkedHashMap<String, String> tags = new LinkedHashMap<String, String>();

        for (String tag: (List<String>)tagsMap) {
            tags.put(tag, null);
        }

        return tags;
    }
}
项目:JavaOutlineEditor    文件:StrungDocumentInfo.java   
public int compareTo(Object obj) {
    String objString = null;
    String ourString = null;

    // if obj is not effectively one of us ...
    if (! this.getClass().isInstance(obj)) {
        throw new ClassCastException ();
    }

    // get the strings
    objString = ((StrungDocumentInfo)obj).getString();
    ourString = string;

    // if we're ignoring case
    if (ignoreCase) {
        // we'll compare in uppercase
        objString = objString.toUpperCase();
        ourString = ourString.toUpperCase();
    }

    // compare
    return ourString.compareTo(objString);
}
项目:JavaOutlineEditor    文件:StrungDocumentInfo.java   
public int compare(Object obj01, Object obj02) {
    String obj01String = null;
    String obj02String = null;

    // if obj01 or obj02 is not effectively one of us ...
    if ( (! this.getClass().isInstance(obj01)) || (! this.getClass().isInstance(obj02)) ) {
        throw new ClassCastException ();
    }

    // get the objects' strings
    obj01String = ((StrungDocumentInfo)obj01).getString();
    obj02String = ((StrungDocumentInfo)obj02).getString();

    // if we're ignoring case
    if (ignoreCase) {
        // we'll compare in uppercase
        obj01String = obj01String.toUpperCase();
        obj02String = obj02String.toUpperCase();
    }

    // compare
    return obj01String.compareTo(obj02String);
}
项目:JavaOutlineEditor    文件:StrungDocumentInfo.java   
public boolean equals(Object obj) {
    String objString = null;
    String ourString = null;

    // if obj is not effectively one of us ...
    if (! this.getClass().isInstance(obj)) {
        throw new ClassCastException ();
    }

    // get the strings
    objString = ((StrungDocumentInfo)obj).getString();
    ourString = string;

    // if we're ignoring case
    if (ignoreCase) {
        // we'll compare in uppercase
        objString = objString.toUpperCase();
        ourString = ourString.toUpperCase();
    }

    // return test result
    return ourString.equals(objString);
}
项目:nightdream    文件:NotificationReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    if (intent == null) return;
    if (isDebuggable){
        Log.d(TAG, "Broadcast received.");
        dumpIntent(intent);
    }

    String action = intent.getStringExtra("action");
    action = (action == null) ? "" : action;

    if (action.equals("clear")) {
        notificationBar.removeAllViews();
        return;
    }

    String packageName = intent.getStringExtra("packageName");
    int iconId = intent.getIntExtra("iconId", -1);
    Drawable icon = getNotificationIcon(context, packageName, iconId);
    if (icon != null) {
        int size = getNotificationIconSize(context);
        Log.i(TAG, String.format("new size is %d", size));
        try {
            icon = resize(context, icon, size);
        } catch (ClassCastException e) {
            // AnimationDrawable cannot be cast to BitmapDrawable
            icon = null;
        }
    }

    if (action.equals("added")) {
        IconView myImage = new IconView(context);
        int padding = Utility.dpToPx(context, 5);
        myImage.setPadding(padding, 0, 0, 0);
        myImage.setImageDrawable(icon);
        myImage.setColorFilter( color, PorterDuff.Mode.SRC_ATOP );
        notificationBar.addView(myImage);
    }
}
项目:adaptive-restful-api    文件:HttpHeaderValueTest.java   
@Test(expectedExceptions = ClassCastException.class)
public void testGetNotSupportedYet() throws Exception {
    HttpHeaderValue value = new HttpHeaderValue("a");

    Boolean b = value.get();
    Integer i = value.get();
    Float f = value.get();
    Double d = value.get();
    Date dt = value.get();
}
项目:NetSim    文件:NodeImp.java   
/**
 * Creates an instance of NodeImp from a template node. This template node
 * must be an instance of <code>Repairable</code> so that the properties 
 * for this node, such as the probability of failure and the threshold, 
 * and the required generations for repair, can be copied. There are some 
 * properties such as capacity and efficiency (similar to properties of 
 * <code>Usable</code> object) that are exclusive to NodeImp. Thus it is
 * assumed that the parameter node "n" must be NodeImp.<p>
 * 
 * Having all relevant properties copied, a complete node is created by
 * assigning a label <code>l</code> to it.<p>
 *
 * @param   l The label indicating type of this node
 * @param   x The X-coordinate of this node
 * @param   y The Y-coordinate of this node
 * @param   n The repairable node template for this node. That is
 *          <code>n</code> inherits from <code>Repairable</code>.
 * @throws  ClassCastException If <code>n</code> is not an instance of
 *          <code>Repairable</code>.
 * @throws  PreconditionException If <code>l</code> is Null.
 * @throws  PreconditionException If <code>x</code> or <code>y</code> are
 *          negative.
 * @see     Repairable
 */          
public NodeImp (String l, int x, int y, Node n)
throws PreconditionException, ClassCastException {
    /**
     * call super class constructor with appropriate parameters obtained
     * from the template node
     */
    super( ((Repairable) n).getAvgRepGen(),
           ((Repairable) n).getFailureProb(),
           ((Repairable) n).getThreshold(),
           ((Repairable) n).activated() );
    // check precondition
    Assertion.pre( l != null, "Label to be set is " + l,
                              "Label to be set must not be null");
    Assertion.pre( (x >= 0) && (y >= 0),
                   "The new coordinates are ("+ x +","+ y +")",
                   "The new coordinates must not be negative");
    label      = new String(l);       // store the label
    /**
     * # Modified by Andy 08/07/05:
     *      Since Node interface no longer extends the Usable interface,
     *      it has not inherited the methods getMaxCapacity and
     *      getEfficiency (please note Efficiency and Utilisation are now
     *      interchangeable terms). Thus "n' must be casted to NodeImp to
     *      use the respective methods.
     */
    capacity   = ((NodeImp)n).getMaxCapacity();  // obtain and store values from "n"
    efficiency = ((NodeImp)n).getEfficiency();
    coord[0] = x;                     // store the coordinates
    coord[1] = y;
}
项目:pluotsorbet    文件:TryCatch.java   
/**
 * Runs the test using the specified harness.
 *
 * @param harness  the test harness (<code>null</code> not permitted).
 */
public void test(TestHarness harness)
{
    // flag that is set when exception is caught
    boolean caught = false;
    try {
        throw new ClassCastException("ClassCastException");
    }
    catch (ClassCastException e) {
        // correct exception was caught
        caught = true;
    }
    harness.check(caught);
}
项目:mpack-java    文件:MPack.java   
@SuppressWarnings("unchecked")
public final <T> List<T> decodeList(Class<T> elementClass) throws IOException {
  final List<?> list = (List) this.decode();
  for (Object obj : list) {
    if (!elementClass.isAssignableFrom(obj.getClass())) {
      throw new ClassCastException("unexpected type found while decoding list: " + obj.getClass().toString());
    }
  }
  return (List<T>) list;
}
项目:mpack-java    文件:MPack.java   
@SuppressWarnings("unchecked")
public final <K, V> Map<K, V> decodeMap(Class<K> keyClass, Class<V> valueClass) throws IOException {
  final Map<?, ?> map = (Map) this.decode();
  for (Map.Entry<?, ?> entry : map.entrySet()) {
    final Object key = entry.getKey();
    final Object value = entry.getValue();
    if (!keyClass.isAssignableFrom(key.getClass())) {
      throw new ClassCastException("unexpected type found while decoding map key: " + key.getClass().toString());
    }
    if (!valueClass.isAssignableFrom(value.getClass())) {
      throw new ClassCastException("unexpected type found while decoding map value: " + value.getClass().toString());
    }
  }
  return (Map<K, V>) map;
}
项目:javify    文件:ParserFactory.java   
/**
    * Create a new SAX parser using the `org.xml.sax.parser' system property.
    *
    * <p>The named class must exist and must implement the
    * {@link org.xml.sax.Parser Parser} interface.</p>
    *
    * @exception java.lang.NullPointerException There is no value
    *            for the `org.xml.sax.parser' system property.
    * @exception java.lang.ClassNotFoundException The SAX parser
    *            class was not found (check your CLASSPATH).
    * @exception IllegalAccessException The SAX parser class was
    *            found, but you do not have permission to load
    *            it.
    * @exception InstantiationException The SAX parser class was
    *            found but could not be instantiated.
    * @exception java.lang.ClassCastException The SAX parser class
    *            was found and instantiated, but does not implement
    *            org.xml.sax.Parser.
    * @see #makeParser(java.lang.String)
    * @see org.xml.sax.Parser
    */
   public static Parser makeParser ()
throws ClassNotFoundException,
IllegalAccessException, 
InstantiationException,
NullPointerException,
ClassCastException
   {
String className = System.getProperty("org.xml.sax.parser");
if (className == null) {
    throw new NullPointerException("No value for sax.parser property");
} else {
    return makeParser(className);
}
   }
项目:javify    文件:ParserFactory.java   
/**
    * Create a new SAX parser object using the class name provided.
    *
    * <p>The named class must exist and must implement the
    * {@link org.xml.sax.Parser Parser} interface.</p>
    *
    * @param className A string containing the name of the
    *                  SAX parser class.
    * @exception java.lang.ClassNotFoundException The SAX parser
    *            class was not found (check your CLASSPATH).
    * @exception IllegalAccessException The SAX parser class was
    *            found, but you do not have permission to load
    *            it.
    * @exception InstantiationException The SAX parser class was
    *            found but could not be instantiated.
    * @exception java.lang.ClassCastException The SAX parser class
    *            was found and instantiated, but does not implement
    *            org.xml.sax.Parser.
    * @see #makeParser()
    * @see org.xml.sax.Parser
    */
   public static Parser makeParser (String className)
throws ClassNotFoundException,
IllegalAccessException, 
InstantiationException,
ClassCastException
   {
return (Parser) NewInstance.newInstance (
    NewInstance.getClassLoader (), className);
   }
项目:jvm-stm    文件:ParserFactory.java   
/**
    * Create a new SAX parser using the `org.xml.sax.parser' system property.
    *
    * <p>The named class must exist and must implement the
    * {@link org.xml.sax.Parser Parser} interface.</p>
    *
    * @exception java.lang.NullPointerException There is no value
    *            for the `org.xml.sax.parser' system property.
    * @exception java.lang.ClassNotFoundException The SAX parser
    *            class was not found (check your CLASSPATH).
    * @exception IllegalAccessException The SAX parser class was
    *            found, but you do not have permission to load
    *            it.
    * @exception InstantiationException The SAX parser class was
    *            found but could not be instantiated.
    * @exception java.lang.ClassCastException The SAX parser class
    *            was found and instantiated, but does not implement
    *            org.xml.sax.Parser.
    * @see #makeParser(java.lang.String)
    * @see org.xml.sax.Parser
    */
   public static Parser makeParser ()
throws ClassNotFoundException,
IllegalAccessException, 
InstantiationException,
NullPointerException,
ClassCastException
   {
String className = System.getProperty("org.xml.sax.parser");
if (className == null) {
    throw new NullPointerException("No value for sax.parser property");
} else {
    return makeParser(className);
}
   }
项目:jvm-stm    文件:ParserFactory.java   
/**
    * Create a new SAX parser object using the class name provided.
    *
    * <p>The named class must exist and must implement the
    * {@link org.xml.sax.Parser Parser} interface.</p>
    *
    * @param className A string containing the name of the
    *                  SAX parser class.
    * @exception java.lang.ClassNotFoundException The SAX parser
    *            class was not found (check your CLASSPATH).
    * @exception IllegalAccessException The SAX parser class was
    *            found, but you do not have permission to load
    *            it.
    * @exception InstantiationException The SAX parser class was
    *            found but could not be instantiated.
    * @exception java.lang.ClassCastException The SAX parser class
    *            was found and instantiated, but does not implement
    *            org.xml.sax.Parser.
    * @see #makeParser()
    * @see org.xml.sax.Parser
    */
   public static Parser makeParser (String className)
throws ClassNotFoundException,
IllegalAccessException, 
InstantiationException,
ClassCastException
   {
return (Parser) NewInstance.newInstance (
    NewInstance.getClassLoader (), className);
   }
项目:JamVM-PH    文件:ParserFactory.java   
/**
    * Create a new SAX parser using the `org.xml.sax.parser' system property.
    *
    * <p>The named class must exist and must implement the
    * {@link org.xml.sax.Parser Parser} interface.</p>
    *
    * @exception java.lang.NullPointerException There is no value
    *            for the `org.xml.sax.parser' system property.
    * @exception java.lang.ClassNotFoundException The SAX parser
    *            class was not found (check your CLASSPATH).
    * @exception IllegalAccessException The SAX parser class was
    *            found, but you do not have permission to load
    *            it.
    * @exception InstantiationException The SAX parser class was
    *            found but could not be instantiated.
    * @exception java.lang.ClassCastException The SAX parser class
    *            was found and instantiated, but does not implement
    *            org.xml.sax.Parser.
    * @see #makeParser(java.lang.String)
    * @see org.xml.sax.Parser
    */
   public static Parser makeParser ()
throws ClassNotFoundException,
IllegalAccessException, 
InstantiationException,
NullPointerException,
ClassCastException
   {
String className = System.getProperty("org.xml.sax.parser");
if (className == null) {
    throw new NullPointerException("No value for sax.parser property");
} else {
    return makeParser(className);
}
   }
项目:JamVM-PH    文件:ParserFactory.java   
/**
    * Create a new SAX parser object using the class name provided.
    *
    * <p>The named class must exist and must implement the
    * {@link org.xml.sax.Parser Parser} interface.</p>
    *
    * @param className A string containing the name of the
    *                  SAX parser class.
    * @exception java.lang.ClassNotFoundException The SAX parser
    *            class was not found (check your CLASSPATH).
    * @exception IllegalAccessException The SAX parser class was
    *            found, but you do not have permission to load
    *            it.
    * @exception InstantiationException The SAX parser class was
    *            found but could not be instantiated.
    * @exception java.lang.ClassCastException The SAX parser class
    *            was found and instantiated, but does not implement
    *            org.xml.sax.Parser.
    * @see #makeParser()
    * @see org.xml.sax.Parser
    */
   public static Parser makeParser (String className)
throws ClassNotFoundException,
IllegalAccessException, 
InstantiationException,
ClassCastException
   {
return (Parser) NewInstance.newInstance (
    NewInstance.getClassLoader (), className);
   }
项目:classpath    文件:ParserFactory.java   
/**
    * Create a new SAX parser using the `org.xml.sax.parser' system property.
    *
    * <p>The named class must exist and must implement the
    * {@link org.xml.sax.Parser Parser} interface.</p>
    *
    * @exception java.lang.NullPointerException There is no value
    *            for the `org.xml.sax.parser' system property.
    * @exception java.lang.ClassNotFoundException The SAX parser
    *            class was not found (check your CLASSPATH).
    * @exception IllegalAccessException The SAX parser class was
    *            found, but you do not have permission to load
    *            it.
    * @exception InstantiationException The SAX parser class was
    *            found but could not be instantiated.
    * @exception java.lang.ClassCastException The SAX parser class
    *            was found and instantiated, but does not implement
    *            org.xml.sax.Parser.
    * @see #makeParser(java.lang.String)
    * @see org.xml.sax.Parser
    */
   public static Parser makeParser ()
throws ClassNotFoundException,
IllegalAccessException, 
InstantiationException,
NullPointerException,
ClassCastException
   {
String className = System.getProperty("org.xml.sax.parser");
if (className == null) {
    throw new NullPointerException("No value for sax.parser property");
} else {
    return makeParser(className);
}
   }
项目:classpath    文件:ParserFactory.java   
/**
    * Create a new SAX parser object using the class name provided.
    *
    * <p>The named class must exist and must implement the
    * {@link org.xml.sax.Parser Parser} interface.</p>
    *
    * @param className A string containing the name of the
    *                  SAX parser class.
    * @exception java.lang.ClassNotFoundException The SAX parser
    *            class was not found (check your CLASSPATH).
    * @exception IllegalAccessException The SAX parser class was
    *            found, but you do not have permission to load
    *            it.
    * @exception InstantiationException The SAX parser class was
    *            found but could not be instantiated.
    * @exception java.lang.ClassCastException The SAX parser class
    *            was found and instantiated, but does not implement
    *            org.xml.sax.Parser.
    * @see #makeParser()
    * @see org.xml.sax.Parser
    */
   public static Parser makeParser (String className)
throws ClassNotFoundException,
IllegalAccessException, 
InstantiationException,
ClassCastException
   {
return (Parser) NewInstance.newInstance (
    NewInstance.getClassLoader (), className);
   }