Допустим, у нас есть класс
Vector2D, типа такого:public static final class Vector2D {
private double x;
private double y;
public Vector2D( final double x,
final double y ) {
this.x = x;
this.y = y;
}
public Vector2D add( final Vector2D other ) {
return new Vector2D(
x + other.x,
y + other.y
);
}
public void addAccumulate( final Vector2D other ) {
x = x + other.x;
y = y + other.y;
}
public double dot( final Vector2D other ) {
return x * other.x + y * other.y;
}
public double length() {
return Math.sqrt( this.dot( this ) );
}
}
(Конкретные детали не важны, нужен класс без сложной логики и коллекций внутри)