Example usage for java.lang CloneNotSupportedException printStackTrace

List of usage examples for java.lang CloneNotSupportedException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java

/**
 * Confirm that cloning works./*w  w w . j  a v a  2s.c om*/
 */
public void testCloning() {
    XYSeries s1 = new XYSeries("Series");
    s1.add(1.0, 1.1);
    XYSeriesCollection c1 = new XYSeriesCollection();
    c1.addSeries(s1);
    XYSeriesCollection c2 = null;
    try {
        c2 = (XYSeriesCollection) c1.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
        assertTrue(false);
        return;
    }
    assertTrue(c1 != c2);
    assertTrue(c1.getClass() == c2.getClass());
    assertTrue(c1.equals(c2));

    // check independence
    s1.setDescription("XYZ");
    assertFalse(c1.equals(c2));
}

From source file:main.java.edu.isistan.genCom.redSocial.RedSocial.java

/**
 * Returns the degree of reachability by getting the distances of every pair of vertices in the network when a vertices set is removed
 * network/*w  w w  .  j  ava 2s  .c o  m*/
 * 
 * Degree of reachability by Borgatti
 * 
 * @param comission
 *            Nodes to be removed
 * @return List of distances
 */
public List<Double> getDegreeOfReachability(List<Investigador> comission) {
    List<Double> distancias = new ArrayList<>();

    try {
        RedSocial reduced = null;

        reduced = (RedSocial) this.clone();

        Set<Investigador> invSet = new HashSet<>(getNodos());
        invSet.removeAll(comission);

        reduced.reducirA(invSet);

        UnweightedShortestPath<Investigador, String> uWSP = new UnweightedShortestPath(reduced.getRed());

        List<Investigador> nodos = reduced.getNodos();

        for (int i = 0; i < nodos.size(); i++) {
            Investigador inv1 = nodos.get(i);

            for (int j = 0; j < i; j++) {
                Investigador inv2 = nodos.get(j);

                Number dist = uWSP.getDistance(inv1, inv2);

                Double d = dist != null ? dist.doubleValue() : Double.POSITIVE_INFINITY;

                distancias.add(d);
            }
        }

    } catch (CloneNotSupportedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return distancias;
}

From source file:org.jfree.data.junit.DefaultKeyedValuesTests.java

/**
 * Some checks for the clone() method./* w w w .jav a  2 s. c  o m*/
 */
public void testCloning() {
    DefaultKeyedValues v1 = new DefaultKeyedValues();
    v1.addValue("V1", new Integer(1));
    v1.addValue("V2", null);
    v1.addValue("V3", new Integer(3));
    DefaultKeyedValues v2 = null;
    try {
        v2 = (DefaultKeyedValues) v1.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    assertTrue(v1 != v2);
    assertTrue(v1.getClass() == v2.getClass());
    assertTrue(v1.equals(v2));

    // confirm that the clone is independent of the original
    v2.setValue("V1", new Integer(44));
    assertFalse(v1.equals(v2));
}

From source file:com.ibm.jaggr.service.impl.deps.DepTree.java

/**
 * Returns a new tree with an unnamed {@link DepTreeNode} object at the root
 * of the tree. Each of the keys specified in the map are children of the
 * returned node and those node's children are the children of the nodes 
 * corresponding to the resource URIs specified by the map values.
 * The map values must be the same as, or a subset of, the paths that
 * were used to create this instance.//ww w.  jav a2s .com
 * 
 * @param map
 *            A map of module names to resource URIs
 * 
 * @return The root {@link DepTreeNode} for the new tree
 */
public DepTreeRoot mapDependencies(DepTreeRoot root, BundleContext context, Map<String, URI> map,
        IConfig config) {
    // For each config path entry...
    for (Entry<String, URI> configPathEntry : map.entrySet()) {
        String name = configPathEntry.getKey();
        // make sure name is valid
        if (name.startsWith("/")) { //$NON-NLS-1$
            log.severe(MessageFormat.format(Messages.DepTree_8, new Object[] { name }));
            throw new IllegalArgumentException(name);
        }

        // make sure no relative path components (./ ore ../).
        for (String part : name.split("/")) { //$NON-NLS-1$
            if (part.startsWith(".")) { //$NON-NLS-1$
                log.severe(MessageFormat.format(Messages.DepTree_9, new Object[] { name }));
                throw new IllegalArgumentException(name);
            }
        }

        // Create the child node for this entry's package/path name
        DepTreeNode target = root.createOrGet(name);
        URI filePath = configPathEntry.getValue();

        /*
         * Get the root node corresponding to the entry's file path from the
         * map. This node does not have any resolved references and the
         * module names in the dependency lists may contain relative paths.
         * Note that the node may be null if the config specifies a path
         * that is not found.
         */
        DepTreeNode source = DepUtils.getNodeForResource(filePath, depMap);
        if (source != null) {
            /*
             * Clone the tree and copy the cloned node's children to the 
             * target node.
             */
            DepTreeNode temp = null;
            try {
                temp = source.clone();
            } catch (CloneNotSupportedException e) {
                // won't happen, but the language requires us to handle it.
                e.printStackTrace();
            }
            target.overlay(temp);
        }
    }

    return root;
}

From source file:com.stromberglabs.jopensurf.Surf.java

private List<SURFInterestPoint> getDescriptorFreeInterestPoints() {
    List<SURFInterestPoint> points = new ArrayList<SURFInterestPoint>(mDescriptorFreeInterestPoints.size());
    for (SURFInterestPoint point : mDescriptorFreeInterestPoints) {
        try {//  w  w w  .  j a v  a  2s . co m
            points.add((SURFInterestPoint) point.clone());
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
    }
    return points;
}

From source file:org.jfree.data.junit.KeyedObjectsTests.java

/**
 * Confirm that cloning works.//  w  w w .j av  a2  s.co m
 */
public void testCloning() {
    KeyedObjects ko1 = new KeyedObjects();
    ko1.addObject("V1", new Integer(1));
    ko1.addObject("V2", null);
    ko1.addObject("V3", new Integer(3));
    KeyedObjects ko2 = null;
    try {
        ko2 = (KeyedObjects) ko1.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    assertTrue(ko1 != ko2);
    assertTrue(ko1.getClass() == ko2.getClass());
    assertTrue(ko1.equals(ko2));
}

From source file:org.jfree.data.junit.KeyedObjectsTests.java

/**
 * Confirm special features of cloning./*from w  ww  .  j ava2  s.  c  o m*/
 */
public void testCloning2() {
    // case 1 - object is mutable but not PublicCloneable
    Object obj1 = new ArrayList();
    KeyedObjects ko1 = new KeyedObjects();
    ko1.addObject("K1", obj1);
    KeyedObjects ko2 = null;
    try {
        ko2 = (KeyedObjects) ko1.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    assertTrue(ko1 != ko2);
    assertTrue(ko1.getClass() == ko2.getClass());
    assertTrue(ko1.equals(ko2));

    // the clone contains a reference to the original object
    assertTrue(ko2.getObject("K1") == obj1);

    // CASE 2 - object is mutable AND PublicCloneable
    obj1 = new DefaultPieDataset();
    ko1 = new KeyedObjects();
    ko1.addObject("K1", obj1);
    ko2 = null;
    try {
        ko2 = (KeyedObjects) ko1.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    assertTrue(ko1 != ko2);
    assertTrue(ko1.getClass() == ko2.getClass());
    assertTrue(ko1.equals(ko2));

    // the clone contains a reference to a CLONE of the original object
    assertTrue(ko2.getObject("K1") != obj1);
}

From source file:org.apache.slide.lock.NodeLock.java

/**
 * Clone.// w ww .java2s.com
 * 
 * @return Object clone
 */
public NodeLock cloneObject() {
    NodeLock result = null;
    try {
        result = (NodeLock) super.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:com.supremainc.biostar2.user.UserListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (super.onOptionsItemSelected(item)) {
        return true;
    }/*w w  w  . j a  v a2s  .  co  m*/
    if (mSubToolbar != null) {
        mSubToolbar.hideIme();
    }
    switch (item.getItemId()) {
    case R.id.action_delete_confirm:
        int selectedCount = mUserAdapter.getCheckedItemCount();
        if (selectedCount < 1) {
            mToastPopup.show(getString(R.string.selected_none), null);
            return true;
        }
        deleteConfirm(selectedCount);
        break;
    case R.id.action_delete:
        setSubMode(MODE_DELETE);
        break;
    case R.id.action_add:
        if (mUserGroup == null) {
            mScreenControl.addScreen(ScreenType.USER_MODIFY, null);
        } else {
            UserGroup userGroup = null;
            try {
                userGroup = mUserGroup.clone();
            } catch (CloneNotSupportedException e) {
                Log.e(TAG, "selected user clone fail");
                e.printStackTrace();
            }
            Bundle bundle = new Bundle();
            bundle.putSerializable(UserGroup.TAG, userGroup);
            mScreenControl.addScreen(ScreenType.USER_MODIFY, bundle);
        }
        return true;
    case R.id.action_usergroups:
        mSelectUserGroupsPopup.show(SelectType.USER_GROUPS, new OnSelectResultListener<UserGroup>() {
            @Override
            public void OnResult(ArrayList<UserGroup> selectedItem) {
                if (isInValidCheck(null)) {
                    return;
                }
                if (selectedItem == null) {
                    return;
                }
                mUserGroup = selectedItem.get(0);
                if (mUserAdapter != null) {
                    mUserAdapter.setUserGroupId(mUserGroup.id);
                }
                mTitle = mUserGroup.name;
                initActionbar(mUserGroup.name);
            }
        }, null, getString(R.string.select_user_group), false);
        break;
    default:
        break;
    }
    return false;
}

From source file:com.ibm.jaggr.core.impl.deps.DepTree.java

/**
 * Returns a new tree with an unnamed {@link DepTreeNode} object at the root
 * of the tree. Each of the keys specified in the map are children of the
 * returned node and those node's children are the children of the nodes
 * corresponding to the resource URIs specified by the map values.
 * The map values must be the same as, or a subset of, the paths that
 * were used to create this instance.//from w w w .jav a  2 s . c  om
 *
 * @param root
 *            The root tree node
 * @param map
 *            A map of module names to resource URIs
 * @param failIfNoExist
 *            if true, then an {@link IllegalStateException} is thrown if
 *            any of the resources in <code>map</code> don't exist
 *
 * @return The root {@link DepTreeNode} for the new tree
 */
public DepTreeRoot mapDependencies(DepTreeRoot root, Map<String, URI> map, boolean failIfNoExist) {
    // For each config path entry...
    for (Entry<String, URI> configPathEntry : map.entrySet()) {
        String name = configPathEntry.getKey();
        // make sure name is valid
        if (name.startsWith("/")) { //$NON-NLS-1$
            log.severe(MessageFormat.format(Messages.DepTree_8, new Object[] { name }));
            throw new IllegalArgumentException(name);
        }

        // make sure no relative path components (./ ore ../).
        for (String part : name.split("/")) { //$NON-NLS-1$
            if (part.startsWith(".")) { //$NON-NLS-1$
                log.severe(MessageFormat.format(Messages.DepTree_9, new Object[] { name }));
                throw new IllegalArgumentException(name);
            }
        }

        URI filePath = configPathEntry.getValue();

        /*
         * Get the root node corresponding to the entry's file path from the
         * map. This node does not have any resolved references and the
         * module names in the dependency lists may contain relative paths.
         * Note that the node may be null if the config specifies a path
         * that is not found.
         */
        DepTreeNode source = DepUtils.getNodeForResource(filePath, depMap);
        if (source != null) {
            // Create the child node for this entry's package/path name
            DepTreeNode target = root.createOrGet(name, filePath);
            /*
             * Clone the tree and copy the cloned node's children to the
             * target node.
             */
            DepTreeNode temp = null;
            try {
                temp = source.clone();
            } catch (CloneNotSupportedException e) {
                // won't happen, but the language requires us to handle it.
                e.printStackTrace();
            }
            target.overlay(temp);
        } else if (failIfNoExist) {
            throw new IllegalStateException("Missing required resource: " + filePath); //$NON-NLS-1$
        }
    }

    return root;
}