Reset author name to chosen name

This commit is contained in:
2025-10-19 21:55:26 -05:00
parent a3e71f9673
commit 03c2474f78
1825 changed files with 8916 additions and 8921 deletions

View File

@@ -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>Graal_JDK_20</netbeans.hint.jdkPlatform>
</properties>
</project-shared-configuration>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.slcc.asdv.chloe</groupId>
<artifactId>MP1_ManyToMany_ChloeFontenot</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
<exec.mainClass>edu.slcc.asdv.chloe.mp1_manytomany_chloefontenot.MP1_ManyToMany_ChloeFontenot</exec.mainClass>
</properties>
</project>

View File

@@ -0,0 +1,114 @@
/*
* 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 edu.slcc.asdv.chloe.mp1_manytomany_chloefontenot;
/**
*
* @author chloe
*/
import java.util.List;
import java.util.Set;
/**
*
* @author A. V. Markou
* @param <Many1>
* @param <Many2>
*/
public interface ManyToMany<Many1, Many2>
{
/**
* 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.
* @return the previous value associated with Many1, or null if there was no
* Many1 with the same "key".
* @throws ClassCastException - if the class of the specified Many1, or
* Many2 or value prevents it from being stored in this map( i,e Many1 is
* String and you pass an object)
* @throws NullPointerException - if the specified Many1 or Many2 is null
* and ManyToMany does not permit nulls as values.
* @throw IllegalArgumentException - if a duplicate exists in childrenRight
* list ( s1 --> p1,p2,p2 is not allowed).
* @return the previous value associated with parentLeft, or null if there
* was no childrenRight for parentLeft.
*/
List<Many2> add(Many1 parentLeft, Many2... childrenRight);
/**
* 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.
*/
List<Many1> getChildrenLeft(Many2 parentRight);
/**
* 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.
*/
List<Many2> getChildrenRight(Many1 parentLeft);
/**
* Returns a set of the Many1 elements that exist on the LHS of the many to
* many relationship.
*
* @return Set of Many1
*/
Set<Many1> getParentsLeft();
/**
* Returns a set of the Many2 elements that exist on the RHS of the many to
* many relationship.
*
* @return Set of Many2
*/
Set<Many2> getParentsRight();
/**
* Removes the many1 parameter from the LHS of the many relationship AND all
* its corresponding values that exist in the RHS of the many to many
* relationship. For example given: ( LHS e1: p1, p2 e2: p2, p3 RHS: p1: e1
* p2: e1, e2 p3: e2 after removing e1 from the LHS will results into: ( LHS
* e2: p2, p3 RHS: p2: e2 p3: e2
*
* @param many1 the unique element on the LHS to be removed.
* @throws NullPointerException if parameter many1 is null.
* @return true if the removal occurred, false if many1 does not exist in
* the LHS of the many to many relationship.
*/
boolean removeLeft(Many1 many1);
/**
* Removes the many1 parameter from the RHS of the many relationship AND all
* its corresponding values that exist in the LHS of the many to many
* relationship. For example given: LHS e2: p2, p3 RHS: p2: e2 p3: e2 after
* removing p2 from the RHS will results into: LHS e2: p3 RHS p3: e2
*
*
* @param many2 the unique element on the LHS to be removed.
* @throws NullPointerException if parameter many1 is null.
* @return true if the removal occurred, false if many1 does not exist in
* the LHS of the many to many relationship.
*/
boolean removeRight(Many2 many2);
/**
* Clears all.
*
*/
void clear();
}

View File

