From eb94a026a78a6bf805ac15c22746a69345921ed2 Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Thu, 8 Feb 2024 14:01:43 -0600 Subject: [PATCH] broken code :) --- .gitignore | 2 + .../ManyToManyFactory.java | 139 +- .../MapASDV_CalebFontenot/build.xml | 73 + .../MapASDV_CalebFontenot/manifest.mf | 3 + .../nbproject/build-impl.xml | 1799 +++++++++++++++++ .../nbproject/genfiles.properties | 8 + .../nbproject/project.properties | 95 + .../nbproject/project.xml | 16 + .../src/mapasdv_calebfontenot/ListASDV.java | 1694 ++++++++++++++++ .../src/mapasdv_calebfontenot/MapASDV.java | 796 ++++++++ .../ZIPs/MP1_ManyToMany_CalebFontenot.zip | Bin 0 -> 7357 bytes 11 files changed, 4582 insertions(+), 43 deletions(-) create mode 100644 Semester 4/Assignments/MapASDV_CalebFontenot/build.xml create mode 100644 Semester 4/Assignments/MapASDV_CalebFontenot/manifest.mf create mode 100644 Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/build-impl.xml create mode 100644 Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/genfiles.properties create mode 100644 Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/project.properties create mode 100644 Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/project.xml create mode 100644 Semester 4/Assignments/MapASDV_CalebFontenot/src/mapasdv_calebfontenot/ListASDV.java create mode 100644 Semester 4/Assignments/MapASDV_CalebFontenot/src/mapasdv_calebfontenot/MapASDV.java create mode 100644 Semester 4/ZIPs/MP1_ManyToMany_CalebFontenot.zip diff --git a/.gitignore b/.gitignore index bc44d97..f133c83 100644 --- a/.gitignore +++ b/.gitignore @@ -205,3 +205,5 @@ /Semester 4/Assignments/HashMapASDV_Ant/dist/ /Semester 4/Assignments/MP1_ManyToMany_CalebFontenot/target/ /Semester 4/Assignments/Multithreading_CalebFontenot/target/ +/Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/private/ +/Semester 4/Assignments/MapASDV_CalebFontenot/build/ diff --git a/Semester 4/Assignments/MP1_ManyToMany_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp1_manytomany_calebfontenot/ManyToManyFactory.java b/Semester 4/Assignments/MP1_ManyToMany_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp1_manytomany_calebfontenot/ManyToManyFactory.java index cc64074..7393148 100644 --- a/Semester 4/Assignments/MP1_ManyToMany_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp1_manytomany_calebfontenot/ManyToManyFactory.java +++ b/Semester 4/Assignments/MP1_ManyToMany_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/mp1_manytomany_calebfontenot/ManyToManyFactory.java @@ -14,6 +14,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; /** @@ -24,24 +25,20 @@ public class ManyToManyFactory { public static //generic types to be used in the method ManyToMany< Many1, Many2>//return type - createManyToMany() - { + createManyToMany() { return new ManyToMany() { - //private HashSet parents = new HashSet(); - - private Map left = new HashMap(); - private Map right = new HashMap(); + private HashSet parents = new HashSet<>(); + + private Map left = new HashMap<>(); + private Map right = new HashMap<>(); @Override - public String toString() - { + public String toString() { return "{" + "left=" + left + ", right=" + right + '}'; } /** - * Creates a Many to Many relationship between the parentLeft and the childrenRight. - * Example for ( Many1 a, Many2 1, 2, 3) it creates --> (a 1) ( a 2 ) ( a 3 ) and ( 1, a ), ( 2, a ), ( 3, a). - * No duplicate values of Many2 are allowed. + * Creates a Many to Many relationship between the parentLeft and the childrenRight. Example for ( Many1 a, Many2 1, 2, 3) it creates --> (a 1) ( a 2 ) ( a 3 ) and ( 1, a ), ( 2, a ), ( 3, a). No duplicate values of Many2 are allowed. * * @param parentLeft - exactly one Many1 object. * @param childrenRight - one or more Many2 objects. @@ -52,70 +49,126 @@ public class ManyToManyFactory { * @return the previous value associated with parentLeft, or null if there was no childrenRight for parentLeft. */ @Override - public List add(Many1 parentLeft, Many2... childrenRight) - { - List returnList = new ArrayList(); - + public List add(Many1 parentLeft, Many2... childrenRight) { + HashSet verifyUnique = new HashSet<>(); + List returnList = new ArrayList<>(); + // Check for exceptions if (!childrenRight.equals(parentLeft.getClass())) { - throw new ClassCastException(); + //throw new ClassCastException(); + } + if (parentLeft == null || childrenRight == null) { + throw new NullPointerException(); + } + // Try to add all elements from childrenRight into HashSet. If we're unable to, through an IllegalArgumentException, assuming HashSet doesn't throw one already. + verifyUnique.addAll(Arrays.asList(childrenRight)); + if (left.size() > 0 && childrenRight.length > 0) { + for (Object e : left.values()) { + returnList.add((Many2) e); + } + //returnList.addAll(() left.values()); + } + // Keep track of the parents so we can manipulate the RHS + parents.add(parentLeft); + // Handle LHS + //for (Many2 e : childrenRight) { + left.put(parentLeft, new ArrayList(Arrays.asList(childrenRight))); + //} + //Handle RHS + /* + for (Many1 e: parents) { + + right.put(, e ); + } + */ + if (returnList.size() == 0) { + return null; } - left.put(parentLeft, new ArrayList(Arrays.asList(childrenRight))); return returnList; } + /** + * Returns the List of all left children of the parentRight. + * + * @param parentRight a parent at the RHS of the many to many relationship. + * @return the List of all left children of the parentRight. + * @throw IllegalArgumentException if the value of parameter parentRight does not exist in the RHS of the many to many relationship. + */ @Override - public List getChildrenLeft(Many2 parentRight) - { + public List getChildrenLeft(Many2 parentRight) { + List returnList = new ArrayList(); + for (Entry ee : left.entrySet()) { + System.out.println(ee.getKey() + ", " + parentRight); + if (ee.getKey().equals(parentRight)) { + returnList.add((Many1) ee.getValue()); + } + } + if (returnList.size() > 0) { + return null; + } + return returnList; + } + + /** + * Returns the List of all right children of the parentLeft. + * + * @param parentLeft a parent at the LHS of the many to many relationship. + * @return the List of all right children of the parentLeft. + * @throws IllegalArgumentException if the value of parameter parentLeft does not exist on the LHS of the many to many relationship. + */ + @Override + public List getChildrenRight(Many1 parentLeft) { + List returnList = new ArrayList<>(); + for (Entry ee : right.entrySet()) { + if (ee.getKey() == parentLeft) { + returnList.add((Many2) ee.getValue()); + } + } + if (returnList.size() > 0) { + return null; + } + return returnList; + } + + /** + * Returns a set of the Many1 elements that exist on the LHS of the many to many relationship. + * + * @return Set of Many1 + */ + @Override + public Set getParentsLeft() { throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody } @Override - public List getChildrenRight(Many1 parentLeft) - { + public Set getParentsRight() { throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody } @Override - public Set getParentsLeft() - { + public boolean removeLeft(Many1 many1) { throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody } @Override - public Set getParentsRight() - { + public boolean removeRight(Many2 many2) { throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody } @Override - public boolean removeLeft(Many1 many1) - { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody - } - - @Override - public boolean removeRight(Many2 many2) - { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody - } - - @Override - public void clear() - { + public void clear() { throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody } }; } - public static void main(String[] args) throws InterruptedException - { + public static void main(String[] args) throws InterruptedException { ManyToMany mm = ManyToManyFactory.createManyToMany(); //mm.add(1, 1);///will not compile, we have Many1, Many2 as String System.out.println("add(e1, p1, p2)returns: " + mm.add("e1", "p1", "p2")); System.out.println("add(e2, p2, p3)returns: " + mm.add("e2", "p2", "p3")); - System.out.println("getParentsLeft returns: " + mm.getParentsLeft()); - System.out.println("getParentsRight returns: " + mm.getParentsRight()); + //System.out.println("getParentsLeft returns: " + mm.getParentsLeft()); + //System.out.println("getParentsRight returns: " + mm.getParentsRight()); System.out.println("getChildrenLeft(p1) returns: " + mm.getChildrenLeft("p2")); System.out.println("getChildrenLeft(p2) returns: " + mm.getChildrenLeft("p3")); System.out.println("getChildrenRight(e1) returns: " + mm.getChildrenRight("e1")); diff --git a/Semester 4/Assignments/MapASDV_CalebFontenot/build.xml b/Semester 4/Assignments/MapASDV_CalebFontenot/build.xml new file mode 100644 index 0000000..237cd2e --- /dev/null +++ b/Semester 4/Assignments/MapASDV_CalebFontenot/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project MapASDV_CalebFontenot. + + + diff --git a/Semester 4/Assignments/MapASDV_CalebFontenot/manifest.mf b/Semester 4/Assignments/MapASDV_CalebFontenot/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Semester 4/Assignments/MapASDV_CalebFontenot/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/build-impl.xml b/Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/build-impl.xml new file mode 100644 index 0000000..2b58afc --- /dev/null +++ b/Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/build-impl.xml @@ -0,0 +1,1799 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set platform.home + Must set platform.bootcp + Must set platform.java + Must set platform.javac + + The J2SE Platform is not correctly set up. + Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. + Either open the project in the IDE and setup the Platform with the same name or add it manually. + For example like this: + ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) + or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + ${platform.java} -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/genfiles.properties b/Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/genfiles.properties new file mode 100644 index 0000000..ca12892 --- /dev/null +++ b/Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=25d86ec5 +build.xml.script.CRC32=638d3506 +build.xml.stylesheet.CRC32=f85dc8f2@1.108.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=25d86ec5 +nbproject/build-impl.xml.script.CRC32=57519cf4 +nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.108.0.48 diff --git a/Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/project.properties b/Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/project.properties new file mode 100644 index 0000000..4f04225 --- /dev/null +++ b/Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/project.properties @@ -0,0 +1,95 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/MapASDV_CalebFontenot.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/MapASDV_CalebFontenot +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=20 +javac.target=20 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=MapASDV_CalebFontenot +main.class=mapasdv_calebfontenot.MapASDV_CalebFontenot +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=Graal_JDK_20 +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/project.xml b/Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/project.xml new file mode 100644 index 0000000..4bff5e6 --- /dev/null +++ b/Semester 4/Assignments/MapASDV_CalebFontenot/nbproject/project.xml @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + MapASDV_CalebFontenot + + + + + + + + + + diff --git a/Semester 4/Assignments/MapASDV_CalebFontenot/src/mapasdv_calebfontenot/ListASDV.java b/Semester 4/Assignments/MapASDV_CalebFontenot/src/mapasdv_calebfontenot/ListASDV.java new file mode 100644 index 0000000..0aacf92 --- /dev/null +++ b/Semester 4/Assignments/MapASDV_CalebFontenot/src/mapasdv_calebfontenot/ListASDV.java @@ -0,0 +1,1694 @@ + +package mapasdv_calebfontenot; + + +import java.io.Serializable; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collection; +import java.util.Deque; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Queue; +import java.util.function.Consumer; + +public class ListASDV + implements Serializable, + Cloneable, + Iterable, + Collection, Deque, List, Queue +{ + + public Node head; + public Node tail; + BigInteger size; + + public class Node + { + + public E e; + public Node l; + public Node r; + } + public BigInteger sizeBigInteger() + { + return size; + } + /** + * Constructs an empty list. + */ + public ListASDV() + { + size = new BigInteger("0"); + } + + /** + * Constructs a list containing the elements of the specified collection, in + * the order they are returned by the collection's iterator. + * + * @param c - the collection whose elements are to be placed into this list + * @throws NullPointerException - if the specified collection is null + */ + public ListASDV(Collection c) + { + if (c == null) + { + throw new NullPointerException("Null parameter " + c); + } + this.addAll(c); + size.add(new BigInteger( Integer.toString(c.size()))); + } + + /** + * @return Iteraror with the implementation of: hasNext, next + * forEachRemaining + */ + @Override + public Iterator iterator() + { + Iterator it = new Iterator() + { + Node trailNext = head; + @Override public boolean hasNext() + { + if (trailNext == null) + { + trailNext = head; + return false; + } + return true; + } + @Override public E next() + { + Node temp = trailNext; + trailNext = trailNext.r; + return temp.e; + } + /** + * Performs the given action for each remaining element until all + * elements have been processed or the action throws an exception. + * + * @param action has method accept(T t) which performs this + * operation on the given argument. + */ + @Override public void forEachRemaining(Consumer action) + { + //Node temp = trailNext; + //while (temp != null){action.accept(temp.e);temp = temp.r;} + while (hasNext()) action.accept( next() ); + } + }; + return it; + } + + /** + * Inserts all of the elements in the specified collection into this list, + * starting at the specified position. Shifts the element currently at that + * position (if any) and any subsequent elements to the right (increases + * their indices). The new elements will appear in the list in the order + * that they are returned by the specified collection's iterator. + * + * @param index - index at which to insert the first element from the + * specified collection + * @param c - collection containing elements to be added to this list + * @return true if this list changed as a result of the call + * @throws IndexOutOfBoundsException - if the index is out of range (index + * LESS 0 || index GREATER size()) + * @throws NullPointerException - if the specified collection is null + */ + @Override + public boolean addAll(int index, Collection c) + { + if (index < 0 || index > size()) + { + throw new IndexOutOfBoundsException("IndexOutOfBoundsException, index: " + index); + } + if (c == null) + { + throw new NullPointerException("Null parameter " + c); + } + Node temp = tail; + for (E e : c) + { + add(index++, e); + } + size.add(new BigInteger( Integer.toString(c.size()))); + + return temp != tail; + } + + /** + * Returns the element at the specified position in this list. + * + * @param index - index of the element to return + * @return the element at the specified position in this list + * @throws IndexOutOfBoundsException - if the index is out of range (index + * LT 0 || index GE size()) + */ + @Override + public E get(int index) + { + if (index < 0 || index >= size()) + { + throw new IndexOutOfBoundsException("Out of bounds: " + Integer.toString(index)); + } + + Node temp = head; + for (int i = 0; i < index; ++i) + { + temp = temp.r; + } + return temp.e; + } + + /** + * Replaces the element at the specified position in this list with the + * specified element (optional operation). + * + * @param index - index of the element to replace + * @param element + * @return element - the element previously at the specified position + * @throws ClassCastException - if the class of the specified element + * prevents it from being added to this list + * @throws NullPointerException - if the specified element is null and this + * list does not permit null elements + * @throws IllegalArgumentException - if some property of the specified + * element prevents it from being added to this list + * @throws IndexOutOfBoundsException - if the index is out of range (index L + * 0 || index GE size()) + */ + @Override + public E set(int index, E element) + { + + if (index < 0 || index >= size()) + { + throw new IndexOutOfBoundsException("Out of bounds: " + Integer.toString(index)); + } + if (element == null) + { + throw new NullPointerException("Null parameter " + element); + } + + Node temp = head; + for (int i = 0; i < index; ++i) + { + temp = temp.r; + } + E e = temp.e; + temp.e = element; + return e; + } + + /** + * Inserts the specified element at the specified position in this list. + * Shifts the element currently at that position (if any) and any subsequent + * elements to the right (adds one to their indices). + * + * @param index at which the specified element is to be inserted + * @param element - element to be appended to this list + * @throws IndexOutOfBoundsException - if the index is out of range (index L + * 0 || index G size()) + */ + @Override + public void add(int index, E element) + { + if (index < 0 || index > size()) + { + throw new IndexOutOfBoundsException("Out of bounds: " + Integer.toString(index)); + } + if (element == null) + { + throw new NullPointerException("Null parameter " + element); + } + Node newNode = new Node(); + newNode.e = element; + if (head == null) + { + tail = head = newNode; + } + else + { + if (index == 0)//add in the front + { + newNode.r = head; + head.l = newNode; + head = newNode; + } + else if (index == size())//add in the end + { + newNode.l = tail; + tail.r = newNode; + tail = newNode; + } + else //add in the middle + { + Node temp = head; + for (int i = 0; i < index; ++i) + { + temp = temp.r; + } + + newNode.r = temp; + newNode.l = temp.l; + temp.l.r = newNode; + temp.l = newNode; + + } + } + size.add(new BigInteger( "1")); + + } + + /** + * Removes the element at the specified position in this list. Shifts any + * subsequent elements to the left (subtracts one from their indices). + * Returns the element that was removed from the list. + * + * @param index the index of the element to be removed + * @return the element previously at the specified position, null if empty + * list + * @throws IndexOutOfBoundsException - if the index is out of range (index + * LESS 0 or index GE size() + */ + @Override + public E remove(int index) + { + if (index < 0 || index >= size()) + { + throw new IndexOutOfBoundsException("Index Out of bounds exception : " + index); + } + if (size() == 0) + { + return null; + } + size.subtract(new BigInteger( "1")); + if (size() == 1 && index == 0)//special case just having 1 node + { + Node temp = head; + head = tail = null; + return temp.e; + } + else if (index == 0)//remove the first node + { + Node temp = head; + head = head.r; + head.l = null; + return temp.e; + } + else if (index == size() - 1)//remove last node + { + Node temp = tail; + tail = tail.l; + tail.r = null; + return temp.e; + } + else //remove in the middle + { + Node temp = head; + for (int i = 0; i < index; ++i) + { + temp = temp.r; + } + + temp.l.r = temp.r; + temp.r.l = temp.l; + return temp.e; + } + } + + /** + * Returns the index of the first occurrence of the specified element in + * this list, or -1 if this list does not contain the element. More + * formally, returns the lowest index i such that (o==null ? get(i)==null : + * o.equals(get(i))), or -1 if there is no such index. + * + * + * @param o - element to search for + * @return the index of the first occurrence of the specified element in + * this list, or -1 if this list does not contain the element + * @throws ClassCastException - if the type of the specified element is + * incompatible with this list (optional) + */ + @Override + public int indexOf(Object o) + { + Iterator it = iterator(); + int i = 0; + while (it.hasNext()) + { + E e = it.next(); + if (e.equals(o)) + { + return i; + } + i++; + } + return -1; + } + + /** + * Returns the index of the last occurrence of the specified element in this + * list, or -1 if this list does not contain the element. More formally, + * returns the highest index i such that (o==null ? get(i)==null : + * o.equals(get(i))), or -1 if there is no such index. + * + * + * + * @param o - element to search for + * @return the index of the last occurrence of the specified element in this + * list, or -1 if this list does not contain the element + * @throws:ClassCastException - if the type of the specified element is + * incompatible with this list (optional) + * + */ + @Override + public int lastIndexOf(Object o) + { + Iterator it = this.descendingIterator(); + int index = size() - 1; + while (it.hasNext()) + { + if (it.next().equals(o)) + { + return index; + } + --index; + } + return -1; + } + + /** + * Returns a list-iterator of the elements in this list (in proper + * sequence), starting at the specified position in the list. Obeys the + * general contract of List.listIterator(int). implements : hasNext, next,, + * previous, hasPrevious, nextIndex, previousIndex + * + * @param index - index of the first element to be returned from the + * list-iterator (by a call to next) + * @return a ListIterator of the elements in this list (in proper sequence), + * starting at the specified position in the list + * + * @throws IndexOutOfBoundsException - if the index is out of range (index L + * 0 || index G size()) + */ + @Override + public ListIterator listIterator(int index) + { + ListIterator it = new ListIterator() + { + Node trailNext = trailNextInitialize(); + Node trailPrevious = trailNext.l; + + int nextIndex = index; + int previousIndex = nextIndex - 1; + + Node trailNextInitialize() + { + if (index < 0 || index > size()) + { + throw new IndexOutOfBoundsException("ListIterator index out of bounds: " + index); + } + trailNext = head; + for (int i = 0; i < index; ++i) + { + trailNext = trailNext.r; + } + return trailNext; + } + + /** + * Returns true if this list iterator has more elements when + * traversing the list in the forward direction. (In other words, + * returns true if next() would return an element rather than + * throwing an exception.) + * + * @return returns true if next() would return an element; + */ + @Override + public boolean hasNext() + { + if (trailNext == null) + { + trailNext = head; + trailPrevious = trailNext.l; + nextIndex = 0; + previousIndex = -1; + return false; + } + return true; + } + + /** + * Returns the next element in the list and advances the cursor + * position. This method may be called repeatedly to iterate through + * the list, or intermixed with calls to previous() to go back and + * forth. (Note that alternating calls to next and previous will + * return the same element repeatedly.) Specified by: next in + * interface IteratorLE E> + * NoSuchElementException - if the iteration has no next element + * + * @return the next element in the list + * @throws NoSuchElementException if the iteration has no next element + */ + @Override + public E next() + { + if ( trailNext == null ) + throw new NoSuchElementException( "mo next element exists"); + + Node temp = trailNext; + trailPrevious = trailNext; + trailNext = trailNext.r;//advance the trailNext to the next node + previousIndex = nextIndex;//advance previous index to next + nextIndex++;// advance the next index + + return temp.e; + } + + @Override + public boolean hasPrevious() + { + + if (trailPrevious == null) + { + trailNext = head; + trailPrevious = trailNext.l; + nextIndex = 0; + previousIndex = -1; + return false; + } + return true; + } + + @Override + public E previous() + { + if ( trailPrevious == null ) + throw new NoSuchElementException( "no next element exists"); + + Node temp = trailPrevious; + trailNext = trailPrevious; + trailPrevious = trailPrevious.l; + nextIndex = previousIndex; + previousIndex--; + return temp.e; + } + + @Override + public int nextIndex() + { + return nextIndex; + } + + @Override + public int previousIndex() + { + return previousIndex; + } + + @Override + public void remove() + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void set(E e) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void add(E e) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + }; + return it; + } + + /** + * One line of code here. Call listIterator(0) + * + * @return ListIterator + */ + @Override + public ListIterator listIterator() + { + return listIterator(0); + } + + /** + * Returns a view of the portion of this list between the specified + * fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex + * are equal, the returned list is empty.) The returned list is backed by + * this list, so non-structural changes in the returned list are reflected + * in this list, and vice-versa. The returned list supports all of the + * optional list operations supported by this list. + * + * + * @param fromIndex - low endpoint (inclusive) of the subList + * @param toIndex - high endpoint (exclusive) of the subList + * @return a view of the specified range within this list + * @throws Throws: IndexOutOfBoundsException - for an illegal endpoint index + * value (fromIndex L 0 || toIndex G size || fromIndex > toIndex) + */ + @Override + public List subList(int fromIndex, int toIndex) + { + if (fromIndex > toIndex || fromIndex < 0 || toIndex > size()) + { + throw new IndexOutOfBoundsException("Index out of Bounds exception " + fromIndex + " " + toIndex); + } + + E[] a = (E[]) new Object[0]; + a = toArray(a); + a = Arrays.copyOfRange(a, fromIndex, toIndex); + return Arrays.asList(a); + } + + @Override + public int size() + { + Node temp = head; + int count = 0; + while (temp != null) + { + count++; + temp = temp.r; + } + return count; + } + + /** + * Tests is the list is empty + * + * @return true if the list is empty, false otherwise. + */ + @Override + public boolean isEmpty() + { + return head == null; + } + + /** + * + * Returns true if this list contains the specified element. More formally, + * returns true if and only if this list contains at least one element e + * such that (o==null ? e==null : o.equals(e)). + * + * @param o - element whose presence in this list is to be tested + * @return true if this list contains the specified element + * @throws ClassCastException - if the type of the specified element is + * incompatible with this list (optional) + */ + @Override + public boolean contains(Object o) + { + Iterator it = this.iterator(); + while (it.hasNext()) + { + if (it.next().equals(o)) + { + return true; + } + } + return false; + } + + /** + * Returns an array containing all of the elements in this list in proper + * sequence (from first to last element). + * + * The returned array will be "safe" in that no references to it are + * maintained by this list. (In other words, this method must allocate a new + * array even if this list is backed by an array). The caller is thus free + * to modify the returned array. + * + * @return an array containing all of the elements in this list in proper + * sequence + */ + @Override + public Object[] toArray() + { + Object[] ar = new Object[size()]; + Iterator it = iterator(); + int i = 0; + while (it.hasNext()) + { + ar[i++] = it.next(); + } + return ar; + } + + /** + * Returns an array containing all of the elements in this list in proper + * sequence (from first to last element); the runtime type of the returned + * array is that of the specified array. If the list fits in the specified + * array, it is returned therein. Otherwise, a new array is allocated with + * the runtime type of the specified array and the size of this list. If the + * list fits in the specified array with room to spare (i.e., the array has + * more elements than the list), the element in the array immediately + * following the end of the list is set to null. (This is useful in + * determining the length of the list only if the caller knows that the list + * does not contain any null elements.) + * + * Like the toArray() method, this method acts as bridge between array-based + * and collection-based APIs. Further, this method allows precise control + * over the runtime type of the output array, and may, under certain + * circumstances, be used to save allocation costs. + * + * Suppose x is a list known to contain only strings. The following code can + * be used to dump the list into a newly allocated array of String: String[] + * y = x.toArray(new String[0]); Note that toArray(new Object[0]) is + * identical in function to toArray(). + * + * Specified by: toArray in interface Collection Type Parameters: T - the + * runtime type of the array to contain the collection Parameters: a - the + * array into which the elements of this list are to be stored, if it is big + * enough; otherwise, a new array of the same runtime type is allocated for + * this purpose. Returns: an array containing the elements of this list + * Throws: ArrayStoreException - if the runtime type of the specified array + * is not a supertype of the runtime type of every element in this list + * NullPointerException - if the specified array is null + * + * @param - the runtime type of the array to contain the collection + * @param a - the array into which the elements of this list are to be + * stored, if it is big enough; otherwise, a new array of the same runtime + * type is allocated for this purpose. + * + * @return an array containing the elements of this list + * @throws ArrayStoreException - if the runtime type of the specified array + * is not a supertype of the runtime type of every element in this list + * @throws NullPointerException - if the specified array is null + */ + @Override + public T[] toArray(T[] a) + { + if (a == null) + { + throw new NullPointerException("Null pointer exception: parameter is null"); + } + + if (a.length >= this.size()) + { + Iterator it = iterator(); + int i = 0; + while (it.hasNext()) + { + T e = (T) it.next(); + a[i++] = e; + } + return a; + } + else + { + T[] ar = Arrays.copyOf(a, size()); + + Iterator it = iterator(); + int i = 0; + while (it.hasNext()) + { + T e = (T) it.next(); + ar[i++] = e; + } + return ar; + } + + } + + /** + * Appends the specified element to the end of this list. This method is + * equivalent to addLast(E). + * + * @param e element to be appended to this list + * @return true if this collection changed as a result of the call + */ + @Override + public boolean add(E e) + { + Node newNode = new Node(); + newNode.e = e; + if (head == null) + { + head = tail = newNode; + } + else + { + newNode.l = tail; + tail.r = newNode; + tail = newNode; + } + size.add(new BigInteger( "1")); + return true; + } + + /** + * Removes a single instance of the specified element from this collection, + * if it is present (optional operation). More formally, removes an element + * e such that (o==null ? e==null : o.equals(e)), if this collection + * contains one or more such elements. + * + * + * @param o - element to be removed from this collection, if present + * @return true if this collection changed as a result of the call. + * @throws ClassCastException - if the type of the specified element is + * incompatible with this collection (optional) + * @throws NullPointerException - if the specified element is null and this + * collection does not permit null elements (optional) + */ + @Override + public boolean remove(Object o) + { + if (o == null) + { + throw new NullPointerException("Null Pointer exception, cant pass null arguments"); + } + Iterator it = this.iterator(); + int pos = 0; + while (it.hasNext()) + { + if (it.next().equals(o)) + { + remove(pos); + return true; + } + pos++; + } + return false; + } + + /** + * Returns true if this collection contains all of the elements in the + * specified collection. + * + * @param c - collection to be checked for containment in this collection + * @return true if this collection contains all of the elements in the + * specified collection + * @throws ClassCastException - if the types of one or more elements in the + * specified collection are incompatible with this collection (optional) + * @throws NullPointerException - if the specified collection contains one + * or more null elements and this collection does not permit null elements + * (optional), or if the specified collection is null. + */ + @Override + public boolean containsAll(Collection c) + { + for (Object o : c) + { + if (contains(o) == false) + { + return false; + } + } + return true; + } + + /** + * Appends all of the elements in the specified collection to the end of + * this list, in the order that they are returned by the specified + * collection's iterator. The behavior of this operation is undefined if the + * specified collection is modified while the operation is in progress. + * (Note that this will occur if the specified collection is this list, and + * it's nonempty.) + * + * @param c - collection containing elements to be added to this list + * @return true if this list changed as a result of the call + * @throws NullPointerException - if the specified collection is null + */ + @Override + public boolean addAll(Collection c) + { + Node temp = tail; + for (E e : c) + { + add(e); + } + return temp != tail; + } + + /** + * Removes from this list all of its elements that are contained in the + * specified collection (optional operation). + * + * @param c - collection containing elements to be removed from this list + * @return true if this list changed as a result of the call + * @throws ClassCastException - if the class of an element of this list is + * incompatible with the specified collection (optional) + */ + @Override + public boolean removeAll(Collection c) + { + Node temp1 = tail; + Node temp2 = head; + for (Object o : c) + { + while (this.remove(o))//remove all same occurances + ; + } + + return temp1 != tail || temp2 != head; + } + + /** + * Retains only the elements in this list that are contained in the + * specified collection (optional operation). In other words, removes from + * this list all of its elements that are not contained in the specified + * collection. + * + * @param c - collection containing elements to be retained in this list + * @return true if this list changed as a result of the call + * @throws ClassCastException - if the class of an element of this list is + * incompatible with the specified collection (optional) + */ + @Override + public boolean retainAll(Collection c) + { + ListASDV cloner = (ListASDV) this.clone(); + cloner.removeAll(c);//cloner has elements to be deleted in the original list + Iterator it = cloner.iterator(); + while (it.hasNext()) + { + Object o = it.next(); + while (this.remove(o)); + } + return true; + } + + /** + * Clears the list of all elements. + */ + @Override + public void clear() + { + size = new BigInteger( "0"); + head = tail = null; + } + + /** + * Inserts the specified element at the beginning of this list. + * + * @param e - the element to add + */ + @Override + public void addFirst(E e) + { + this.add(0, e); + } + + /** + * Appends the specified element to the end of this list. This method is + * equivalent to add(E). + * + * @param e - the element to add + */ + @Override + public void addLast(E e) + { + this.add(size(), e); + } + + /** + * Inserts the specified element at the front of this deque unless it would + * violate capacity restrictions. When using a capacity-restricted deque, + * this method is generally preferable to the addFirst(E) method, which can + * fail to insert an element only by throwing an exception. + * + * Parameters: e - the element to add Returns: true if the element was added + * to this deque, else false Throws: ClassCastException - if the class of + * the specified element prevents it from being added to this deque + * NullPointerException - if the specified element is null and this deque + * does not permit null elements IllegalArgumentException - if some property + * of the specified element prevents it from being added to this deque + * + * @param e - the element to add + * @return true if the element was added to this deque, else false + * @throws ClassCastException if the class of the specified element prevents + * it from being added to this deque + * @throws IllegalArgumentException - if some property of the specified + * element prevents it from being added to this deque + */ + @Override + public boolean offerFirst(E e) + { + addFirst(e); + return true; + } + + /** + * Inserts the specified element at the end of this deque unless it would + * violate capacity restrictions. When using a capacity-restricted deque, + * this method is generally preferable to the addLast(E) method, which can + * fail to insert an element only by throwing an exception. + * + * Parameters: e - the element to add Returns: true if the element was added + * to this deque, else false Throws: ClassCastException - if the class of + * the specified element prevents it from being added to this deque + * NullPointerException - if the specified element is null and this deque + * does not permit null elements IllegalArgumentException - if some property + * of the specified element prevents it from being added to this deque + * + * @param e - the element to add + * @return true if the element was added to this deque, else false + * @throws ClassCastException - if the class of the specified element + * prevents it from being added to this deque + * @throws IllegalArgumentException - if some property of the specified + * element prevents it from being added to this deque * + */ + @Override + public boolean offerLast(E e) + { + addLast(e); + return true; + } + + /** + * E removeFirst() + * + * Retrieves and removes the first element of this deque. This method + * differs from pollFirst only in that it throws an exception if this deque + * is empty. + * + * @return the head of this deque + * @throws NoSuchElementException - if this deque is empty + */ + @Override + public E removeFirst() + { + if (this.isEmpty()) + { + throw new NoSuchElementException("list is empty"); + } + return this.remove(0); + } + + /** + * Retrieves and removes the last element of this deque. This method differs + * from pollLast only in that it throws an exception if this deque is empty. + * + * @return the tail of this deque + * @thows NoSuchElementException - if this deque is empty + */ + @Override + public E removeLast() + { + if (this.isEmpty()) + { + throw new NoSuchElementException("list is empty"); + } + return this.remove(size() - 1); + } + + /** + * Retrieves and removes the first element of this deque, or returns null if + * this deque is empty. + * + * @return the head of this deque, or null if this deque is empty + */ + @Override + public E pollFirst() + { + return isEmpty() ? null : this.remove(0); + } + + /** + * Retrieves and removes the last element of this deque, or returns null if + * this deque is empty. + * + * @return the tail of this deque, or null if this deque is empty + */ + @Override + public E pollLast() + { + return isEmpty() ? null : this.remove(size() - 1); + } + + /** + * Retrieves, but does not remove, the first element of this deque. This + * method differs from peekFirst only in that it throws an exception if this + * deque is empty. + * + * @return the head of this deque + * @throws NoSuchElementException - if this deque is empty + */ + @Override + public E getFirst() + { + if (isEmpty()) + { + throw new NoSuchElementException("The list is empty"); + } + + return head.e; + } + + /** + * Retrieves, but does not remove, the last element of this deque. This + * method differs from peekLast only in that it throws an exception if this + * deque is empty. + * + * @return the tail of this deque + * @throws Throws: NoSuchElementException - if this deque is empty + */ + @Override + public E getLast() + { + if (isEmpty()) + { + throw new NoSuchElementException("The list is empty"); + } + return tail.e; + } + + /** + * Retrieves, but does not remove, the first element of this deque, or + * returns null if this deque is empty. + * + * @return the head of this deque, or null if this deque is empty + * + */ + @Override + public E peekFirst() + { + return isEmpty() ? null : this.get(0); + } + + /** + * Retrieves, but does not remove, the last element of this deque, or + * returns null if this deque is empty. + * + * @return the tail of this deque, or null if this deque is empty + */ + @Override + public E peekLast() + { + return isEmpty() ? null : this.get(size() - 1); + } + + /** + * Removes the first occurrence of the specified element from this deque. If + * the deque does not contain the element, it is unchanged. More formally, + * removes the first element e such that (o==null ? e==null : o.equals(e)) + * (if such an element exists). Returns true if this deque contained the + * specified element (or equivalently, if this deque changed as a result of + * the call). + * + * @param o - element to be removed from this deque, if present + * @return true if an element was removed as a result of this call + * @throws ClassCastException - if the class of the specified element is + * incompatible with this deque + */ + @Override + public boolean removeFirstOccurrence(Object o) + { + return isEmpty() ? false : this.remove(o); + + } + + /** + * Removes the last occurrence of the specified element from this deque. If + * the deque does not contain the element, it is unchanged. More formally, + * removes the last element e such that (o==null ? e==null : o.equals(e)) + * (if such an element exists). Returns true if this deque contained the + * specified element (or equivalently, if this deque changed as a result of + * the call) + * + * @param o - element to be removed from this deque, if present + * @return true if an element was removed as a result of this call + * @throws ClassCastException - if the class of the specified element is + * incompatible with this deque (optional) + */ + @Override + public boolean removeLastOccurrence(Object o) + { + Node temp = tail; + int index = size() - 1; + while (temp != null) + { + if (this.get(index).equals(o)) + { + this.remove(index); + return true; + } + index--; + temp = temp.l; + } + return false; + } + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. When using a + * capacity-restricted queue, this method is generally preferable to add(E), + * which can fail to insert an element only by throwing an exception. + * + * + * @param e - the element to add + * @return true if the element was added to this queue, else false + * @throws: ClassCastException - if the class of the specified element + * prevents it from being added to this queue + */ + @Override + public boolean offer(E e) + { + return this.offerLast(e); + } + + /** + * Retrieves and removes the head of this queue. This method differs from + * poll only in that it throws an exception if this queue is empty. + * + * @return the head of this queue + * @throws NoSuchElementException - if this queue is empty + * + */ + @Override + public E remove() + { + if (isEmpty()) + { + throw new NoSuchElementException("The list is empty!"); + } + return this.remove(0); + } + + /** + * Retrieves and removes the head of this queue, or returns null if this + * queue is empty. + * + * @return the head of this queue, or null if this queue is empty + * + */ + @Override + public E poll() + { + if (isEmpty()) + { + throw new NoSuchElementException("The list is empty!"); + } + return this.remove(0); + } + + /** + * Retrieves, but does not remove, the head of this queue. This method + * differs from peek only in that it throws an exception if this queue is + * empty. + * + * @return the head of this queue + * @throws: NoSuchElementException - if this queue is empty + * + */ + @Override + public E element() + { + if (isEmpty()) + { + throw new NoSuchElementException("The list is empty!"); + } + return this.get(0); + } + + /** + * Retrieves, but does not remove, the head of this queue, or returns null + * if this queue is empty. + * + * @return the head of this queue, or null if this queue is empty + */ + @Override + public E peek() + { + return isEmpty() ? null : this.get(0); + } + + /** + * Pushes an element onto the stack represented by this list. In other + * words, inserts the element at the front of this list. + * + * This method is equivalent to addFirst(E). Specified by: push in interface + * Deque + * + * @param e - the element to push + */ + @Override + public void push(E e) + { + this.addFirst(e); + } + + /** + * Pops an element from the stack represented by this list. In other words, + * removes and returns the first element of this list. + * + * This method is equivalent to removeFirst(). Specified by: pop in + * interface Deque + * + * @return the element at the front of this list (which is the top of the + * stack represented by this list) + * @throws: NoSuchElementException - if this list is empty + */ + @Override + public E pop() + { + if (isEmpty()) + { + throw new NoSuchElementException("The list is empty!"); + } + return this.remove(0); + } + + /** + * Description copied from interface: Deque Returns an iterator over the + * elements in this deque in reverse sequential order. The elements will be + * returned in order from last (tail) to first (head). + * + * Specified by: descendingIterator in interface Deque + * + * @return an iterator over the elements in this deque in reverse sequence + */ + @Override + public Iterator descendingIterator() + { + + Iterator it = new Iterator() + { + Node trailPrevious = tail; + + @Override + public boolean hasNext() + { + if (trailPrevious == null) + { + trailPrevious = tail; + return false; + } + return true; + } + + @Override + public E next() + { + Node temp = trailPrevious; + trailPrevious = trailPrevious.l; + return temp.e; + } + }; + return it; + } + + /** + * Returns a deep clone of the list. + * + * @return the cloned list + */ + @Override + public Object clone() + { + ListASDV listCloned = new ListASDV(); + Iterator it = this.iterator(); + while (it.hasNext()) + { + + listCloned.add((E) it.next()); + } + return listCloned; + } + + @Override + public String toString() + { + + String s = "ListASDV{ "; + Iterator it = iterator(); + while (it.hasNext()) + { + s += it.next() + " "; + } + s += '}'; + return s; + } + + public static void main(String[] args) + { + class ASDV_ENTRY implements Map.Entry + { + T1 key; + T2 value; + public ASDV_ENTRY( T1 t1, T2 t2) + { + key = t1; + value = t2; + } + @Override + public T1 getKey() + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public T1 getValue() + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public T1 setValue(T1 value) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + + } + Map.Entry e1 = new ASDV_ENTRY("john", 20); + + ListASDV listTest = new ListASDV(); + listTest.add(e1); + + + ListASDV list = new ListASDV(); + list.add(100); + list.addFirst(50); + list.add(1, 75); + list.addLast(200); + List collection = Arrays.asList(new Integer[] + { + 300, 400 + }); + list.addAll(collection); + try + { + list.addAll(8, collection); + } + catch (IndexOutOfBoundsException e) + { + System.out.println(e.getMessage()); + } + + Iterator it = list.iterator(); + System.out.println("\ntest add methods ***************************************"); + while (it.hasNext()) + { + Object o = it.next(); + System.out.print(o + " "); + } + + System.out.println(""); + System.out.println("\nforEachRemaining(action) ***************************************"); + + Consumer action = new Consumer() + { + @Override + public void accept(Integer t) + { + System.out.print("*" + t + " "); + } + + }; + it = list.iterator(); + it.next(); + it.next(); + it.forEachRemaining(action); + System.out.println(""); + while (it.hasNext()) + { + Object o = it.next(); + System.out.print(o + " "); + } + System.out.println(""); + it.forEachRemaining(action); + + System.out.println(""); + System.out.println("indexOf ***************************************"); + System.out.println(list.indexOf(new A())); + System.out.println(list.indexOf(200)); + System.out.println(list.indexOf(800)); + + System.out.println("\nclone() ***************************************"); + ListASDV listCloned = (ListASDV) list.clone(); + list.clear(); + it = listCloned.iterator(); + while (it.hasNext()) + { + Object o = it.next(); + System.out.print(o + " "); + } + System.out.println("\nsize of original list after clear: " + list.size()); + list.addAll(0, listCloned); + System.out.println("\ntoString() ***************************************\n" + list); + + System.out.println("\ncontains ***************************************"); + System.out.println(list.contains(new A())); + System.out.println(list.contains(200)); + System.out.println(list.contains(800)); + + System.out.println("\ncontainsAll ***************************************"); + try + { + System.out.println(list.containsAll((Collection) new A())); + } + catch (ClassCastException e) + { + System.out.println(e.getMessage()); + } + System.out.println(list.containsAll(listCloned)); + System.out.println(list.containsAll(Arrays.asList(new Integer[] + { + 100, 300 + }))); + System.out.println(list.containsAll(Arrays.asList(new Integer[] + { + 10, 300 + }))); + + System.out.println("\ndiscendingIterator ***************************************"); + Iterator descIt = list.descendingIterator(); + while (descIt.hasNext()) + { + Object o = descIt.next(); + System.out.print(o + " "); + } + + System.out.println("\nelement ***************************************"); + System.out.println(list.element()); + System.out.println(list.element()); + listCloned.clear(); + try + { + listCloned.element(); + } + catch (NoSuchElementException e) + { + System.out.println(e.getMessage()); + } + + System.out.println("\nget(int) ***************************************"); + System.out.println(list.get(0)); + System.out.println(list.get(list.size() - 1)); + try + { + list.get(list.size()); + } + catch (IndexOutOfBoundsException e) + { + System.out.println(e.getMessage()); + } + + System.out.println("\ngetFirst() ***************************************"); + System.out.println(list.getFirst()); + System.out.println(list.getFirst()); + try + { + listCloned.getFirst(); + } + catch (NoSuchElementException e) + { + System.out.println(e.getMessage()); + } + + System.out.println("\n getLAst()***************************************"); + System.out.println(list.getLast()); + System.out.println(list.getLast()); + + try + { + listCloned.getLast(); + } + catch (NoSuchElementException e) + { + System.out.println(e.getMessage()); + } + + System.out.println("\n isEmpty()***************************************"); + System.out.println(list.isEmpty()); + System.out.println(listCloned.isEmpty()); + + System.out.println("\n lastIndexOf***************************************"); + list.add(1, -888); + list.add(4, -888); + System.out.println(list); + System.out.println(list.lastIndexOf(-888)); + System.out.println(list.lastIndexOf(12)); + System.out.println(list.lastIndexOf(new A())); + + System.out.println("\nlistIterator( index=3) using next***************************************"); + System.out.println(list); + ListIterator itList = list.listIterator(3); + + while (itList.hasNext()) + { + Object o = itList.next(); + System.out.print("next Index " + itList.nextIndex()); + System.out.print(" previous Index " + itList.previousIndex()); + System.out.println(" node " + o + " "); + } + + System.out.println("\nlistIterator( index=3) using previous ***************************************"); + System.out.println(list); + itList = list.listIterator(3); + + while (itList.hasPrevious()) + { + Object o = itList.previous(); + System.out.print("next Index " + itList.nextIndex()); + System.out.print(" previous Index " + itList.previousIndex()); + System.out.println(" node " + o + " "); + } + + System.out.println("\nlistIterator with next ***************************************"); + System.out.println(list); + itList = list.listIterator(); + + while (itList.hasNext()) + { + Object o = itList.next(); + System.out.print("next Index " + itList.nextIndex()); + System.out.print(" previous Index " + itList.previousIndex()); + System.out.println(" node " + o + " "); + } + + System.out.println("\noffer methods ***************************************"); + list.offer(500); + list.offerLast(600); + list.offerFirst(33); + System.out.println(list); + + System.out.println("\npeek poll methods ***************************************"); + System.out.println(list.peek()); + System.out.println(list.peekFirst()); + System.out.println(list.peekLast()); + System.out.println(listCloned.peekLast()); + System.out.println(list.poll()); + System.out.println(list.pollFirst()); + System.out.println(list.pollLast()); + System.out.println(listCloned.pollFirst()); + + System.out.println("\npush pop methods ***************************************"); + System.out.println(list); + Integer o = list.pop(); + list.push(o); + System.out.println(list); + try + { + listCloned.pop(); + } + catch (NoSuchElementException e) + { + System.out.println(e.getMessage()); + } + + System.out.println("\nremove methods ***************************************"); + System.out.println(list); + System.out.println(list.removeLastOccurrence(-888)); + System.out.println(list); + System.out.println(list.remove()); + System.out.println(list.removeFirst()); + System.out.println(list); + System.out.println(list.remove((Integer) 300)); + try + { + list.remove(null); + } + catch (NullPointerException e) + { + System.out.println(e.getMessage()); + } + try + { + list.remove(200); + } + catch (IndexOutOfBoundsException e) + { + System.out.println(e.getMessage()); + } + System.out.println(list); + + System.out.println("\nremoveAll( Collection c) ***************************************"); + list.add(0, -888); + list.add(2, -888); + list.add(-888); + listCloned = (ListASDV) list.clone(); + System.out.println(list); + List col = Arrays.asList(new Integer[] + { + -888, 200 + }); + list.removeAll(col); + System.out.println(list); + + System.out.println("\nretailAll( Collection c) ***************************************"); + list = (ListASDV) listCloned.clone(); + list.retainAll(col); + System.out.println(list); + + System.out.println("\nset ***************************************"); + list.set(0, 100); + System.out.println(list); + + System.out.println("\nsubList ***************************************"); + List subList = list.subList(1, 3); + System.out.println(subList); + try + { + list.subList(1, 5); + } + catch (IndexOutOfBoundsException e) + { + System.out.println(e.getMessage()); + } + + System.out.println("\ntoArray ***************************************"); + System.out.println(list); + System.out.println(Arrays.asList(list.toArray())); + + Integer[] ar = new Integer[list.size()]; + System.out.println("\ntoArray(T[] ) ***************************************"); + System.out.println(list); + System.out.println(Arrays.asList(list.toArray(ar))); + + ar = new Integer[1]; + System.out.println(Arrays.asList(list.toArray(ar))); + + ar = new Integer[list.size() + list.size()]; + System.out.println(Arrays.asList(list.toArray(ar))); + + ar = null; + try + { + list.toArray(ar); + } + catch (NullPointerException e) + { + System.out.println(e.getMessage()); + } + + } + +} + +class A +{ +} + diff --git a/Semester 4/Assignments/MapASDV_CalebFontenot/src/mapasdv_calebfontenot/MapASDV.java b/Semester 4/Assignments/MapASDV_CalebFontenot/src/mapasdv_calebfontenot/MapASDV.java new file mode 100644 index 0000000..137c60e --- /dev/null +++ b/Semester 4/Assignments/MapASDV_CalebFontenot/src/mapasdv_calebfontenot/MapASDV.java @@ -0,0 +1,796 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package mapasdv_calebfontenot; + +/** + * + * @author caleb + */ + +//import ListASDV; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.function.BiConsumer;//needed in putAll + +public class MapASDV implements Map, Cloneable +{ + + private int capacity = 4; + private double loadFactor = 0.75; + private ArrayList>> map = new ArrayList<>(); + + private Set sharedKeySet = new SharedSet(); + private Set> sharedEntrySet = new SharedSet>(); + private Collection sharedValuesCollection = new SharedCollection(); + + private class SharedCollection extends ArrayList + { + + public boolean addValue(V v) + { + return this.add(v); + } + + @Override + public boolean remove(Object o) + { + + //> The parameter is key not entry if we are here + //>>remove value) and key) from the map + return MapASDV.this.removeFirstValue(o); + + //>>remove key from shared values set + //return super.remove(o); + } + + /** + * Removes one value from the collection. This method is meant to be + * called from out class. The overridden remove(Object o) of this inner + * class, calls the remove of the outer class(MapASDV), and the remove + * of the outer class, calls remove(V v, boolean callFromOuterClass) + * instead of remove(Object o) to avoid Stack Overflow when remover of + * inner calls remove of outer and vice versa. + * + * @param o - the key + * @param callFromOuterClass - dummy variable. + * @return true if the key was removed from the Set + */ + public boolean remove(V v, boolean callFromOuterClass) + { + //remove key from shared keys set + boolean b = super.remove(v); + return b; + + } + + @Override + public Object clone() + { + return super.clone(); + } + + @Override + public void clear() + { + super.clear(); + } + } + + private class SharedSet extends HashSet + { + + @Override + public boolean add(E e) + { + throw new UnsupportedOperationException("Not supported...."); + } + + @Override + public boolean removeAll(Collection c) + { + throw new UnsupportedOperationException("Not supported...."); + } + + /** + * Adds an EntryASDV to the set. It is private and cannot be used by the + * user of the Set. It is used from the MapASDV to add EntriesASDV to + * the SharedSet. Without this method we wouldn't be able to create a + * Set of keys or a Set of entries to give to the user via methods + * keySet() and entrySet() of this Map + * + * @param e EntryASDV + * @return true if the entry was added false otherwise + */ + private boolean addEntry(E e) + { + return super.add(e); + } + + @Override + public boolean remove(Object o) + { + + //>if parameter oo is EntryASDV call auxiliary method removeEntry + if (o instanceof EntryASDV) + { + return removeEntry((EntryASDV) o); + } + + //> The parameter is key not entry if we are here + //>>remove key from the map + MapASDV.this.remove(o); + //>>remove key from shared keys set + return super.remove(o); + } + + /** + * Removes the entry for the shared set + * + * @param entry the entry to be removed + * @return true if the entry was removed, false otherwise + */ + private boolean removeEntry(EntryASDV entry) + { + + MapASDV.this.remove(entry.getKey()); + return super.remove(entry); + } + + /** + * Removes the key from the set. This method is meant to be called from + * out class. The overridden remove(Object o) of this inner class calls + * the remove of the out class, and the remove of the outer class calls + * remove(K o, boolean callFromOuterClass) instead of remove(Object o) + * to avoid Stack Overflow when remover of inner calls remove of outer + * and vice versa. + * + * @param o - the key + * @param callFromOuterClass - dummy variable. + * @return true if the key was removed from the Set + */ + public boolean remove(E o, boolean callFromOuterClass) + { + + //remove key from shared keys set + return super.remove(o); + } + + @Override + public Object clone() + { + return super.clone(); + } + + @Override + public void clear() + { + super.clear(); + } + + } + + public MapASDV() + { + for (int i = 0; i < capacity; ++i) + { + map.add(new ListASDV>()); + } + } + + /** + * Double the size of the Map and rehashes the entries of the Map + */ + private void doubleTheSizeOfTheMapAndRehash() + { + capacity *= 2; + //>create a new arrayList of ListsASDV + ArrayList>> newMap = new ArrayList>>(); + + //>Add at every enetry of the arrayList a new ASDVList + for (int i = 0; i < capacity; ++i) + { + newMap.add(new ListASDV>()); + } + + //>for the size of the OLD arrayList + for (int i = 0; i < map.size(); ++i)//array list + { + //>> get The ASDVlist at i + ListASDV> list = map.get(i); + + //>>for the size() of the ASDVlist + for (int j = 0; j < list.size(); ++j) + { + ///>>>hash and put in the the new array + int index = hash( list.get(j).getKey().hashCode() ); + newMap.get(index).add(list.get(j)); + + } + } + map = newMap; + } + + class EntryASDV implements Entry, Comparable + { + + K key; + V value; + + public EntryASDV(K key, V value) + { + this.key = key; + this.value = value; + } + + @Override + public K getKey() + { + return key; + } + + @Override + public V getValue() + { + return value; + } + + @Override + public V setValue(V value) + { + V oldValue = this.value; + this.value = value; + return oldValue; + } + + @Override + public String toString() + { + return "EntryASDV{" + "key=" + key + ", value=" + value + '}'; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + final EntryASDV other = (EntryASDV) obj; + if (!Objects.equals(this.key, other.key)) + { + return false; + } + return true; + } + + /** + * + * @param o + * @return throws IllegalArgumentException if parameter class is not K + */ + @Override + public int compareTo(K o) + { + if (getClass() != o.getClass()) + { + throw new IllegalArgumentException("ellegal parameter " + o); + } + return ((Comparable) key).compareTo(o); + } + + } + + @Override + public int size() + { + return this.keySet().size(); + } + + @Override + public boolean isEmpty() + { + throw new UnsupportedOperationException("Not supported...."); + + } + + @Override + public boolean containsKey(Object key) + { + for (int i = 0; i < map.size(); ++i) { + System.out.println(map.get(i)); + } + throw new UnsupportedOperationException("Not supported yet...."); + + } + + /** + * Return an entry of the map + * + * @param key the key of the entry to be returned + * @return the entry, or null if the key is not in the map + */ + private EntryASDV getEntryForKey(Object key) + { + for (ListASDV> list : map) + { + Iterator> it = list.iterator(); + while (it.hasNext()) + { + EntryASDV entry = it.next(); + if (key.equals(entry.getKey())) + { + return entry; + } + } + } + return null; + } + + /** + * Returns the index of the given key + * + * @param key a key of the map + * @return the index of a key in the map or -1, if the key is not in the map + */ + private int getIndexForKey(Object key) + { + for (int i = 0; i < map.size(); ++i) + { + Iterator> it = map.get(i).iterator(); + while (it.hasNext()) + { + EntryASDV entry = it.next(); + if (key.equals(entry.getKey())) + { + return i; + } + } + } + return -1; + } + + /** + * Returns true if this map maps one or more keys to the specified value. + * More formally, returns true if and only if this map contains at least one + * mapping to a value v such that (value==null ? v==null : value.equals(v)). + * This operation will probably require time linear in the map size for most + * implementations of the Map interface. + * + * Parameters: value - value whose presence in this map is to be tested + * Returns: true if this map maps one or more keys to the specified value + * Throws: ClassCastException - if the value is of an inappropriate type for + * this map (optional) NullPointerException - if the specified value is null + * and this map does not permit null values (optional) + * + * @param value - value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified value + * @throws NullPointerException - if the specified value is null and this + * map does not permit null values (optional) + */ + @Override + public boolean containsValue(Object value) + { + throw new UnsupportedOperationException("Not supported yet...."); + + } + + /** + * Returns the value to which the specified key is mapped, or null if this + * map contains no mapping for the key. + * + * More formally, if this map contains a mapping from a key k to a value v + * such that (key==null ? k==null : key.equals(k)), then this method returns + * v; otherwise it returns null. (There can be at most one such mapping.) + * + * If this map permits null values, then a return value of null does not + * necessarily indicate that the map contains no mapping for the key; it's + * also possible that the map explicitly maps the key to null. The + * containsKey operation may be used to distinguish these two cases. + * + * @param key - the key whose associated value is to be returned + * @return the value to which the specified key is mapped, or null if this + * map contains no mapping for the key + * @throws NullPointerException - if the specified key is null and this map + * does not permit null keys (optional) + */ + @Override + public V get(Object key) + { + throw new UnsupportedOperationException("Not supported yet...."); + + } + + /** + * Associates the specified value with the specified key in this map + * (optional operation). If the map previously contained a mapping for the + * key, the old value is replaced by the specified value. (A map m is said + * to contain a mapping for a key k if and only if m.containsKey(k) would + * return true.) + * + * @param key - key with which the specified value is to be associated + * @param value - value to be associated with the specified key + * @return the previous value associated with key, or null if there was no + * mapping for key. (A null return can also indicate that the map previously + * associated null with key, if the implementation supports null values.) + * @throws NullPointerException - if specified key or value is null and this + * map does not permit null keys + */ + @Override + public V put(K key, V value) + { + + if (key == null || value == null) + { + throw new NullPointerException("parm(s) null"); + } + + //>if contains the key, replace the key's value + EntryASDV entry = getEntryForKey(key); + if (entry != null) + { + V oldValue = entry.value; + entry.value = value; + + return oldValue; + } + ///>>hash and put in the array + int code = this.hash(key.hashCode()); + int index = hash(code); + + ListASDV> list = map.get(index); + EntryASDV e = new EntryASDV(key, value); + list.add(e); + + //>>add the key to the shared keys-set + ((SharedSet) this.sharedKeySet).addEntry(key); + ((SharedSet>) this.sharedEntrySet).addEntry(e); + + //>>get the value of this entry + V v = list.get(list.size() - 1).getValue(); + + //>> add value to the value collection + ((SharedCollection) this.sharedValuesCollection).addValue(v); + + //>> if reach 75% capacity double the size + if ((double) this.size() / capacity >= 0.75) + { + this.doubleTheSizeOfTheMapAndRehash(); + } + + //>>return the value of Entry just added + return v; + } + + int hash(int keyHashCode) + { + int h = hashHash(keyHashCode); + return Math.abs(h % capacity - 1); + } + + /** + * Removes the first entry with the given values. + * + * @param value - the value to be removed + * @return true if removed, false otherwise + * @throws NullPointerException if the value is null + */ + private boolean removeFirstValue(Object value) + { + throw new UnsupportedOperationException("Not supported yet...."); + + } + + /** + * Ensure hash code is evenly distributed + * + * @param h - hash code + * @return evenly distributed hash code + */ + private static int hashHash(int h) + { + h ^= (h >>> 20) ^ (h >>> 12); + return h ^ (h >>> 7) ^ (h >>> 4); + } + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k to + * value v such that (key==null ? k==null : key.equals(k)), that mapping is + * removed. (The map can contain at most one such mapping.) + * + * @param key - key whose mapping is to be removed from the map + * @return the previous value associated with key, or null if there was no + * mapping for key. + * @throws NullPointerException - if the specified key is null and this map + * does not permit null keys + */ + @Override + public V remove(Object key) + { + throw new UnsupportedOperationException("Not supported yet...."); + + } + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * put(k, v) on this map once for each mapping from key k to value v in the + * specified map. The behavior of this operation is undefined if the + * specified map is modified while the operation is in progress. + * + * @param m - mappings to be stored in this map + * @throws NullPointerException - if the specified map is null, or if this + * map does not permit null keys or values, and the specified map contains + * null keys + */ + @Override + public void putAll(Map m) + { + if (m == null) + { + throw new NullPointerException("null parameter"); + } + + BiConsumer consumeEachEntry = new BiConsumer() + { + MapASDV mapForConsumer = MapASDV.this; + + @Override + public void accept(K k, V v) + { + mapForConsumer.put(k, v); + } + }; + + m.forEach(consumeEachEntry); + } + + + /** + * Removes all of the mappings from this map (optional operation). The map + * will be empty after this call returns. Any shared sets are also cleared. + */ + @Override + public void clear() + { + throw new UnsupportedOperationException("Not supported yet...."); + + } + + /** + * Returns a Set view of the keys contained in this map. The set is backed + * by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. + * It does not support the add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + @Override + public Set keySet() + { + + return this.sharedKeySet; + } + + /** + * Returns a Collection view of the values contained in this map. The + * collection is backed by the map, so changes to the map are reflected in + * the collection, and vice-versa. If the map is modified while an iteration + * over the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding + * mapping from the map, via the Iterator.remove, Collection.remove, + * removeAll, retainAll and clear operations. It does not support the add or + * addAll operations. + * + * @return + */ + @Override + public Collection values() + { + return sharedValuesCollection; + } + + /** + * Returns a Set view of the mappings contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation, or through + * the setValue operation on a map entry returned by the iterator) the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, retainAll and clear operations. + * It does not support the add or addAll operations. + * + * + * @return a set view of the mappings contained in this map + */ + @Override + public Set> entrySet() + { + return this.sharedEntrySet; + } + + @Override + public String toString() + { + String s = "[ "; + for (int i = 0; i < capacity; ++i) + { + s += map.get(i).toString() + "\n"; + } + s += " ]"; + + return s; + } + + /** + * Created a deep copy of the MapASDV + * + * @return the deep copy of the map + */ + @Override + public Object clone() + { + /* + MapASDV clonedMap = new MapASDV(); + + //clonedMap.putAll(this); + + for (ListASDV< EntryASDV> list : this.map) + { + ListASDV< EntryASDV> l = (ListASDV< EntryASDV>) list.clone(); + clonedMap.map.add(l); + } + return clonedMap; + */ + + MapASDV clonedMap = new MapASDV(); + clonedMap.putAll(this); + return clonedMap; + } + + public static void main(String[] args) + { + + MapASDV map = new MapASDV(); + System.out.println("---------------------------testing put(K, V)"); + map.put("ann", 20); + map.put("coco", 25); + System.out.println(map); + MapASDV clonedMap = ( MapASDV) map.clone(); + + + System.out.println("\n\n---------------------------testing double-the-size-and-rehash by reaching 0.75 load factor with another put(K, V)"); + map.put("Jonathan", 30); + System.out.println(map); + map.put("Jonhathan", 45); + System.out.println(map); + map.put("Alexander", 33); + System.out.println(map); + + System.out.println("\n\n---------------------------testing putAll(Map)"); + Map anotherJavaMap = new HashMap(); + anotherJavaMap.put("lion king", 45); + anotherJavaMap.put("HYENA", 6); + map.putAll(anotherJavaMap); + System.out.println(map); + + + System.out.println("\n\n---------------------------testing containsKey"); + System.out.println(map.containsKey("Alexander")); + System.out.println(map.containsKey("alexander")); + + System.out.println("\n\n---------------------------testing containsValue"); + System.out.println(map.containsValue(33)); + System.out.println(map.containsValue(34)); + + System.out.println("\n\n---------------------------testing getEntryForKey"); + Entry e = map.getEntryForKey("Alexander"); + System.out.println( map.getEntryForKey("Alexander")); + System.out.println( map.getEntryForKey("Alex")); + + System.out.println("\n\n---------------------------testing get"); + System.out.println(map.get( "Alexander") ); + System.out.println(map.get( "Alex") ); + try{ map.get( null);}catch (NullPointerException ex ){System.out.println(ex.getMessage());} + + System.out.println("\n\n---------------------------testing getIndexForKey"); + System.out.println(map.getIndexForKey("Alexander")); + System.out.println(map.getIndexForKey("Alex")); + + System.out.println("\n\n---------------------------testing isEmpty"); + System.out.println( map.isEmpty()); + + + System.out.println("\n\n---------------------------testing size"); + System.out.println( map.size()); + System.out.println( map); + + System.out.println("\n\n---------------------------testing entrySet()"); + Set> entries = map.entrySet(); + System.out.println( entries); + + System.out.println("\n\n---------------------------testing keySet()"); + Set keys = map.keySet(); + System.out.println( keys ); + + System.out.println("\n\n---------------------------testing values()"); + Collection values = map.values(); + System.out.println( values); + + System.out.println("\n\n---------------------------testing remove( K) coco 25"); + map.remove("coco"); + System.out.println(map); + System.out.println(entries); + System.out.println(keys); + System.out.println(values); + + System.out.println("\n\n---------------------------testing Entry-Collection remove "); + entries.remove( e); + System.out.println(map); + System.out.println(entries); + System.out.println(keys); + System.out.println(values); + + + System.out.println("\n\n---------------------------testing Set Keys remove "); + keys.remove( "ann"); + System.out.println(map); + System.out.println(entries); + System.out.println(keys); + System.out.println(values); + + + System.out.println("\n\n---------------------------testing Set Values remove "); + values.remove( 45); + System.out.println(map); + System.out.println(entries); + System.out.println(keys); + System.out.println(values); + + System.out.println("\n\n---------------------------testing clear "); + map.clear(); + System.out.println(map); + System.out.println(entries); + System.out.println(keys); + + System.out.println("\n\n---------------------------testing add of sets and collections "); + try{ keys.add( "a");}catch (Exception ex ){System.out.println(ex.getMessage());} + try{ values.add( 33);}catch (Exception ex ){System.out.println(ex.getMessage());} + try{ entries.add( e);}catch (Exception ex ){System.out.println(ex.getMessage());} + + + + System.out.println("\n\n---------------------------testing clone"); + System.out.println( clonedMap); + + System.out.println("---------------------------testing put(K, V) AGAIN"); + map.put("Nicholas", 100); + map.put("a", 200); + map.put("b", -20); + System.out.println( map); + } + +} + diff --git a/Semester 4/ZIPs/MP1_ManyToMany_CalebFontenot.zip b/Semester 4/ZIPs/MP1_ManyToMany_CalebFontenot.zip new file mode 100644 index 0000000000000000000000000000000000000000..81f5087c25dc90f3494cb7fd56c6f8951a87f421 GIT binary patch literal 7357 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