ArrayList completedmess is approaching

master
Caleb Fontenot 2023-09-29 13:33:32 +07:00
parent b372b1d559
commit 1e9d90d12a
4 changed files with 162 additions and 80 deletions

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.hint.jdkPlatform>JDK_20</netbeans.hint.jdkPlatform>
</properties>
</project-shared-configuration>

@ -7,8 +7,8 @@
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
<exec.mainClass>com.calebfontenot.mp4_generics_calebfontenot.MP4_Generics_CalebFontenot</exec.mainClass>
</properties>
</project>

@ -29,7 +29,8 @@ public class ArrayListASDV<E>
* Constructs an empty list with an initial capacity of three.
*
*/
public ArrayListASDV() {
public ArrayListASDV()
{
list = (E[]) new Object[3];
index = 0;
}
@ -40,7 +41,8 @@ public class ArrayListASDV<E>
* @param initialCapacity - the initial capacity of the list
* @throws IllegalArgumentException - if the specified initial capacity is negative
*/
public ArrayListASDV(int initialCapacity) {
public ArrayListASDV(int initialCapacity)
{
if (initialCapacity < 0) {
throw new IllegalArgumentException("initialCapacity id negative: " + initialCapacity);
}
@ -57,7 +59,8 @@ public class ArrayListASDV<E>
*
*
*/
public ArrayListASDV(Collection<? extends E> c) {
public ArrayListASDV(Collection<? extends E> c)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@ -72,7 +75,8 @@ public class ArrayListASDV<E>
* @throws IllegalArgumentException - if some property of the element prevents it from being added to this collection
*/
@Override
public boolean add(E e) {
public boolean add(E e)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
@ -84,12 +88,14 @@ public class ArrayListASDV<E>
* @return the number of elements in this list.
*/
@Override
public int size() {
public int size()
{
return index;
}
@Override
public String toString() {
public String toString()
{
String s = "ArrayListASDV[";
for (int i = 0; i < index; ++i) {
@ -107,7 +113,8 @@ public class ArrayListASDV<E>
*
*/
@Override
public boolean isEmpty() {
public boolean isEmpty()
{
return this.index == 0;
}
@ -120,7 +127,8 @@ public class ArrayListASDV<E>
*
*/
@Override
public boolean contains(Object o) {
public boolean contains(Object o)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
@ -132,7 +140,8 @@ public class ArrayListASDV<E>
* @return an array containing all of the elements in this list in proper sequence
*/
@Override
public Object[] toArray() {
public Object[] toArray()
{
Object[] returnArray = new Object[index];
for (int i = 0; i < index; ++i) {
Object objCopy = list[i];
@ -149,7 +158,8 @@ public class ArrayListASDV<E>
*/
@Override
public boolean remove(Object o
) {
)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
@ -159,7 +169,8 @@ public class ArrayListASDV<E>
* Removes all of the elements from this list. The list will be empty after this call returns. Note: Traverse the array and set all of its elements to null. Set its index to zero.
*/
@Override
public void clear() {
public void clear()
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@ -173,7 +184,8 @@ public class ArrayListASDV<E>
*/
@Override
public E get(int index
) {
)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@ -188,7 +200,8 @@ public class ArrayListASDV<E>
*/
@Override
public E set(int index, E element
) {
)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@ -202,7 +215,8 @@ public class ArrayListASDV<E>
* @throws IndexOutOfBoundsException - if the index is out of range (index GE 0 || index GE size())
*/
@Override
public void add(int index, E element) {
public void add(int index, E element)
{
if (element == null) {
throw new NullPointerException("cant add null");
}
@ -231,7 +245,8 @@ public class ArrayListASDV<E>
* @throws IndexOutOfBoundsException - if the index is out of range (index GE 0 || index GE size())
*/
@Override
public E remove(int index) {
public E remove(int index)
{
E r = this.list[index];
this.list[index] = null;
if (index == 0) {
@ -256,7 +271,8 @@ public class ArrayListASDV<E>
*/
@Override
public int indexOf(Object o
) {
)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@ -268,7 +284,8 @@ public class ArrayListASDV<E>
* @return the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element
*/
@Override
public int lastIndexOf(Object o) {
public int lastIndexOf(Object o)
{
ListIterator<E> iterator = listIterator(size());
while (iterator.hasPrevious()) {
int indexOf = iterator.previousIndex();
@ -293,7 +310,8 @@ public class ArrayListASDV<E>
*/
@Override
public List<E> subList(int fromIndex, int toIndex
) {
)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@ -307,7 +325,8 @@ public class ArrayListASDV<E>
* @throws NullPointerException - if the specified array is null
*/
@Override
public <T> T[] toArray(T[] a) {
public <T> T[] toArray(T[] a)
{
Class<?> clazz = a.getClass();
//>length of a is too small
if (a.length < index) // Make a new array of a's runtime type
@ -331,9 +350,10 @@ public class ArrayListASDV<E>
}
@Override
public Iterator<E> iterator() {
return new IteratorASDV<>(this);
public Iterator<E> iterator()
{
return new IteratorASDV<E>().iterator();
//return new Iterator < E >(this);
}
/**
@ -343,17 +363,19 @@ public class ArrayListASDV<E>
* @return a list iterator over the elements in this list (in proper sequence
*/
@Override
public ListIterator<E> listIterator() {
public ListIterator<E> listIterator()
{
return listIterator(0);
}
@Override
public ListIterator<E> listIterator(int index) {
public ListIterator<E> listIterator(int index)
{
ListIterator<E> it = new ListIterator<E>() {
int current = 0;
E[] list = (E[]) new Object[3];
int index = 0;
/**
* Returns true if this list iterator has more elements when traversing the list in the forward direction. (In other words, returns true if ListIterator.next would return an element rather than throwing an exception.)
@ -361,8 +383,11 @@ public class ArrayListASDV<E>
* @return true if the list iterator has more elements when traversing the list in the forward direction
*/
@Override
public boolean hasNext() {
return next() != null;
public boolean hasNext()
{
if (this.index == this.list.length) {
}
}
/**
@ -372,21 +397,24 @@ public class ArrayListASDV<E>
* @throws NoSuchElementException - if the iteration has no next element
*/
@Override
public E next() throws NoSuchElementException {
if (current < index) {
public E next() throws NoSuchElementException
{
if (index > this.list.length) {
throw new NoSuchElementException();
}
return list[current++];
return this.list[index++];
}
@Override
public boolean hasPrevious() {
return previous() != null;
public boolean hasPrevious()
{
return index > 0;
}
@Override
public E previous() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public E previous()
{
return this.list[--index];
}
@ -396,7 +424,8 @@ public class ArrayListASDV<E>
* @return the index of the element that would be returned by a subsequent call to next, or list size if the list iterator is at the end of the list
*/
@Override
public int nextIndex() {
public int nextIndex()
{
return index + 1 == size() ? size() : index + 1;
}
@ -406,7 +435,8 @@ public class ArrayListASDV<E>
* @return the index of the element that would be returned by a subsequent call to previous, or -1 if the list iterator is at the beginning of the list
*/
@Override
public int previousIndex() {
public int previousIndex()
{
return index - 1;
}
@ -417,7 +447,8 @@ public class ArrayListASDV<E>
* @throws NullPointerException - if the specified action is null
*/
@Override
public void forEachRemaining(Consumer<? super E> action) {
public void forEachRemaining(Consumer<? super E> action)
{
while (hasNext()) {
if (action == null) {
throw new NullPointerException("Action is NULL! YOU ARE A FOOL!");
@ -428,17 +459,20 @@ public class ArrayListASDV<E>
}
@Override
public void remove() {
public void remove()
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void set(E e) {
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) {
public void add(E e)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
};
@ -458,20 +492,23 @@ public class ArrayListASDV<E>
* @throws ClassCastException - if the types of one or more elements in the specified collection are incompatible with this collection
*/
@Override
public boolean containsAll(Collection<?> c) {
public boolean containsAll(Collection<?> c)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean addAll(Collection<? extends E> c) {
public boolean addAll(Collection<? extends E> c)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean addAll(int index, Collection<? extends E> c
) {
)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@ -486,7 +523,8 @@ public class ArrayListASDV<E>
* @throws ClassCastException - if the types of one or more elements in this collection are incompatible with the specified collection
*/
@Override
public boolean removeAll(Collection<?> c) {
public boolean removeAll(Collection<?> c)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@ -501,13 +539,15 @@ public class ArrayListASDV<E>
*/
@Override
public boolean retainAll(Collection<?> c
) {
)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public static void main(String[] args)
throws ClassNotFoundException, InterruptedException {
throws ClassNotFoundException, InterruptedException
{
ArrayList<Integer> aaa = new ArrayList();
ArrayListASDV<Integer> list1 = new ArrayListASDV();
@ -714,7 +754,8 @@ public class ArrayListASDV<E>
System.out.println(li.next());
li.forEachRemaining(new Consumer<Integer>() {
@Override
public void accept(Integer t) {
public void accept(Integer t)
{
System.out.print(t + 1 + " ");
}
});
@ -793,17 +834,20 @@ class A1 implements Consumer<A1> {
int x;
public A1(int x) {
public A1(int x)
{
this.x = x;
}
@Override
public String toString() {
public String toString()
{
return "A1{" + "x=" + x + '}';
}
@Override
public boolean equals(Object obj) {
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
@ -821,7 +865,8 @@ class A1 implements Consumer<A1> {
}
@Override
public void accept(A1 t) {
public void accept(A1 t)
{
System.out.println(t.x * t.x);
}

@ -10,33 +10,52 @@ import java.util.function.Consumer;
/**
*
* @author caleb
*/
public class IteratorASDV<T> implements Iterator<T> {
ArrayListASDV<?> arrayList;
public IteratorASDV(ArrayListASDV<?> arrayList) {
this.arrayList = arrayList;
*/
public class IteratorASDV<E> {
E[] list = (E[]) new Object[3];
int i;
public void add (E e) {
list[i++] = e;
}
/** Checks to see if the array has an element in it.
*
* @return true if our ArrayList has items in it
*/
@Override
public boolean hasNext() {
return arrayList.get(arrayList.size() - 1) != null;
public IteratorASDV<E> iterator() implements Iterator<T>{
Iterator<E> it = new Iterator<E>()
{
int index = 0;
@Override
public boolean hasNext()
{
if (index == IteratorASDV.this.list.length) {
return false;
}
return true;
}
@Override
public E next()
{
return IteratorASDV.this.list[index++];
}
@Override
public void forEachRemaining(Consumer<? super E> action)
{
Iterator.super.forEachRemaining(action); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/OverriddenMethodBody
}
};
return (IteratorASDV<E>) it;
}
public static void main(String[] args)
{
IteratorASDV<Integer> ti = new IteratorASDV<Integer>();
ti.add(1);
ti.add(2);
ti.add(3);
Iterator<Integer> it = (Iterator<Integer>) ti.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
}
@Override
public T next() {
arrayList.remove(0);
return (T) arrayList.get(0);
}
@Override
public void remove() {
Iterator.super.remove(); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/OverriddenMethodBody
}
}