package de.ugoe.cs.autoquest.tasktrees.alignment.matrix; import java.io.Serializable; public class StaticTriangleMatrix implements ITriangleMatrix,Serializable { /** * */ private static final long serialVersionUID = 7599542322424894866L; private float[] matrix; protected int size; public StaticTriangleMatrix(int size) { this.size = size; matrix = new float [size*(size+1)/2]; } public float get(int first, int second) { int row = Math.min(first, second); int col = Math.max(first, second); return matrix[row*size-(row*(row+1)/2 - (size-col))]; } public void set(int first, int second, float value) { int row = Math.min(first, second); int col = Math.max(first, second); matrix[row*size-(row*(row+1)/2 - (size-col))] = value; } public void initialize(float value) { for (int i=0; i < matrix.length; i++) { matrix[i] = value; } } public String toString() { String result = ""; for (int i = 0; i < size; i++) { for(int j = 0; j< size; j++) { if(i