From eb8000ad4cc022c529fc0763ad79ea8fbc8a31da Mon Sep 17 00:00:00 2001
From: MAZZARELLA ENZO <enzo.mazzarella@etu.unistra.fr>
Date: Wed, 17 Mar 2021 10:42:05 +0100
Subject: [PATCH] Ajout du projet java

---
 P4a/.classpath                                |  11 +
 P4a/.project                                  |  17 ++
 P4a/.settings/org.eclipse.jdt.core.prefs      |  14 ++
 P4a/Common/PersonalStructure/ChainedList.java | 164 ++++++++++++++
 P4a/Common/PersonalStructure/Cursor.java      |  79 +++++++
 P4a/Common/PersonalStructure/Link.java        |  27 +++
 P4a/Common/StandardStructure/ArrayListC.java  |  73 ++++++
 P4a/Common/StandardStructure/LinkedListC.java |  73 ++++++
 P4a/Common/StandardStructure/Table.java       | 124 +++++++++++
 P4a/Common/defaultpackage/Main.java           | 208 ++++++++++++++++++
 P4a/Common/defaultpackage/Structure.java      |  13 ++
 P4a/bin/.gitignore                            |   3 +
 P4a/manifest                                  |   3 +
 13 files changed, 809 insertions(+)
 create mode 100644 P4a/.classpath
 create mode 100644 P4a/.project
 create mode 100644 P4a/.settings/org.eclipse.jdt.core.prefs
 create mode 100644 P4a/Common/PersonalStructure/ChainedList.java
 create mode 100644 P4a/Common/PersonalStructure/Cursor.java
 create mode 100644 P4a/Common/PersonalStructure/Link.java
 create mode 100644 P4a/Common/StandardStructure/ArrayListC.java
 create mode 100644 P4a/Common/StandardStructure/LinkedListC.java
 create mode 100644 P4a/Common/StandardStructure/Table.java
 create mode 100644 P4a/Common/defaultpackage/Main.java
 create mode 100644 P4a/Common/defaultpackage/Structure.java
 create mode 100644 P4a/bin/.gitignore
 create mode 100644 P4a/manifest

