Correzioni firme delle eccezioni
This commit is contained in:
@@ -2,10 +2,10 @@ package org.fscotto.asd.adt;
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ package org.fscotto.asd.adt;
|
||||
public interface BinaryTree<E> extends Tree<E> {
|
||||
|
||||
/** 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). */
|
||||
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). */
|
||||
Position<E> sibling(Position<E> position) throws IllegalArgumentException;
|
||||
Position<E> sibling(Position<E> position);
|
||||
|
||||
}
|
||||
|
||||
@@ -10,15 +10,15 @@ public interface List<E> extends Iterable<E> {
|
||||
boolean isEmpty();
|
||||
|
||||
/** 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. */
|
||||
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. */
|
||||
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. */
|
||||
E remove(int i) throws IndexOutOfBoundsException;
|
||||
E remove(int i);
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,6 @@ public interface Position<E> {
|
||||
* @return l'elemento memorizzato
|
||||
* @throws IllegalStateException se la posizione non è più valida
|
||||
*/
|
||||
E getElement() throws IllegalStateException;
|
||||
E getElement();
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ public interface PositionalList<E> extends Iterable<E> {
|
||||
Position<E> last();
|
||||
|
||||
/** 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). */
|
||||
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. */
|
||||
Position<E> addFirst(E element);
|
||||
@@ -28,16 +28,16 @@ public interface PositionalList<E> extends Iterable<E> {
|
||||
Position<E> addLast(E element);
|
||||
|
||||
/** 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. */
|
||||
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. */
|
||||
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). */
|
||||
E remove(Position<E> position) throws IllegalArgumentException;
|
||||
E remove(Position<E> position);
|
||||
|
||||
/** Restituisce una rappresentazione iterabile delle posizioni dela lista. */
|
||||
public Iterable<Position<E>> positions();
|
||||
|
||||
@@ -14,7 +14,7 @@ public interface PriorityQueue<K extends Comparable<K>, V> {
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
Entry<K, V> insert(K key, V value) throws IllegalArgumentException;
|
||||
Entry<K, V> insert(K key, V value);
|
||||
|
||||
Entry<K, V> min();
|
||||
|
||||
|
||||
@@ -7,22 +7,22 @@ public interface Tree<E> extends Iterable<E> {
|
||||
Position<E> root();
|
||||
|
||||
/** 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. */
|
||||
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. */
|
||||
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. */
|
||||
boolean isInternal(Position<E> position) throws IllegalArgumentException;
|
||||
boolean isInternal(Position<E> position);
|
||||
|
||||
/** 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. */
|
||||
boolean isRoot(Position<E> position) throws IllegalArgumentException;
|
||||
boolean isRoot(Position<E> position);
|
||||
|
||||
/** Restituisce il numero di elementi presenti nella struttura. */
|
||||
int size();
|
||||
|
||||
@@ -49,7 +49,7 @@ public class ArrayList<E> implements List<E> {
|
||||
* senza eliminarlo.
|
||||
*/
|
||||
@Override
|
||||
public E get(int i) throws IndexOutOfBoundsException {
|
||||
public E get(int i) {
|
||||
checkIndex(i, size);
|
||||
return data[i];
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class ArrayList<E> implements List<E> {
|
||||
* restituisce l'elemento sostituito.
|
||||
*/
|
||||
@Override
|
||||
public E set(int i, E e) throws IndexOutOfBoundsException {
|
||||
public E set(int i, E e) {
|
||||
checkIndex(i, size);
|
||||
E tmp = data[i];
|
||||
data[i] = e;
|
||||
@@ -71,7 +71,7 @@ public class ArrayList<E> implements List<E> {
|
||||
* spostando gli elementi successivi.
|
||||
*/
|
||||
@Override
|
||||
public void add(int i, E e) throws IndexOutOfBoundsException {
|
||||
public void add(int i, E e) {
|
||||
checkIndex(i, size + 1);
|
||||
if(size == data.length) resize(2 * data.length);
|
||||
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.
|
||||
*/
|
||||
@Override
|
||||
public E remove(int i) throws IndexOutOfBoundsException {
|
||||
public E remove(int i) {
|
||||
checkIndex(i, size);
|
||||
E tmp = data[i];
|
||||
for(int k = i; k <= size-1; ++k) data[k] = data[k + 1];
|
||||
|
||||
@@ -41,7 +41,7 @@ public class LinkedPositionalList<E> implements PositionalList<E> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public E getElement() throws IllegalStateException {
|
||||
public E getElement() {
|
||||
if(next == null) throw new IllegalStateException("Position no longer valid");
|
||||
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).
|
||||
*/
|
||||
@Override
|
||||
public Position<E> before(Position<E> position) throws IllegalArgumentException {
|
||||
public Position<E> before(Position<E> position) {
|
||||
Node<E> node = validate(position);
|
||||
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).
|
||||
*/
|
||||
@Override
|
||||
public Position<E> after(Position<E> position) throws IllegalArgumentException {
|
||||
public Position<E> after(Position<E> position) {
|
||||
Node<E> node = validate(position);
|
||||
return position(node.getNext());
|
||||
}
|
||||
@@ -173,7 +173,7 @@ public class LinkedPositionalList<E> implements PositionalList<E> {
|
||||
* ne restituisce la posizione.
|
||||
*/
|
||||
@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);
|
||||
return addBeetween(element, node.getPrev(), node);
|
||||
}
|
||||
@@ -183,7 +183,7 @@ public class LinkedPositionalList<E> implements PositionalList<E> {
|
||||
* ne restituisce la posizione.
|
||||
*/
|
||||
@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);
|
||||
return addBeetween(element, node, node.getNext());
|
||||
}
|
||||
@@ -193,7 +193,7 @@ public class LinkedPositionalList<E> implements PositionalList<E> {
|
||||
* restituisce l'elemento sostituito.
|
||||
*/
|
||||
@Override
|
||||
public E set(Position<E> position, E element) throws IllegalArgumentException {
|
||||
public E set(Position<E> position, E element) {
|
||||
Node<E> node = validate(position);
|
||||
E answer = node.getElement();
|
||||
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).
|
||||
*/
|
||||
@Override
|
||||
public E remove(Position<E> position) throws IllegalArgumentException {
|
||||
public E remove(Position<E> position) {
|
||||
Node<E> node = validate(position);
|
||||
Node<E> predecessor = node.getPrev();
|
||||
Node<E> successor = node.getNext();
|
||||
|
||||
@@ -73,7 +73,7 @@ public class HeapAdaptablePriorityQueue<K extends Comparable<K>, V> extends Heap
|
||||
|
||||
/** Inserisce una coppia chiave-valore e restituisce la voce creata. */
|
||||
@Override
|
||||
public Entry<K, V> insert(K key, V value) throws IllegalArgumentException {
|
||||
public Entry<K, V> insert(K key, V value) {
|
||||
checkKey(key);
|
||||
Entry<K, V> newest = new AdaptablePQEntry<K, V>(key, value, heap.size());
|
||||
heap.add(newest);
|
||||
@@ -84,7 +84,7 @@ public class HeapAdaptablePriorityQueue<K extends Comparable<K>, V> extends Heap
|
||||
/** Elimina dalla coda prioritaria la voce ricevuta. */
|
||||
|
||||
@Override
|
||||
public void remove(Entry<K, V> entry) throws IllegalArgumentException {
|
||||
public void remove(Entry<K, V> entry) {
|
||||
AdaptablePQEntry<K, V> locator = validate(entry);
|
||||
int j = locator.getIndex();
|
||||
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. */
|
||||
@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);
|
||||
checkKey(key);
|
||||
locator.setKey(key);
|
||||
@@ -107,7 +107,7 @@ public class HeapAdaptablePriorityQueue<K extends Comparable<K>, V> extends Heap
|
||||
|
||||
/** Sostituisce il valore di una voce. */
|
||||
@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);
|
||||
locator.setValue(value);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class HeapPriorityQueue<K extends Comparable<K>, V> extends AbstractPrior
|
||||
|
||||
/** Inserisce una coppia chiave-valore e restituisce la voce creata. */
|
||||
@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)
|
||||
Entry<K, V> newest = new PQEntry<>(key, value);
|
||||
heap.add(newest); // aggiunge alla fine della lista
|
||||
|
||||
@@ -28,7 +28,7 @@ public class SortedPriorityQueue<K extends Comparable<K>, V> extends AbstractPri
|
||||
|
||||
|
||||
@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)
|
||||
Entry<K, V> newest = new PQEntry<>(key, value);
|
||||
Position<Entry<K, V>> walk = list.last();
|
||||
|
||||
@@ -40,7 +40,7 @@ public class UnsortedPriorityQueue<K extends Comparable<K>, V> extends AbstractP
|
||||
|
||||
/** Inserisce una coppia chiave-valore e restituisce la voce creata. */
|
||||
@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)
|
||||
Entry<K, V> newest = new PQEntry<>(key, value);
|
||||
list.addLast(newest);
|
||||
|
||||
@@ -12,17 +12,17 @@ import org.fscotto.asd.adt.Queue;
|
||||
public abstract class AbstractTree<E> implements Tree<E> {
|
||||
|
||||
@Override
|
||||
public boolean isInternal(Position<E> position) throws IllegalArgumentException {
|
||||
public boolean isInternal(Position<E> position) {
|
||||
return numChildren(position) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExternal(Position<E> position) throws IllegalArgumentException {
|
||||
public boolean isExternal(Position<E> position) {
|
||||
return numChildren(position) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRoot(Position<E> position) throws IllegalArgumentException {
|
||||
public boolean isRoot(Position<E> position) {
|
||||
return position == root();
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ public class LinkedBinaryTree<E> extends AbstractBinaryTree<E> {
|
||||
* @return figlio sinistro o null se non c'è
|
||||
*/
|
||||
@Override
|
||||
public Position<E> left(Position<E> position) throws IllegalArgumentException {
|
||||
public Position<E> left(Position<E> position) {
|
||||
Node<E> node = validate(position);
|
||||
return node.getLeft();
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class LinkedBinaryTree<E> extends AbstractBinaryTree<E> {
|
||||
* @return figlio destro o null se non c'è
|
||||
*/
|
||||
@Override
|
||||
public Position<E> right(Position<E> position) throws IllegalArgumentException {
|
||||
public Position<E> right(Position<E> position) {
|
||||
Node<E> node = validate(position);
|
||||
return node.getRight();
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public class LinkedBinaryTree<E> extends AbstractBinaryTree<E> {
|
||||
* @return posizione di position o null se è radice
|
||||
*/
|
||||
@Override
|
||||
public Position<E> parent(Position<E> position) throws IllegalArgumentException {
|
||||
public Position<E> parent(Position<E> position) {
|
||||
Node<E> node = validate(position);
|
||||
return node.getParent();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user