1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
987 public void remove() {
988 itr.remove();
989 }
990 }
991
992 @SuppressWarnings("unchecked")
993 private LinkedList<E> superClone() {
994 try {
995 return (LinkedList<E>) super.clone();
996 } catch (CloneNotSupportedException e) {
997 throw new InternalError(e);
998 }
999 }
1000
1001 /**
1002 * Returns a shallow copy of this {@code LinkedList}. (The elements
1003 * themselves are not cloned.)
1004 *
1005 * @return a shallow copy of this {@code LinkedList} instance
1006 */
1007 public Object clone() {
1008 LinkedList<E> clone = superClone();
1009
1010 // Put clone into "virgin" state
1011 clone.first = clone.last = null;
1012 clone.size = 0;
1013 clone.modCount = 0;
1014
1015 // Initialize clone with our elements
1016 for (Node<E> x = first; x != null; x = x.next)
1017 clone.add(x.item);
1018
1019 return clone;
1020 }
1021
1022 /**
1023 * Returns an array containing all of the elements in this list
1024 * in proper sequence (from first to last element).
1025 *
1026 * <p>The returned array will be "safe" in that no references to it are
1027 * maintained by this list. (In other words, this method must allocate
|
1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
987 public void remove() {
988 itr.remove();
989 }
990 }
991
992 @SuppressWarnings("unchecked")
993 private LinkedList<E> superClone() {
994 try {
995 return (LinkedList<E>) super.clone();
996 } catch (CloneNotSupportedException e) {
997 throw new InternalError(e);
998 }
999 }
1000
1001 /**
1002 * Returns a shallow copy of this {@code LinkedList}. (The elements
1003 * themselves are not cloned.)
1004 *
1005 * @return a shallow copy of this {@code LinkedList} instance
1006 */
1007 @Override
1008 public LinkedList<E> clone() {
1009 LinkedList<E> clone = superClone();
1010
1011 // Put clone into "virgin" state
1012 clone.first = clone.last = null;
1013 clone.size = 0;
1014 clone.modCount = 0;
1015
1016 // Initialize clone with our elements
1017 for (Node<E> x = first; x != null; x = x.next)
1018 clone.add(x.item);
1019
1020 return clone;
1021 }
1022
1023 /**
1024 * Returns an array containing all of the elements in this list
1025 * in proper sequence (from first to last element).
1026 *
1027 * <p>The returned array will be "safe" in that no references to it are
1028 * maintained by this list. (In other words, this method must allocate
|