diff --git a/P4a/.classpath b/P4a/.classpath
new file mode 100644
index 0000000..98f7101
--- /dev/null
+++ b/P4a/.classpath
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="Common"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-15.0.2">
+		<attributes>
+			<attribute name="module" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/P4a/.project b/P4a/.project
new file mode 100644
index 0000000..a692bab
--- /dev/null
+++ b/P4a/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>P4a</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>
diff --git a/P4a/.settings/org.eclipse.jdt.core.prefs b/P4a/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..223b166
--- /dev/null
+++ b/P4a/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,14 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=15
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=15
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=15
diff --git a/P4a/Common/PersonalStructure/ChainedList.java b/P4a/Common/PersonalStructure/ChainedList.java
new file mode 100644
index 0000000..6605203
--- /dev/null
+++ b/P4a/Common/PersonalStructure/ChainedList.java
@@ -0,0 +1,164 @@
+package PersonalStructure;
+import defaultpackage.Structure;
+
+public class ChainedList implements Structure {
+	protected Link head;
+	protected Cursor cursor;
+	public int nbVal = 0;
+//	
+//	public ChainedList(Link head, Cursor cursor) {
+//		this.head = head;
+//		this.cursor = cursor;
+//		this.nbVal = 1;
+//	}
+
+	public ChainedList(Cursor cursor) {
+		this.cursor = cursor;
+		this.nbVal = 0;
+
+	}
+	
+
+	
+	public void setNextLink(Link currentLink)
+	{
+		Link last_next = this.cursor.currentLink.next;
+		this.cursor.currentLink.next = currentLink;
+		nbVal+=1;
+	}
+	
+	public void setPreviousLink(Link currentLink)
+	{
+		Link last_next = this.cursor.currentLink.next;
+		this.cursor.currentLink.next = currentLink;
+		nbVal+=1;
+	}
+	
+	public Link getLink()
+	{
+		return this.cursor.currentLink;
+	}
+	
+	public Link getNextLink()
+	{
+		return this.cursor.currentLink.next;
+	}
+	
+	public Link getPreviousLink(Link currentLink)
+	{
+		return this.cursor.currentLink.next;
+	}
+	
+	public void replaceCursor(int position)
+	{
+
+		this.cursor.currentList = this;
+		this.cursor.position(position);
+
+	}
+	
+	public boolean isEmpty() {
+		boolean res = false;
+		if(this.nbVal != 0)
+			res = true;
+		return res;
+	}
+
+	@Override
+	public void Add(int value) {
+
+		if (nbVal == 0) {
+			
+			Link new_link = new Link(value);
+			this.head = new_link;
+			this.head.last = new_link;
+
+			this.cursor.currentLink = new_link;
+
+			this.head.next = new_link;
+		}
+		else {
+
+			
+			this.replaceCursor(this.nbVal);
+		
+			Link last_before_added = this.cursor.currentLink.last;
+			Link next_after_added = this.head;
+		
+			Link new_link = new Link(value, next_after_added, last_before_added);
+
+			last_before_added.next = new_link;
+			this.head.last = new_link;
+		
+			this.cursor.currentLink = new_link;
+		}
+		this.nbVal += 1;
+
+	}
+	
+	public int GetNbVal()
+	{
+		return this.nbVal;
+	}
+
+	@Override
+	public void RemoveTete() throws Exception  {
+
+		
+		this.replaceCursor(nbVal - 1);
+		Link last_of_remove = this.cursor.currentLink.last;
+		Link next_of_remove = this.cursor.currentLink.next;
+		
+		last_of_remove.next = next_of_remove;
+		next_of_remove.last = last_of_remove;
+		
+		this.cursor.currentLink = next_of_remove;
+	}
+
+	@Override
+	public int Get(int index) throws Exception {
+		if ((index < 0) && isEmpty())
+			throw new IndexOutOfBoundsException("Wrong position");
+		this.replaceCursor(index);
+		return this.cursor.currentLink.value;
+	}
+
+
+
+	@Override
+	public void RemoveMiddle() throws Exception 
+	{
+		if(nbVal%2==0)
+		{
+			// TODO Auto-generated method stub
+			this.replaceCursor(nbVal / 2);
+			Link last_of_remove = this.cursor.currentLink.last;
+			Link next_of_remove = this.cursor.currentLink.next;
+			
+			last_of_remove.next = next_of_remove;
+			next_of_remove.last = last_of_remove;
+			
+			this.cursor.currentLink = next_of_remove;
+		}
+		else 
+		{
+			// TODO Auto-generated method stub
+			this.replaceCursor((nbVal-1) / 2);
+			Link last_of_remove = this.cursor.currentLink.last;
+			Link next_of_remove = this.cursor.currentLink.next;
+						
+			last_of_remove.next = next_of_remove;
+			next_of_remove.last = last_of_remove;
+						
+			this.cursor.currentLink = next_of_remove;
+		}
+	}
+
+
+
+	@Override
+	public int GetLenght() {
+		// TODO Auto-generated method stub
+		return nbVal;
+	}
+}
diff --git a/P4a/Common/PersonalStructure/Cursor.java b/P4a/Common/PersonalStructure/Cursor.java
new file mode 100644
index 0000000..7e48e11
--- /dev/null
+++ b/P4a/Common/PersonalStructure/Cursor.java
@@ -0,0 +1,79 @@
+package PersonalStructure;
+
+public class Cursor {
+	protected Link currentLink;
+	protected ChainedList currentList;
+	protected int pos;
+	
+	public Cursor(ChainedList currentList, Link currentLink, int pos) {
+		this.currentLink = currentLink;
+		this.currentList = currentList;
+		this.pos = pos;
+	}
+
+	public Cursor() {
+		this.pos = 0;
+	}
+	
+	public void position(int pos)
+	{
+		// si on est arrivé à la bonne position, on garde le maillon actuel
+		if (pos == this.pos)
+		{ 
+			return;
+		}
+		// si nous sommes avant la position voulue, on avance
+		else if (pos > this.pos)
+		{
+			while(pos != this.pos)
+			{
+				goForward();
+			}
+		}
+		// si nous sommes après la position voulue, on recule
+		else if (pos < this.pos)
+		{
+			while(pos != this.pos)
+			{
+				goBack();
+			}
+		}
+	}
+	
+	private void goForward()
+	{
+
+		
+		// si on n'est pas encore arrivé à la fin de la liste, on avance
+		if(this.pos <= this.currentList.GetNbVal())
+		{
+			this.pos += 1;
+			this.currentLink = this.currentLink.next;
+		}
+		// sinon on retourne au début de la liste
+		else 
+		{
+			this.pos = 0;
+			this.currentLink = this.currentList.head;
+		}
+	}
+	
+	private void goBack() {
+		// si on n'est pas encore arrivé au début de la liste, on recule
+		if(this.pos >= 0)
+		{
+			this.pos -= 1;
+		}
+		// sinon on va à la fin de la liste
+		else {
+			this.pos = this.currentList.nbVal;
+		}
+		// on recule toujours
+		this.currentLink = this.currentLink.last;
+	}
+
+	private void setList(ChainedList list) {
+		this.currentList = list;
+		this.currentLink = list.head;	
+	}
+}
diff --git a/P4a/Common/PersonalStructure/Link.java b/P4a/Common/PersonalStructure/Link.java
new file mode 100644
index 0000000..2f8fd76
--- /dev/null
+++ b/P4a/Common/PersonalStructure/Link.java
@@ -0,0 +1,27 @@
+package PersonalStructure;
+
+public class Link {
+	protected int value;
+	protected Link next;
+	protected Link last;
+	
+	public Link(int value, Link next, Link last) {
+		this.value = value;
+		this.next = next;
+		this.last = next;
+	}
+
+	public Link(int value) {
+		this.value = value;
+	}
+
+	public void setNext(Link next) {
+		this.next = next;
+	}
+
+	public void setLast(Link last) {
+		this.last = last;
+	}
+
+}
+
diff --git a/P4a/Common/StandardStructure/ArrayListC.java b/P4a/Common/StandardStructure/ArrayListC.java
new file mode 100644
index 0000000..0bbed26
--- /dev/null
+++ b/P4a/Common/StandardStructure/ArrayListC.java
@@ -0,0 +1,73 @@
+package StandardStructure;
+
+import defaultpackage.Structure;
+import java.util.ArrayList;
+import java.util.Random;;
+
+public class ArrayListC implements Structure
+{
+	protected ArrayList<Integer> arrayList;
+	
+	public ArrayListC(int nbValue) 
+	{
+		Random rnd = new Random();
+		arrayList = new ArrayList<Integer>();
+		for(int i = 0; i < nbValue; i++) 
+		{
+			Add(rnd.nextInt());
+		}
+
+	}
+
+	@Override
+	public void Add(int value) 
+	{
+		arrayList.add(value);
+	}
+
+	@Override
+	public void RemoveTete() throws Exception 
+	{	
+		try 
+		{
+			arrayList.remove(arrayList.size() - 1);
+		}
+		catch(IndexOutOfBoundsException e)
+		{
+			throw new Exception("L'index défini ne se situe pas dans les bornes du tableau");
+		}
+	}
+
+	@Override
+	public int Get(int index) throws Exception
+	{
+		try 
+		{
+			return arrayList.get(index);
+		}
+		catch(IndexOutOfBoundsException e)
+		{
+			throw new Exception("L'index défini ne se situe pas dans les bornes du tableau");
+		}
+	}
+	
+
+	@Override
+	public void RemoveMiddle() throws Exception {
+		// TODO Auto-generated method stub
+		if(arrayList.size()%2==0) {
+			arrayList.remove(arrayList.size()/2);
+		}
+		else {
+			arrayList.remove((arrayList.size()-1)/2);
+		}
+		
+
+	}
+
+	@Override
+	public int GetLenght() {
+		// TODO Auto-generated method stub
+		return arrayList.size();
+	}
+}
diff --git a/P4a/Common/StandardStructure/LinkedListC.java b/P4a/Common/StandardStructure/LinkedListC.java
new file mode 100644
index 0000000..44af951
--- /dev/null
+++ b/P4a/Common/StandardStructure/LinkedListC.java
@@ -0,0 +1,73 @@
+package StandardStructure;
+
+import java.util.LinkedList;
+import java.util.Random;
+
+import defaultpackage.Structure;
+
+public class LinkedListC implements Structure
+{
+	
+	LinkedList<Integer> linkedList;
+	
+	public LinkedListC(int nbValue) 
+	{
+		Random rnd = new Random();
+		linkedList = new LinkedList<Integer>();
+		for(int i = 0; i < nbValue; i++) {
+			Add(rnd.nextInt());
+		}
+	}
+	@Override
+	public void Add(int value) {
+		// TODO Auto-generated method stub
+		
+		linkedList.add(value);
+	}
+
+	@Override
+	public void RemoveTete() throws Exception  {
+		// TODO Auto-generated method stub
+		
+		try 
+		{
+			linkedList.remove(linkedList.size() - 1);
+		}
+		catch(IndexOutOfBoundsException e)
+		{
+			throw new Exception("L'index défini ne se situe pas dans les bornes du tableau");
+		}
+	}
+
+	@Override
+	public int Get(int index) throws Exception
+	{
+		// TODO Auto-generated method stub
+		try
+		{
+			return linkedList.get(index);
+		}
+		catch(IndexOutOfBoundsException e)
+		{
+			throw new Exception("L'index défini ne se situe pas dans les bornes du tableau");
+		}
+	}
+	
+	@Override
+	public void RemoveMiddle() throws Exception {
+		// TODO Auto-generated method stub
+		if(linkedList.size()%2==0) {
+			linkedList.remove(linkedList.size()/2);
+		}
+		else {
+			linkedList.remove((linkedList.size()-1)/2);
+		}
+
+	}
+	@Override
+	public int GetLenght() {
+		// TODO Auto-generated method stub
+		return linkedList.size();
+	}
+
+}
diff --git a/P4a/Common/StandardStructure/Table.java b/P4a/Common/StandardStructure/Table.java
new file mode 100644
index 0000000..6cdeee4
--- /dev/null
+++ b/P4a/Common/StandardStructure/Table.java
@@ -0,0 +1,124 @@
+package StandardStructure;
+
+import java.util.Random;
+
+import defaultpackage.Structure;
+
+public class Table implements Structure
+{
+	Integer[] tab;
+	Integer nbValue = 0;
+	
+	public Table(int nbValue)
+	{
+
+		Random rnd = new Random();
+		
+		tab = new Integer[nbValue];
+		
+		for(int i = 0; i < nbValue;i++) 
+		{
+			Add(rnd.nextInt());
+		}
+		
+	}
+
+	@Override
+	public void Add(int value) {
+		// TODO Auto-generated method stub
+		
+		if(nbValue < tab.length) 
+		{
+			tab[nbValue] = value;
+			nbValue++;
+		}
+		else 
+		{
+			Integer[] temp = new Integer[nbValue * 2];
+			
+			for(int i = 0; i < nbValue; i++) 
+			{
+				temp[i] = tab[i];
+			}
+			
+			temp[nbValue] = value;
+			tab=temp;
+		}
+
+		
+	}
+
+	@Override
+	public void RemoveTete() throws Exception 
+	{
+		// TODO Auto-generated method stub
+		try 
+		{
+		
+			for(int y = 1; y<tab.length;y++) 
+			{
+				tab[y-1] = tab[y];
+			}
+			
+			nbValue--;
+
+		}
+		catch(IndexOutOfBoundsException e)
+		{
+			throw new Exception("L'index défini ne se situe pas dans les bornes du tableau");
+		}
+		
+	}
+
+	@Override
+	public int Get(int index) throws Exception 
+	{
+		// TODO Auto-generated method stub
+		try 
+		{
+			return tab[index];
+		}
+		catch(IndexOutOfBoundsException e)
+		{
+			throw new Exception("L'index défini ne se situe pas dans les bornes du tableau");
+		}
+		catch(NullPointerException e) 
+		{
+			throw new Exception("Tableau n'existe pas");
+		}
+	}
+
+	@Override
+	public void RemoveMiddle() throws Exception
+	{
+		// TODO Auto-generated method stub
+		if(tab.length%2==0)
+		{
+			tab[tab.length/2]=null;
+		}
+		else
+		{
+			tab[(tab.length - 1)/2]=null;
+		}
+		
+		int i = 0;
+		
+		while(tab[i] != null)
+		{
+			i++;
+		}
+		
+		for(int y = i+1; y<tab.length-1;y++) 
+		{
+			tab[y-1] = tab[y];
+		}
+
+	}
+
+	@Override
+	public int GetLenght() {
+		// TODO Auto-generated method stub
+		return nbValue;
+	}
+
+}
diff --git a/P4a/Common/defaultpackage/Main.java b/P4a/Common/defaultpackage/Main.java
new file mode 100644
index 0000000..7d6cdf3
--- /dev/null
+++ b/P4a/Common/defaultpackage/Main.java
@@ -0,0 +1,208 @@
+package defaultpackage;
+
+import java.math.BigInteger;
+import java.util.Random;
+
+import com.sun.jdi.Type;
+
+import PersonalStructure.ChainedList;
+import PersonalStructure.Cursor;
+import StandardStructure.ArrayListC;
+import StandardStructure.LinkedListC;
+import StandardStructure.Table;
+
+
+public class Main {
+
+	Type tab;
+	public static void main(String[] args) throws NumberFormatException, Exception {
+
+		// TODO Auto-generated method stub
+        GenerateTab(args[0],  Integer.parseInt(args[1]), args[2], Integer.parseInt(args[3]));
+
+	}
+	
+	public static void GenerateTab(String type, int nbValue, String methode, Integer nbOperation) throws Exception 
+	{
+		Random rnd = new Random();
+		if(type.equals("Tableau")) 
+		{
+			Table tab = new Table(nbValue);
+			
+
+
+			switch(methode)
+			{
+				case "Add":
+				{
+					for(int i = 0; i < nbOperation; i++)
+					{
+						tab.Add(rnd.nextInt());
+					}
+					break;
+				
+				}
+				case"RemoveTete":
+				{
+					for(int i = 0; i < nbOperation; i++) 
+					{
+						tab.RemoveTete();
+					}
+					break;
+				}
+				case"RemoveMiddle":
+				{
+					for(int i = 0; i < nbOperation; i++) 
+					{
+						tab.RemoveMiddle();
+					}
+					break;
+				}
+				case "Get":
+				{
+					for(int i = 0; i < nbOperation; i++) 
+					{
+						tab.Get(rnd.nextInt(tab.GetLenght()-1));
+					}
+					break;
+				}
+			}
+		}
+
+		
+		if(type.equals("Array")) {
+			ArrayListC array = new ArrayListC(nbValue);
+			
+			switch(methode)
+			{
+				case "Add":
+				{
+					for(int i = 0; i < nbOperation; i++)
+					{
+						array.Add(rnd.nextInt());
+					}
+					break;
+				
+				}
+				case"RemoveTete":
+				{
+					for(int i = 0; i < nbOperation; i++) 
+					{
+						array.RemoveTete();
+					}
+					break;
+				}
+				case"RemoveMiddle":
+				{
+					for(int i = 0; i < nbOperation; i++) 
+					{
+						array.RemoveMiddle();
+					}
+					break;
+				}
+				case "Get":
+				{
+					for(int i = 0; i < nbOperation; i++) 
+					{
+						array.Get(rnd.nextInt(array.GetLenght()));
+					}
+					break;
+				}
+			}
+			
+		}
+		
+		if(type.equals("Linked")) 
+		{
+			LinkedListC linked = new LinkedListC(nbValue);
+			
+			switch(methode)
+			{
+				case "Add":
+				{
+					for(int i = 0; i < nbOperation; i++)
+					{
+						linked.Add(rnd.nextInt());
+					}
+					break;
+				
+				}
+				case"RemoveTete":
+				{
+					for(int i = 0; i < nbOperation; i++) 
+					{
+						linked.RemoveTete();
+					}
+					break;
+				}
+				case"RemoveMiddle":
+				{
+					for(int i = 0; i < nbOperation; i++) 
+					{
+						linked.RemoveMiddle();
+					}
+					break;
+				}
+				case "Get":
+				{
+					for(int i = 0; i < nbOperation; i++) 
+					{
+						linked.Get(rnd.nextInt(linked.GetLenght()-1));
+					}
+					break;
+				}
+			}
+		}
+		
+		if(type.equals("Maillon")) 
+		{
+			Cursor cursor = new Cursor();
+			ChainedList maillons = new ChainedList(cursor);
+			
+			Random rndMaillon = new Random();
+			
+			for(int i = 0; i < nbValue; i++) {
+
+					maillons.Add(rndMaillon.nextInt());				
+			}
+			
+			switch(methode)
+			{
+				case "Add":
+				{
+					for(int i = 0; i < nbOperation; i++)
+					{
+						maillons.Add(rnd.nextInt());
+					}
+					break;
+				
+				}
+				case"RemoveTete":
+				{
+					for(int i = 0; i < nbOperation; i++) 
+					{
+						maillons.RemoveTete();
+					}
+					break;
+				}
+				case"RemoveMiddle":
+				{
+					for(int i = 0; i < nbOperation; i++) 
+					{
+						maillons.RemoveMiddle();
+					}
+					break;
+				}
+				case "Get":
+				{
+					for(int i = 0; i < nbOperation; i++) 
+					{
+						maillons.Get(rnd.nextInt(maillons.GetLenght()-1));
+					}
+					break;
+				}
+			}
+		}
+	}
+
+}
diff --git a/P4a/Common/defaultpackage/Structure.java b/P4a/Common/defaultpackage/Structure.java
new file mode 100644
index 0000000..a4aeb3e
--- /dev/null
+++ b/P4a/Common/defaultpackage/Structure.java
@@ -0,0 +1,13 @@
+package defaultpackage;
+
+
+public interface Structure 
+{
+		
+	public void Add(int value);
+	public void RemoveTete() throws Exception;
+	public void RemoveMiddle() throws Exception;
+	public int Get(int index) throws Exception;
+	public int GetLenght();
+
+}
diff --git a/P4a/bin/.gitignore b/P4a/bin/.gitignore
new file mode 100644
index 0000000..817b61a
--- /dev/null
+++ b/P4a/bin/.gitignore
@@ -0,0 +1,3 @@
+/StandardStructure/
+/defaultpackage/
+/PersonalStructure/
diff --git a/P4a/manifest b/P4a/manifest
new file mode 100644
index 0000000..7e6b236
--- /dev/null
+++ b/P4a/manifest
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: defaultpackage.Main
+
-- 
GitLab