Correzioni firme delle eccezioni

This commit is contained in:
Fabio Scotto di Santolo
2020-06-10 19:48:07 +02:00
parent be1640f72f
commit b113477fac
15 changed files with 48 additions and 48 deletions

View File

@@ -2,10 +2,10 @@ package org.fscotto.asd.adt;
public interface AdaptablePriorityQueue<K extends Comparable<K>, V> extends PriorityQueue<K, V> { public interface AdaptablePriorityQueue<K extends Comparable<K>, V> extends PriorityQueue<K, V> {
public void remove(Entry<K, V> entry) throws IllegalArgumentException; public void remove(Entry<K, V> entry);
public void replaceKey(Entry<K, V> entry, K key) throws IllegalArgumentException; public void replaceKey(Entry<K, V> entry, K key);
public void replaceValue(Entry<K, V> entry, V value) throws IllegalArgumentException; public void replaceValue(Entry<K, V> entry, V value);
} }

View File

@@ -4,12 +4,12 @@ package org.fscotto.asd.adt;
public interface BinaryTree<E> extends Tree<E> { public interface BinaryTree<E> extends Tree<E> {
/** Restituisce la posizione del figlio sinistro di position (o null se non esiste). */ /** Restituisce la posizione del figlio sinistro di position (o null se non esiste). */
Position<E> left(Position<E> position) throws IllegalArgumentException; Position<E> left(Position<E> position);
/** Restituisce la posizione del figlio destro di position (o null se non esiste). */ /** Restituisce la posizione del figlio destro di position (o null se non esiste). */
Position<E> right(Position<E> position) throws IllegalArgumentException; Position<E> right(Position<E> position);
/** Restituisce la posizione del fratello di position (o null se non esiste). */ /** Restituisce la posizione del fratello di position (o null se non esiste). */
Position<E> sibling(Position<E> position) throws IllegalArgumentException; Position<E> sibling(Position<E> position);
} }

View File

@@ -10,15 +10,15 @@ public interface List<E> extends Iterable<E> {
boolean isEmpty(); boolean isEmpty();
/** Restituisce l'elemento corristondente all'indice i, senza eliminarlo. */ /** Restituisce l'elemento corristondente all'indice i, senza eliminarlo. */
E get(int i) throws IndexOutOfBoundsException; E get(int i);
/** Sostituisce con e l'elemento di indice i; restituisce l'elemento sostituito. */ /** Sostituisce con e l'elemento di indice i; restituisce l'elemento sostituito. */
E set(int i, E e) throws IndexOutOfBoundsException; E set(int i, E e);
/** Inserisce e come elemento di indice i, spostando gli elementi successivi. */ /** Inserisce e come elemento di indice i, spostando gli elementi successivi. */
void add(int i, E e) throws IndexOutOfBoundsException; void add(int i, E e);
/** Rimuove e restituisce l'elemento di indice i, spostando i successivi. */ /** Rimuove e restituisce l'elemento di indice i, spostando i successivi. */
E remove(int i) throws IndexOutOfBoundsException; E remove(int i);
} }

View File

@@ -8,6 +8,6 @@ public interface Position<E> {
* @return l'elemento memorizzato * @return l'elemento memorizzato
* @throws IllegalStateException se la posizione non è più valida * @throws IllegalStateException se la posizione non è più valida
*/ */
E getElement() throws IllegalStateException; E getElement();
} }

View File

