riordinato alcuni package e creato una prima implementazione di set e mergetemplate
This commit is contained in:
140
set/OrderedListSet.java
Normal file
140
set/OrderedListSet.java
Normal file
@@ -0,0 +1,140 @@
|
||||
package set;
|
||||
|
||||
import position.NodePositionList;
|
||||
import position.PositionList;
|
||||
import utility.DefaultComparator;
|
||||
import utility.merge.MergeTemplate;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Created with xgiovio.macbookair.
|
||||
* User: xgiovio
|
||||
* Date: 14/05/14
|
||||
* Time: 14:23
|
||||
*/
|
||||
|
||||
public class OrderedListSet <E> implements Set<E> {
|
||||
private Comparator<E> c;
|
||||
private PositionList<E> L;
|
||||
|
||||
|
||||
|
||||
OrderedListSet() {
|
||||
L = new NodePositionList<E>();
|
||||
c = new DefaultComparator();
|
||||
}
|
||||
|
||||
OrderedListSet(Comparator<E> in_c) {
|
||||
L = new NodePositionList<E>();
|
||||
c = in_c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return L.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return L.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Set<E> union(Set<E> B) {
|
||||
new MergeUnion<E>(this.L, ,c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> intersect(Set<E> B) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> subtract(Set<E> B) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////// inner class override methods from merge template /////
|
||||
|
||||
protected class MergeUnion<E> extends MergeTemplate<E>{
|
||||
|
||||
public MergeUnion (PositionList<E> A , PositionList<E> B, DefaultComparator<E> c){
|
||||
super(A,B,c);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void aIsLess(E a) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bIsLess(E b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bothAreEqual(E a, E b) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected class MergeIntersect<E> extends MergeTemplate<E>{
|
||||
|
||||
public MergeIntersect (PositionList<E> A , PositionList<E> B, DefaultComparator<E> c){
|
||||
super(A,B,c);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void aIsLess(E a) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bIsLess(E b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bothAreEqual(E a, E b) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected class MergeSubtract<E> extends MergeTemplate<E>{
|
||||
|
||||
public MergeSubtract (PositionList<E> A , PositionList<E> B, DefaultComparator<E> c){
|
||||
super(A,B,c);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void aIsLess(E a) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bIsLess(E b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bothAreEqual(E a, E b) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
25
set/Set.java
Normal file
25
set/Set.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package set;
|
||||
|
||||
/**
|
||||
* Created with xgiovio.macbookair.
|
||||
* User: xgiovio
|
||||
* Date: 14/05/14
|
||||
* Time: 14:18
|
||||
*/
|
||||
public interface Set<E> {
|
||||
// Restituisce il numero degli elementi nell’insieme
|
||||
public int size();
|
||||
|
||||
// Restituisce true se l’insieme è vuoto
|
||||
public boolean isEmpty();
|
||||
|
||||
// Rimpiazza this con l’unione di this e B
|
||||
public Set<E> union(Set<E> B) ;
|
||||
|
||||
// Rimpiazza this con l’intersezione di this e B
|
||||
public Set<E> intersect(Set<E> B) ;
|
||||
|
||||
// Rimpiazza this con la differenza di this e B
|
||||
public Set <E>subtract(Set <E> B) ;
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package euler_tour;
|
||||
package utility.euler_tour;
|
||||
|
||||
import tree.binarytree.*;
|
||||
import position.Position;
|
||||
@@ -1,4 +1,4 @@
|
||||
package euler_tour.expressions;
|
||||
package utility.euler_tour.expressions;
|
||||
|
||||
/**
|
||||
* Created with MONSTER.
|
||||
@@ -1,6 +1,6 @@
|
||||
package euler_tour.expressions;
|
||||
package utility.euler_tour.expressions;
|
||||
|
||||
import euler_tour.EulerTour;
|
||||
import utility.euler_tour.EulerTour;
|
||||
import position.Position;
|
||||
import tree.binarytree.BinaryTree;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package euler_tour.expressions;
|
||||
package utility.euler_tour.expressions;
|
||||
|
||||
/**
|
||||
* Created with MONSTER.
|
||||
@@ -1,4 +1,4 @@
|
||||
package euler_tour.expressions;
|
||||
package utility.euler_tour.expressions;
|
||||
|
||||
/**
|
||||
* Created with MONSTER.
|
||||
@@ -1,4 +1,4 @@
|
||||
package euler_tour.expressions;
|
||||
package utility.euler_tour.expressions;
|
||||
|
||||
/**
|
||||
* Created with MONSTER.
|
||||
@@ -1,6 +1,6 @@
|
||||
package euler_tour.expressions;
|
||||
package utility.euler_tour.expressions;
|
||||
|
||||
import euler_tour.EulerTour;
|
||||
import utility.euler_tour.EulerTour;
|
||||
import position.Position;
|
||||
import tree.binarytree.BinaryTree;
|
||||
|
||||
80
utility/merge/MergeTemplate.java
Normal file
80
utility/merge/MergeTemplate.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package utility.merge;
|
||||
|
||||
import exceptions.BoundaryViolationException;
|
||||
import exceptions.EmptyListException;
|
||||
import exceptions.InvalidPositionException;
|
||||
import position.NodePositionList;
|
||||
import position.Position;
|
||||
import position.PositionList;
|
||||
import utility.DefaultComparator;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Created with xgiovio.macbookair.
|
||||
* User: xgiovio
|
||||
* Date: 14/05/14
|
||||
* Time: 14:48
|
||||
*/
|
||||
public abstract class MergeTemplate<E> {
|
||||
|
||||
PositionList<E> s = new NodePositionList<E>();
|
||||
Comparator<E> c = null;
|
||||
|
||||
public MergeTemplate (PositionList<E> A, PositionList <E> B){
|
||||
this(A,B,new DefaultComparator<E>());
|
||||
}
|
||||
|
||||
public MergeTemplate (PositionList<E> A, PositionList <E> B, Comparator<E> in_c){
|
||||
|
||||
c = in_c;
|
||||
E a,b;
|
||||
Iterator<E> Ait, Bit;
|
||||
Ait = A.iterator();
|
||||
Bit = B.iterator();
|
||||
|
||||
while (!(Ait.hasNext()) && !(Bit.hasNext())) {
|
||||
|
||||
a = Ait.next();
|
||||
b= Bit.next();
|
||||
|
||||
if ( c.compare(a,b) < 0 )
|
||||
aIsLess(a);
|
||||
else if (c.compare(a,b) > 0)
|
||||
bIsLess(b);
|
||||
else // se b = a
|
||||
bothAreEqual(a, b);
|
||||
|
||||
}
|
||||
while (!(Ait.hasNext())) {
|
||||
a = Ait.next();
|
||||
aIsLess(a);
|
||||
}
|
||||
while (!(Bit.hasNext())) {
|
||||
b = Bit.next();
|
||||
bIsLess(b);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
abstract protected void aIsLess (E a);
|
||||
|
||||
abstract protected void bIsLess (E b);
|
||||
|
||||
abstract protected void bothAreEqual (E a, E b);
|
||||
|
||||
|
||||
public PositionList<E> getResult () {
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user