Markou is absolutely insane
This commit is contained in:
14
Semester 4/Assignments/DAO/pom.xml
Normal file
14
Semester 4/Assignments/DAO/pom.xml
Normal 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.caleb</groupId>
|
||||
<artifactId>DAO</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.caleb.dao.DAO</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
20
Semester 4/Assignments/DAO/src/main/java/DAO/DAO.java
Normal file
20
Semester 4/Assignments/DAO/src/main/java/DAO/DAO.java
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
|
||||
*/
|
||||
package DAO;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public interface DAO<T> {
|
||||
public void create(T t);
|
||||
public void delete(T t);
|
||||
public void update(T t);
|
||||
public T find (T t);
|
||||
public Collection<T> findALl();
|
||||
public boolean updateDBase();
|
||||
}
|
19
Semester 4/Assignments/DAO/src/main/java/DAO/Exam.java
Normal file
19
Semester 4/Assignments/DAO/src/main/java/DAO/Exam.java
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
|
||||
*/
|
||||
package DAO;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public interface Exam<T> {
|
||||
void editExam(T t);
|
||||
void takeExam(T t);
|
||||
void submitExam(T t);
|
||||
void previewExam(T t);
|
||||
void monitorExam(T t);
|
||||
void gradeExam(T t);
|
||||
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* 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 DAO;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public abstract class ExamFactory<T extends Keyable> {
|
||||
public abstract Exam<T> createExam();
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 DAO;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ExamFactoryOutlet<K, V extends Keyable> extends ExamFactory<Keyable> {
|
||||
|
||||
@Override
|
||||
public Exam<Keyable> createExam()
|
||||
{
|
||||
return new Exam<Keyable>() {
|
||||
@Override
|
||||
public void editExam(Keyable t)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeExam(Keyable t)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submitExam(Keyable t)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void previewExam(Keyable t)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void monitorExam(Keyable t)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gradeExam(Keyable t)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
15
Semester 4/Assignments/DAO/src/main/java/DAO/Keyable.java
Normal file
15
Semester 4/Assignments/DAO/src/main/java/DAO/Keyable.java
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
|
||||
*/
|
||||
package DAO;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public interface Keyable<K> {
|
||||
public K getKey();
|
||||
public void setKey(K key);
|
||||
|
||||
}
|
32
Semester 4/Assignments/DAO/src/main/java/DAO/MathExam.java
Normal file
32
Semester 4/Assignments/DAO/src/main/java/DAO/MathExam.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 DAO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class MathExam implements Keyable<MathExam> {
|
||||
ArrayList<Object> fields = new ArrayList<Object>();
|
||||
int key;
|
||||
|
||||
public MathExam(int key, ArrayList<Object> fields) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public MathExam getKey()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKey(MathExam key)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
}
|
23
Semester 4/Assignments/DAO/src/main/java/DAO/Test.java
Normal file
23
Semester 4/Assignments/DAO/src/main/java/DAO/Test.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 DAO;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Test {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
ExamFactory<MathExam> efm = new ExamFactory<MathExam>() {
|
||||
@Override
|
||||
public Exam<MathExam> createExam()
|
||||
{
|
||||
System.out.println("Hello World");
|
||||
}
|
||||
};
|
||||
efm.createExam();
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.caleb.dao.factory_pizza;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class CheezePizza implements Pizza {
|
||||
|
||||
@Override
|
||||
public void prepare()
|
||||
{
|
||||
System.out.println("preparing Cheeze Pizza");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bake()
|
||||
{
|
||||
System.out.println("baking Cheeze Pizza");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cut()
|
||||
{
|
||||
System.out.println("cutting Cheeze Pizza");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.caleb.dao.factory_pizza;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ChickenPizza implements Pizza {
|
||||
|
||||
@Override
|
||||
public void prepare()
|
||||
{
|
||||
System.out.println("preparing Chicken Pizza");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bake()
|
||||
{
|
||||
System.out.println("baking Chicken Pizza");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cut()
|
||||
{
|
||||
System.out.println("cutting Chicken Pizza");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
|
||||
*/
|
||||
package edu.slcc.asdv.caleb.dao.factory_pizza;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public interface Pizza<T> {
|
||||
public void prepare(T t);
|
||||
public void bake(T t);
|
||||
public void cut(T t);
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.caleb.dao.factory_pizza;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class PizzaFactory {
|
||||
|
||||
public PizzaFactory(String cheeze)
|
||||
{
|
||||
}
|
||||
public static <T> Pizza<T> createPizza(T type) throws Exception {
|
||||
Pizza p = null;
|
||||
if (type.equals("cheeze"))
|
||||
p = new CheezePizza();
|
||||
else if (type.equals("chicken"))
|
||||
p = new ChickenPizza();
|
||||
else if (type.equals("veggie"))
|
||||
p = new VeggiePizza();
|
||||
if (p == null) {
|
||||
throw new Exception("Not a valid Pizza.");
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.caleb.dao.factory_pizza;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class PizzaStore {
|
||||
public Pizza orderPizza(String type) throws Exception {
|
||||
Pizza p = PizzaFactory.createPizza(type);
|
||||
p.prepare();
|
||||
p.bake();
|
||||
p.cut();
|
||||
return p;
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.caleb.dao.factory_pizza;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class TestPizza {
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
PizzaStore ps = new PizzaStore();
|
||||
ps.orderPizza("cheeze");
|
||||
ps.orderPizza("chicken");
|
||||
ps.orderPizza("veggie");
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.caleb.dao.factory_pizza;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class VeggiePizza implements Pizza {
|
||||
|
||||
@Override
|
||||
public void prepare()
|
||||
{
|
||||
System.out.println("Preparing Veggie Pizza");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bake()
|
||||
{
|
||||
System.out.println("Baking Veggie Pizza");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cut()
|
||||
{
|
||||
System.out.println("Cutting Veggie Pizza");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
|
||||
*/
|
||||
package factory_generic_pizza;
|
||||
|
||||
import edu.slcc.asdv.caleb.dao.factory_pizza.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Pizza<T> {
|
||||
public void prepare(Object t)
|
||||
{
|
||||
System.out.println("preparing " + t.toString() +" Pizza");
|
||||
}
|
||||
|
||||
public void bake(Object t)
|
||||
{
|
||||
System.out.println("baking " + t.toString() +" Pizza");
|
||||
}
|
||||
|
||||
public void cut(Object t)
|
||||
{
|
||||
System.out.println("cutting" + t.toString() +"Pizza");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 factory_generic_pizza;
|
||||
|
||||
import edu.slcc.asdv.caleb.dao.factory_pizza.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class PizzaFactory {
|
||||
public static <T> Pizza<T> createPizza(T t)
|
||||
{
|
||||
return new Pizza<T>()
|
||||
{
|
||||
public void prepare(T t) {
|
||||
System.out.println("Preparing pizza " + t.toString() + "...");
|
||||
}
|
||||
|
||||
public void bake(T t) {
|
||||
System.out.println("Baking pizza " + t.toString() + "...");
|
||||
}
|
||||
|
||||
public void cut(T t) {
|
||||
System.out.println("Cutting pizza " + t.toString() + "...");
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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 factory_generic_pizza;
|
||||
|
||||
import edu.slcc.asdv.caleb.dao.factory_pizza.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class PizzaStore {
|
||||
public Pizza orderPizza(String type) throws Exception {
|
||||
Pizza p = PizzaFactory.createPizza(type);
|
||||
p.prepare(type);
|
||||
p.bake(type);
|
||||
p.cut(type);
|
||||
return p;
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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 factory_generic_pizza;
|
||||
|
||||
import edu.slcc.asdv.caleb.dao.factory_pizza.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class TestPizza {
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
PizzaStore ps = new PizzaStore();
|
||||
ps.orderPizza("cheeze");
|
||||
ps.orderPizza("chicken");
|
||||
ps.orderPizza("veggie");
|
||||
}
|
||||
}
|
18
Semester 4/Assignments/DataStructures/nb-configuration.xml
Normal file
18
Semester 4/Assignments/DataStructures/nb-configuration.xml
Normal 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>JDK_1.8</netbeans.hint.jdkPlatform>
|
||||
</properties>
|
||||
</project-shared-configuration>
|
14
Semester 4/Assignments/DataStructures/pom.xml
Normal file
14
Semester 4/Assignments/DataStructures/pom.xml
Normal 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.caleb</groupId>
|
||||
<artifactId>DataStructures</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<exec.mainClass>edu.slcc.asdv.caleb.datastructures.DataStructures</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package edu.slcc.asdv.caleb.datastructures;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class DataStructures {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.caleb.datastructures;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public interface OneToMany<One, Many>
|
||||
{
|
||||
/**
|
||||
* Initialization of Ones. The method should be used first before any other
|
||||
* methods
|
||||
*
|
||||
* @param one - the ones ( i.e, countries, or SelectItem or any Object) to
|
||||
* use for initialization
|
||||
* @return true if the initialization succeeded by using the method once,
|
||||
* false when the method is used more than once.
|
||||
*/
|
||||
boolean initializeOne(One... one);
|
||||
|
||||
/**
|
||||
* Initialization of the many for a given one. The method can be used
|
||||
* multiple times after the method initializeOne has succeeded.
|
||||
*
|
||||
* @param one - the one that has the many
|
||||
* @param many - the many which belong to th eone
|
||||
* @throws IllegalArgumentException when the one does not exist (i.e. user's
|
||||
* typing error for the name of one) or when the initialization of the one
|
||||
* has not occurred.
|
||||
*
|
||||
*/
|
||||
void initializeMany(One one, Many... many)
|
||||
throws IllegalArgumentException;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the many of a specific one.
|
||||
*
|
||||
* @param one the one to get its many
|
||||
* @return the many of the parameter one or null if the one does not exist.
|
||||
*/
|
||||
Collection<Many> getMany(One one);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Given a value of the many it gets the one that the many belongs to.
|
||||
*
|
||||
* @param many one of the values of the many
|
||||
* @return the one
|
||||
*/
|
||||
One getOne(Many many);
|
||||
|
||||
/**
|
||||
* Gets a set with all the ones
|
||||
*
|
||||
* @return the set of ones.
|
||||
*/
|
||||
Set<One> getAllOnes();
|
||||
}
|
||||
|
@@ -0,0 +1,185 @@
|
||||
package edu.slcc.asdv.caleb.datastructures;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class OneToManyFactory {
|
||||
|
||||
/**
|
||||
* Creates an object of type OneToMany
|
||||
*
|
||||
* @param <One> a generic parameter can be any object that denotes a One.
|
||||
* @param <Many> a generic parameter can be any object that denotes a city that belongs to the one generic type.
|
||||
* @return a OneCity object.
|
||||
*/
|
||||
public static <One, Many> //generic types to be used in the method
|
||||
OneToMany<One, Many> //rturn type
|
||||
createOneToMany()
|
||||
{
|
||||
return new OneToMany<One, Many>() {
|
||||
private Map<One, Many> oneToMany = new HashMap();
|
||||
boolean oneInitialized = false;
|
||||
boolean manyInitialized = false;
|
||||
|
||||
@Override
|
||||
public boolean initializeOne(One... one)
|
||||
{
|
||||
if (oneInitialized == false && manyInitialized == false) {
|
||||
for (int i = 0; i < one.length; ++i) {
|
||||
oneToMany.put(one[i], (Many) new Boolean(true));
|
||||
}
|
||||
oneInitialized = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeMany(One one, Many... many)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (oneToMany.get(one) == null) { // of the key of the one is null
|
||||
// the method initializekey has not been used
|
||||
throw new IllegalArgumentException(one + " is not valid.");
|
||||
}
|
||||
oneToMany.put(one, (Many) new ArrayList<Many>(Arrays.asList(many)));
|
||||
manyInitialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Many> getMany(One one)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (oneInitialized == true && manyInitialized == true) {
|
||||
if (oneToMany.get(one) == null) {
|
||||
throw new IllegalArgumentException(one + " is not a valid One");
|
||||
}
|
||||
Collection c1 = (Collection) oneToMany.get(one);
|
||||
return c1;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public One getOne(Many many)
|
||||
{
|
||||
Set< Entry<One, Many>> set = oneToMany.entrySet();
|
||||
for (Map.Entry<One, Many> entry : oneToMany.entrySet()) {
|
||||
One key = (One) entry.getKey();
|
||||
Collection<Many> value = (Collection<Many>) oneToMany.get(key);
|
||||
if (value.contains(many)) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<One> getAllOnes()
|
||||
{
|
||||
return (Set<One>) oneToMany.keySet();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
|
||||
OneToMany cc = OneToManyFactory.createOneToMany();
|
||||
|
||||
try {
|
||||
cc.initializeMany("France", "Paris");
|
||||
} catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
boolean b1 = cc.initializeOne("USA", "Greece");
|
||||
System.out.println(b1);
|
||||
boolean b2 = cc.initializeOne("USA", "Greece");
|
||||
System.out.println(b2);
|
||||
cc.initializeMany("USA", "Lafayette", "New Orleans");
|
||||
cc.initializeMany("Greece", "Athens", "Sparta");
|
||||
Collection<String> cities1 = cc.getMany("USA");
|
||||
System.out.println(cities1);
|
||||
Collection<String> cities2 = cc.getMany("Greece");
|
||||
System.out.println(cities2);
|
||||
System.out.println(cc.getOne("Athens"));
|
||||
System.out.println(cc.getOne("Lafayette"));
|
||||
System.out.println(cc.getOne("France"));
|
||||
try {
|
||||
System.out.println(cc.getMany("Germany"));
|
||||
} catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
|
||||
System.out.println(cc.getAllOnes());
|
||||
System.out.println("----------------------------------------------------------");
|
||||
OneToMany supplierParts = OneToManyFactory.createOneToMany();
|
||||
supplierParts.initializeOne(new Supplier("s1"), new Supplier("s2"));
|
||||
Supplier s1 = new Supplier("s1");
|
||||
Supplier s2 = new Supplier("s2");
|
||||
supplierParts.initializeOne(s1, s2);
|
||||
Part p1 = new Part("p1");
|
||||
Part p2 = new Part("p2");
|
||||
Part p3 = new Part("p3");
|
||||
Part p4 = new Part("p4");
|
||||
supplierParts.initializeMany(s1, p1, p2);
|
||||
supplierParts.initializeMany(s2, p3, p4);
|
||||
}
|
||||
}
|
||||
class Supplier {
|
||||
|
||||
public Supplier(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Supplier{" + "name=" + name + '}';
|
||||
}
|
||||
}
|
||||
|
||||
class Part {
|
||||
|
||||
public Part(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Part{" + "name=" + name + '}';
|
||||
}
|
||||
}
|
14
Semester 4/Assignments/ProjectTrees_CalebFontenot/pom.xml
Normal file
14
Semester 4/Assignments/ProjectTrees_CalebFontenot/pom.xml
Normal 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.caleb</groupId>
|
||||
<artifactId>ProjectTrees_CalebFontenot</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.caleb.projecttrees_calebfontenot.ProjectTrees_CalebFontenot</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package edu.slcc.asdv.caleb.projecttrees_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ProjectTrees_CalebFontenot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* 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.caleb.projecttrees_calebfontenot;
|
||||
|
||||
import java.util.ListIterator;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class TreeASDV<T extends Comparable> {
|
||||
|
||||
private Node<T> root;
|
||||
|
||||
class Node<T> {
|
||||
|
||||
T data;
|
||||
Node<T> leftChild;
|
||||
Node<T> rightChild;
|
||||
}
|
||||
|
||||
public boolean insert(T t)
|
||||
{
|
||||
Node<T> currentNode = root;
|
||||
Node<T> trailCurrent = root;
|
||||
Node<T> newNode = new Node<T>();
|
||||
newNode.data = t;
|
||||
System.out.println(t);
|
||||
|
||||
if (this.root == null) {
|
||||
this.root = newNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
while (currentNode != null) {
|
||||
trailCurrent = currentNode;
|
||||
if (t.compareTo(currentNode.data) >= 0) {
|
||||
currentNode = currentNode.rightChild;
|
||||
} else {
|
||||
currentNode = currentNode.leftChild;
|
||||
}
|
||||
if (t.compareTo(trailCurrent.data) >= 0) { // Make the node a right child.
|
||||
trailCurrent.rightChild = newNode;
|
||||
} else { // Make the node a left child.
|
||||
trailCurrent.leftChild = newNode;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void inOrder(Node<T> p)
|
||||
{
|
||||
if (p == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
inOrder(p.leftChild);
|
||||
System.out.print(p.data + " ");
|
||||
inOrder(p.rightChild);
|
||||
}
|
||||
|
||||
public void inOrder()
|
||||
{
|
||||
inOrder(this.root);
|
||||
}
|
||||
|
||||
public Node<T> findNode(T t)
|
||||
{
|
||||
Node<T> currentNode = root;
|
||||
while (currentNode != null) {
|
||||
if (t.compareTo(currentNode.data) == 0) {
|
||||
return currentNode;
|
||||
} else if (t.compareTo(currentNode.data) > 0) {
|
||||
currentNode = currentNode.rightChild;
|
||||
} else {
|
||||
currentNode = currentNode.leftChild;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean remove(T t)
|
||||
{
|
||||
// case: no children
|
||||
if (root.leftChild == null & root.rightChild == null) {
|
||||
root = null;
|
||||
return true;
|
||||
}
|
||||
Node<T> current = this.root;
|
||||
Node<T> currentParent = this.root;
|
||||
|
||||
while (current.data.equals(t)) {
|
||||
if (t.compareTo(current.data) == 0) {
|
||||
break;
|
||||
}
|
||||
else if (t.compareTo(currentParent.data) > 0) {
|
||||
currentParent = current;
|
||||
current = current.rightChild;
|
||||
} else {
|
||||
currentParent = current;
|
||||
current = current.leftChild;
|
||||
}
|
||||
}
|
||||
if (current == null) {
|
||||
return false;
|
||||
}
|
||||
if (current.data.compareTo(currentParent.data) <= 0) {
|
||||
currentParent.leftChild = null;
|
||||
} else {
|
||||
currentParent.rightChild = null;
|
||||
}
|
||||
// case: single child
|
||||
if (current.leftChild == null || current.rightChild == null) {
|
||||
// if the current is the right child of its parent
|
||||
if (current.data.compareTo(t) > 0) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
// case: two children
|
||||
else {
|
||||
// take a left
|
||||
Node<T> p = current;
|
||||
p = current.leftChild;
|
||||
Node<T> pTrailParent = p;
|
||||
Node<T> pTrail = p;
|
||||
while (p != null) { // keep going right
|
||||
pTrailParent = pTrail;
|
||||
pTrail = p;
|
||||
p = p.rightChild;
|
||||
}
|
||||
// swap the data of pTrail with the current
|
||||
current.data = pTrail.data;
|
||||
if (pTrail == pTrailParent) {
|
||||
pTrailParent.leftChild = pTrail.leftChild;
|
||||
} else {
|
||||
pTrailParent.rightChild = pTrail.leftChild;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ListIterator<T> listIterator(){
|
||||
ListIterator it = new ListIterator<T>();
|
||||
return null;
|
||||
}
|
||||
public void breathFirst() {
|
||||
Stack<Node<T>> stack = new Stack();
|
||||
Node<T> p = root;
|
||||
System.out.println(p.data + " ");
|
||||
stack.push(p.rightChild);
|
||||
|
||||
while (stack.empty() == false) {
|
||||
// go to the left
|
||||
p = p.leftChild;
|
||||
if (p != null) {
|
||||
System.out.println(p.data);
|
||||
}
|
||||
Node<T> rightChild = stack.pop();
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
TreeASDV tree = new TreeASDV();
|
||||
tree.insert(100);
|
||||
tree.insert(80);
|
||||
tree.insert(90);
|
||||
tree.insert(95);
|
||||
tree.insert(93);
|
||||
tree.insert(70);
|
||||
tree.inOrder();
|
||||
tree.remove(100);
|
||||
System.out.println();
|
||||
tree.inOrder();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user