@@ -0,0 +1,233 @@
/*
* 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 edu.slcc.asdv.chloe.mp1_manytomany_chloefontenot;
/**
*
* @author chloe
*/
import java.util.ArrayList;
import java.util.Arrays;
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;
/**
*
* @author asdv5
*/
public class ManyToManyFactory {
public static <Many1, Many2> //generic types to be used in the method
ManyToMany< Many1, Many2>//return type
createManyToMany() {
return new ManyToMany<Many1, Many2>() {
private HashSet<Many1> parents = new HashSet<>();
private Map<Object, Object> left = new HashMap<>();
private Map<Object, Object> right = new HashMap<>();
@Override
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.
*
* @param parentLeft - exactly one Many1 object.
* @param childrenRight - one or more Many2 objects.
* @return the previous value associated with Many1, or null if there was no Many1 with the same "key".
* @throws ClassCastException - if the class of the specified Many1, or Many2 or value prevents it from being stored in this map( i,e Many1 is String and you pass an object)
* @throws NullPointerException - if the specified Many1 or Many2 is null and ManyToMany does not permit nulls as values.
* @throw IllegalArgumentException - if a duplicate exists in childrenRight list ( s1 --> p1,p2,p2 is not allowed).
* @return the previous value associated with parentLeft, or null if there was no childrenRight for parentLeft.
*/
@Override
public List<Many2> add(Many1 parentLeft, Many2... childrenRight) {
HashSet<Many2> verifyUnique = new HashSet<>();
List<Many2> returnList = new ArrayList<>();
// Check for exceptions
if (!childrenRight.equals(parentLeft.getClass())) {
//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((<? extends Many2>) 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<Many2>(Arrays.asList(childrenRight)));
//}
//Handle RHS
/*
for (Many1 e: parents) {
right.put(, e );
}
*/
if (returnList.size() == 0) {
return null;
}
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<Many1> getChildrenLeft(Many2 parentRight) {
List<Many1> returnList = new ArrayList<Many1>();
for (Entry<Object, Object> 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<Many2> getChildrenRight(Many1 parentLeft) {
List<Many2> returnList = new ArrayList<>();
for (Entry<Object, Object> 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<Many1> getParentsLeft() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
@Override
public Set<Many2> getParentsRight() {
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() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
};
}
public static void main(String[] args) throws InterruptedException {
ManyToMany<String, String> 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("getChildrenLeft(p1) returns: " + mm.getChildrenLeft("p2"));
System.out.println("getChildrenLeft(p2) returns: " + mm.getChildrenLeft("p3"));
System.out.println("getChildrenRight(e1) returns: " + mm.getChildrenRight("e1"));
System.out.println("getChildrenRight(e1) returns: " + mm.getChildrenRight("e2"));
System.out.println("-----------------------------------------------");
System.out.println("The internal hash maps of ManyToMany after insertions: " + mm);
System.out.println("----------AFTER REMOVAL of e1 LEFT----------------------------------------");
System.out.println("removeLeft(e1) returns: " + mm.removeLeft("e1"));
System.out.println("getParentsLeft returns: " + mm.getParentsLeft());
System.out.println("getParentsRight returns: " + mm.getParentsRight());
System.out.println("getChildrenRight(e2) returns: " + mm.getChildrenRight("e2"));
System.out.println("getChildrenLeft(p2) returns: " + mm.getChildrenLeft("p2"));
System.out.println("getChildrenLeft(p3) returns: " + mm.getChildrenLeft("p3"));
System.out.println("The internal hash maps of ManyToMany after removal LEFT: " + mm);
System.out.println("\n----------AFTER REMOVAL of p2 RIGHT----------------------------------------");
System.out.println("removeLeft(p2) returns: " + mm.removeRight("p2"));
System.out.println("getParentsLeft returns: " + mm.getParentsLeft());
System.out.println("getParentsRight returns: " + mm.getParentsRight());
System.out.println("getChildrenRight(e2) returns: " + mm.getChildrenRight("e2"));
System.out.println("getChildrenLeft(p3) returns: " + mm.getChildrenLeft("p3"));
System.out.println("--------------------------------------------------");
System.out.println("mm.removeLeft(e1) returns: " + mm.removeLeft("e1"));
System.out.println("The internal hash maps of ManyToMany after removal RIGHT: " + mm);
Thread.sleep(5000, 0);
System.out.println("---------------CATCHING EXCEPTIONS -----------------------------------");
try {
mm.getChildrenRight("e10");//e10 dos not exist
} catch (RuntimeException e) {
System.err.println("getChildrenRight for e10 throws exception:" + e);
}
try {
System.out.println(mm.add("e6", new String[]{
"value1", null
}));
} catch (RuntimeException e) {
System.err.println("add(e6, new String[]{null } ) throws exception: " + e);
}
try {
System.out.println(mm.add(null, "p1"));
} catch (RuntimeException e) {
System.err.println("add(null, p1)returns throws exception: " + e);
}
try {
System.out.println(mm.getChildrenLeft("p1"));
} catch (RuntimeException e) {
System.err.println("getChildrenRight(p1) throws exception: " + e);
}
try {
mm.add((String) new Object(), (String) new Object());
} catch (RuntimeException e) {
System.err.println("add((String) new Object(), (String) new Object()) throws exception: " + e);
}
mm.clear();
System.out.println("-----------------------------------------------");
System.out.println("The internal hash maps of ManyToMany after clear: " + mm);
}
}