@@ -16,10 +16,10 @@ public interface PositionalList<E> extends Iterable<E> {
Position<E> last(); Position<E> last();
/** Restituisce la Position che precede p (o null, se p è la prima). */ /** Restituisce la Position che precede p (o null, se p è la prima). */
Position<E> before(Position<E> position) throws IllegalArgumentException; Position<E> before(Position<E> position);
/** Restituisce la Position che segue p (o null, se p è l'ultima). */ /** Restituisce la Position che segue p (o null, se p è l'ultima). */
Position<E> after(Position<E> position) throws IllegalArgumentException; Position<E> after(Position<E> position);
/** Inserisce l'elemento e all'inizio della lista; ne restituisce la posizione. */ /** Inserisce l'elemento e all'inizio della lista; ne restituisce la posizione. */
Position<E> addFirst(E element); Position<E> addFirst(E element);
@@ -28,16 +28,16 @@ public interface PositionalList<E> extends Iterable<E> {
Position<E> addLast(E element); Position<E> addLast(E element);
/** Inserisce l'elemento e prima della Position p; ne restituisce la posizione. */ /** Inserisce l'elemento e prima della Position p; ne restituisce la posizione. */
Position<E> addBefore(Position<E> position, E element) throws IllegalArgumentException; Position<E> addBefore(Position<E> position, E element);
/** Inserisce l'elemento e dopo la Position p; ne restituisce la posizione. */ /** Inserisce l'elemento e dopo la Position p; ne restituisce la posizione. */
Position<E> addAfter(Position<E> position, E element) throws IllegalArgumentException; Position<E> addAfter(Position<E> position, E element);
/** Sostituisce l'elemento nella Position p; restituisce l'elemento sostituito. */ /** Sostituisce l'elemento nella Position p; restituisce l'elemento sostituito. */
E set(Position<E> position, E element) throws IllegalArgumentException; E set(Position<E> position, E element);
/** Elimina e restituisce l'elemento nella Position p; (poi p non è più valida). */ /** Elimina e restituisce l'elemento nella Position p; (poi p non è più valida). */
E remove(Position<E> position) throws IllegalArgumentException; E remove(Position<E> position);
/** Restituisce una rappresentazione iterabile delle posizioni dela lista. */ /** Restituisce una rappresentazione iterabile delle posizioni dela lista. */
public Iterable<Position<E>> positions(); public Iterable<Position<E>> positions();

View File

@@ -14,7 +14,7 @@ public interface PriorityQueue<K extends Comparable<K>, V> {
boolean isEmpty(); boolean isEmpty();
Entry<K, V> insert(K key, V value) throws IllegalArgumentException; Entry<K, V> insert(K key, V value);
Entry<K, V> min(); Entry<K, V> min();

View File

@@ -7,22 +7,22 @@ public interface Tree<E> extends Iterable<E> {
Position<E> root(); Position<E> root();
/** Restituisce la posizione del parent del nodo alla posizione position. */ /** Restituisce la posizione del parent del nodo alla posizione position. */
Position<E> parent(Position<E> position) throws IllegalArgumentException; Position<E> parent(Position<E> position);
/** Restituisce una struttura iterabile dei figli del nodo alla posizione position. */ /** Restituisce una struttura iterabile dei figli del nodo alla posizione position. */
Iterable<Position<E>> children(Position<E> position) throws IllegalArgumentException; Iterable<Position<E>> children(Position<E> position);
/** Restituisce il numero di figli del nodo alla posizione position. */ /** Restituisce il numero di figli del nodo alla posizione position. */
int numChildren(Position<E> position) throws IllegalArgumentException; int numChildren(Position<E> position);
/** Restituisce true se e solo se il nodo alla posizione position non è foglia. */ /** Restituisce true se e solo se il nodo alla posizione position non è foglia. */
boolean isInternal(Position<E> position) throws IllegalArgumentException; boolean isInternal(Position<E> position);
/** Restituisce true se e solo se il nodo alla posizione position è foglia. */ /** Restituisce true se e solo se il nodo alla posizione position è foglia. */
boolean isExternal(Position<E> position) throws IllegalArgumentException; boolean isExternal(Position<E> position);
/** Restituisce true se e solo se il nodo alla posizione position è la radice. */ /** Restituisce true se e solo se il nodo alla posizione position è la radice. */
boolean isRoot(Position<E> position) throws IllegalArgumentException; boolean isRoot(Position<E> position);
/** Restituisce il numero di elementi presenti nella struttura. */ /** Restituisce il numero di elementi presenti nella struttura. */
int size(); int size();

View File

@@ -49,7 +49,7 @@ public class ArrayList<E> implements List<E> {
* senza eliminarlo. * senza eliminarlo.
*/ */
@Override @Override
public E get(int i) throws IndexOutOfBoundsException { public E get(int i) {
checkIndex(i, size); checkIndex(i, size);
return data[i]; return data[i];
} }
@@ -59,7 +59,7 @@ public class ArrayList<E> implements List<E> {
* restituisce l'elemento sostituito. * restituisce l'elemento sostituito.
*/ */
@Override @Override
public E set(int i, E e) throws IndexOutOfBoundsException { public E set(int i, E e) {
checkIndex(i, size); checkIndex(i, size);
E tmp = data[i]; E tmp = data[i];
data[i] = e; data[i] = e;
@@ -71,7 +71,7 @@ public class ArrayList<E> implements List<E> {
* spostando gli elementi successivi. * spostando gli elementi successivi.
*/ */
@Override @Override
public void add(int i, E e) throws IndexOutOfBoundsException { public void add(int i, E e) {
checkIndex(i, size + 1); checkIndex(i, size + 1);
if(size == data.length) resize(2 * data.length); if(size == data.length) resize(2 * data.length);
for(int k = size - 1; k >= i; --k) data[k + 1] = data[k]; for(int k = size - 1; k >= i; --k) data[k + 1] = data[k];
@@ -84,7 +84,7 @@ public class ArrayList<E> implements List<E> {
* spostando i successivi. * spostando i successivi.
*/ */
@Override @Override
public E remove(int i) throws IndexOutOfBoundsException { public E remove(int i) {
checkIndex(i, size); checkIndex(i, size);
E tmp = data[i]; E tmp = data[i];
for(int k = i; k <= size-1; ++k) data[k] = data[k + 1]; for(int k = i; k <= size-1; ++k) data[k] = data[k + 1];

View File

@@ -41,7 +41,7 @@ public class LinkedPositionalList<E> implements PositionalList<E> {
} }
@Override @Override
public E getElement() throws IllegalStateException { public E getElement() {
if(next == null) throw new IllegalStateException("Position no longer valid"); if(next == null) throw new IllegalStateException("Position no longer valid");
return element; return element;
} }
@@ -119,7 +119,7 @@ public class LinkedPositionalList<E> implements PositionalList<E> {
* Restituisce la Position che precede p (o null, se p è la prima). * Restituisce la Position che precede p (o null, se p è la prima).
*/ */
@Override @Override
public Position<E> before(Position<E> position) throws IllegalArgumentException { public Position<E> before(Position<E> position) {
Node<E> node = validate(position); Node<E> node = validate(position);
return position(node.getPrev()); return position(node.getPrev());
} }
@@ -128,7 +128,7 @@ public class LinkedPositionalList<E> implements PositionalList<E> {
* Restituisce la Posizione che segue p (o null, se p è l'ultima). * Restituisce la Posizione che segue p (o null, se p è l'ultima).
*/ */
@Override @Override
public Position<E> after(Position<E> position) throws IllegalArgumentException { public Position<E> after(Position<E> position) {
Node<E> node = validate(position); Node<E> node = validate(position);
return position(node.getNext()); return position(node.getNext());
} }
@@ -173,7 +173,7 @@ public class LinkedPositionalList<E> implements PositionalList<E> {
* ne restituisce la posizione. * ne restituisce la posizione.
*/ */
@Override @Override
public Position<E> addBefore(Position<E> position, E element) throws IllegalArgumentException { public Position<E> addBefore(Position<E> position, E element) {
Node<E> node = validate(position); Node<E> node = validate(position);
return addBeetween(element, node.getPrev(), node); return addBeetween(element, node.getPrev(), node);
} }
@@ -183,7 +183,7 @@ public class LinkedPositionalList<E> implements PositionalList<E> {
* ne restituisce la posizione. * ne restituisce la posizione.
*/ */
@Override @Override
public Position<E> addAfter(Position<E> position, E element) throws IllegalArgumentException { public Position<E> addAfter(Position<E> position, E element) {
Node<E> node = validate(position); Node<E> node = validate(position);
return addBeetween(element, node, node.getNext()); return addBeetween(element, node, node.getNext());
} }
@@ -193,7 +193,7 @@ public class LinkedPositionalList<E> implements PositionalList<E> {
* restituisce l'elemento sostituito. * restituisce l'elemento sostituito.
*/ */
@Override @Override
public E set(Position<E> position, E element) throws IllegalArgumentException { public E set(Position<E> position, E element) {
Node<E> node = validate(position); Node<E> node = validate(position);
E answer = node.getElement(); E answer = node.getElement();
node.setElement(element); node.setElement(element);
@@ -204,7 +204,7 @@ public class LinkedPositionalList<E> implements PositionalList<E> {
* Elimina e restituisce l'elemento nella Position p (poi p non è più valida). * Elimina e restituisce l'elemento nella Position p (poi p non è più valida).
*/ */
@Override @Override
public E remove(Position<E> position) throws IllegalArgumentException { public E remove(Position<E> position) {
Node<E> node = validate(position); Node<E> node = validate(position);
Node<E> predecessor = node.getPrev(); Node<E> predecessor = node.getPrev();
Node<E> successor = node.getNext(); Node<E> successor = node.getNext();

View File

@@ -73,7 +73,7 @@ public class HeapAdaptablePriorityQueue<K extends Comparable<K>, V> extends Heap
/** Inserisce una coppia chiave-valore e restituisce la voce creata. */ /** Inserisce una coppia chiave-valore e restituisce la voce creata. */
@Override @Override
public Entry<K, V> insert(K key, V value) throws IllegalArgumentException { public Entry<K, V> insert(K key, V value) {
checkKey(key); checkKey(key);
Entry<K, V> newest = new AdaptablePQEntry<K, V>(key, value, heap.size()); Entry<K, V> newest = new AdaptablePQEntry<K, V>(key, value, heap.size());
heap.add(newest); heap.add(newest);
@@ -84,7 +84,7 @@ public class HeapAdaptablePriorityQueue<K extends Comparable<K>, V> extends Heap
/** Elimina dalla coda prioritaria la voce ricevuta. */ /** Elimina dalla coda prioritaria la voce ricevuta. */
@Override @Override
public void remove(Entry<K, V> entry) throws IllegalArgumentException { public void remove(Entry<K, V> entry) {
AdaptablePQEntry<K, V> locator = validate(entry); AdaptablePQEntry<K, V> locator = validate(entry);
int j = locator.getIndex(); int j = locator.getIndex();
if (j == heap.size() - 1) // la voce si trova nell'ultima posizione if (j == heap.size() - 1) // la voce si trova nell'ultima posizione
@@ -98,7 +98,7 @@ public class HeapAdaptablePriorityQueue<K extends Comparable<K>, V> extends Heap
/** Sostituisce la chiave di una voce. */ /** Sostituisce la chiave di una voce. */
@Override @Override
public void replaceKey(Entry<K, V> entry, K key) throws IllegalArgumentException { public void replaceKey(Entry<K, V> entry, K key) {
AdaptablePQEntry<K, V> locator = validate(entry); AdaptablePQEntry<K, V> locator = validate(entry);
checkKey(key); checkKey(key);
locator.setKey(key); locator.setKey(key);
@@ -107,7 +107,7 @@ public class HeapAdaptablePriorityQueue<K extends Comparable<K>, V> extends Heap
/** Sostituisce il valore di una voce. */ /** Sostituisce il valore di una voce. */
@Override @Override
public void replaceValue(Entry<K, V> entry, V value) throws IllegalArgumentException { public void replaceValue(Entry<K, V> entry, V value) {
AdaptablePQEntry<K, V> locator = validate(entry); AdaptablePQEntry<K, V> locator = validate(entry);
locator.setValue(value); locator.setValue(value);
} }

View File

@@ -98,7 +98,7 @@ public class HeapPriorityQueue<K extends Comparable<K>, V> extends AbstractPrior
/** Inserisce una coppia chiave-valore e restituisce la voce creata. */ /** Inserisce una coppia chiave-valore e restituisce la voce creata. */
@Override @Override
public Entry<K, V> insert(K key, V value) throws IllegalArgumentException { public Entry<K, V> insert(K key, V value) {
checkKey(key); // metodo ausiliario di verifica (può lanciare eccezione) checkKey(key); // metodo ausiliario di verifica (può lanciare eccezione)
Entry<K, V> newest = new PQEntry<>(key, value); Entry<K, V> newest = new PQEntry<>(key, value);
heap.add(newest); // aggiunge alla fine della lista heap.add(newest); // aggiunge alla fine della lista

View File

@@ -28,7 +28,7 @@ public class SortedPriorityQueue<K extends Comparable<K>, V> extends AbstractPri
@Override @Override
public Entry<K, V> insert(K key, V value) throws IllegalArgumentException { public Entry<K, V> insert(K key, V value) {
checkKey(key); // metodo ausiliario di verifica (può lanciare eccezione) checkKey(key); // metodo ausiliario di verifica (può lanciare eccezione)
Entry<K, V> newest = new PQEntry<>(key, value); Entry<K, V> newest = new PQEntry<>(key, value);
Position<Entry<K, V>> walk = list.last(); Position<Entry<K, V>> walk = list.last();

View File

@@ -40,7 +40,7 @@ public class UnsortedPriorityQueue<K extends Comparable<K>, V> extends AbstractP
/** Inserisce una coppia chiave-valore e restituisce la voce creata. */ /** Inserisce una coppia chiave-valore e restituisce la voce creata. */
@Override @Override
public Entry<K, V> insert(K key, V value) throws IllegalArgumentException { public Entry<K, V> insert(K key, V value) {
checkKey(key); // metodo ausiliario di verifica (può lanciare eccezione) checkKey(key); // metodo ausiliario di verifica (può lanciare eccezione)
Entry<K, V> newest = new PQEntry<>(key, value); Entry<K, V> newest = new PQEntry<>(key, value);
list.addLast(newest); list.addLast(newest);

View File

@@ -12,17 +12,17 @@ import org.fscotto.asd.adt.Queue;
public abstract class AbstractTree<E> implements Tree<E> { public abstract class AbstractTree<E> implements Tree<E> {
@Override @Override
public boolean isInternal(Position<E> position) throws IllegalArgumentException { public boolean isInternal(Position<E> position) {
return numChildren(position) > 0; return numChildren(position) > 0;
} }
@Override @Override
public boolean isExternal(Position<E> position) throws IllegalArgumentException { public boolean isExternal(Position<E> position) {
return numChildren(position) == 0; return numChildren(position) == 0;
} }
@Override @Override
public boolean isRoot(Position<E> position) throws IllegalArgumentException { public boolean isRoot(Position<E> position) {
return position == root(); return position == root();
} }

View File

@@ -79,7 +79,7 @@ public class LinkedBinaryTree<E> extends AbstractBinaryTree<E> {
* @return figlio sinistro o null se non c'è * @return figlio sinistro o null se non c'è
*/ */
@Override @Override
public Position<E> left(Position<E> position) throws IllegalArgumentException { public Position<E> left(Position<E> position) {
Node<E> node = validate(position); Node<E> node = validate(position);
return node.getLeft(); return node.getLeft();
} }
@@ -91,7 +91,7 @@ public class LinkedBinaryTree<E> extends AbstractBinaryTree<E> {
* @return figlio destro o null se non c'è * @return figlio destro o null se non c'è
*/ */
@Override @Override
public Position<E> right(Position<E> position) throws IllegalArgumentException { public Position<E> right(Position<E> position) {
Node<E> node = validate(position); Node<E> node = validate(position);
return node.getRight(); return node.getRight();
} }
@@ -112,7 +112,7 @@ public class LinkedBinaryTree<E> extends AbstractBinaryTree<E> {
* @return posizione di position o null se è radice * @return posizione di position o null se è radice
*/ */
@Override @Override
public Position<E> parent(Position<E> position) throws IllegalArgumentException { public Position<E> parent(Position<E> position) {
Node<E> node = validate(position); Node<E> node = validate(position);
return node.getParent(); return node.getParent();
} }