PIbd - 21 Bakalskaya E.D. LabWork7 Hard #10
17
ProjectElectricLocomotive/LocoStorageOverflowException.java
Normal file
17
ProjectElectricLocomotive/LocoStorageOverflowException.java
Normal file
@ -0,0 +1,17 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
public class LocoStorageOverflowException extends RuntimeException{
|
||||
public LocoStorageOverflowException(Throwable ex){
|
||||
super(ex);
|
||||
}
|
||||
public LocoStorageOverflowException(int count){
|
||||
super("В наборе превышено допустимое количество локомотивов:" + count);
|
||||
}
|
||||
public LocoStorageOverflowException(String message){
|
||||
super(message);
|
||||
}
|
||||
public LocoStorageOverflowException(String message, Throwable ex){
|
||||
super(message, ex);
|
||||
}
|
||||
|
||||
}
|
@ -25,8 +25,10 @@ public class SetGeneric<T extends DrawingLocomotive>{
|
||||
|
||||
public int Insert(T loco, int position)
|
||||
{
|
||||
if(position < 0 || position > maxCount)
|
||||
if(position < 0)
|
||||
return -1;
|
||||
if(position >= maxCount)
|
||||
throw new LocoStorageOverflowException(maxCount);
|
||||
else
|
||||
{
|
||||
_places.add(position, loco);
|
||||
@ -41,6 +43,8 @@ public class SetGeneric<T extends DrawingLocomotive>{
|
||||
else
|
||||
{
|
||||
T plane = _places.get(position);
|
||||
if(plane == null)
|
||||
throw new LocoNotFoundException(position);
|
||||
_places.set(position, null);
|
||||
return plane;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user