I have a simple code below:
import java.util.ArrayList;
public class BoidList extends ArrayList
{
synchronized public Boid GetBoid( int idx_ ) throws ArrayIndexOutOfBoundsException
{
if( idx_ < super.size() &&
idx_ >= 0 )
{
return (Boid) super.get(idx_);
}
else
{
throw new ArrayIndexOutOfBoundsException();
}
}
synchronized public void RemoveBoid( int idx_ ) throws ArrayIndexOutOfBoundsException
{
if( idx_ < super.size() &&
idx_ >= 0 )
{
super.remove(idx_);
}
else
{
throw new ArrayIndexOutOfBoundsException();
}
}
}
There's a lot of similarity between the 2 methods, yet they do two different things. Is it possible to refactor this?