Changeset 1733 for branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/StaticTriangleMatrix.java
- Timestamp:
- 09/05/14 19:33:12 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/StaticTriangleMatrix.java
r1707 r1733 3 3 import java.io.Serializable; 4 4 5 public class StaticTriangleMatrix implements ITriangleMatrix, Serializable {6 5 public class StaticTriangleMatrix implements ITriangleMatrix, Serializable { 6 7 7 /** 8 8 * 9 9 */ 10 10 private static final long serialVersionUID = 7599542322424894866L; 11 private f loat[] matrix;11 private final float[] matrix; 12 12 protected int size; 13 14 13 15 14 public StaticTriangleMatrix(int size) { 16 15 this.size = size; 17 matrix = new float [size*(size+1)/2]; 18 } 19 20 public float get(int first, int second) { 21 int row = Math.min(first, second); 22 int col = Math.max(first, second); 23 return matrix[row*size-(row*(row+1)/2 - (size-col))]; 24 25 } 26 27 public void set(int first, int second, float value) { 28 int row = Math.min(first, second); 29 int col = Math.max(first, second); 30 matrix[row*size-(row*(row+1)/2 - (size-col))] = value; 16 matrix = new float[(size * (size + 1)) / 2]; 31 17 } 32 18 19 @Override 20 public float get(int first, int second) { 21 final int row = Math.min(first, second); 22 final int col = Math.max(first, second); 23 return matrix[(row * size) - (((row * (row + 1)) / 2) - (size - col))]; 24 25 } 26 27 @Override 28 public void increaseSize(int count) throws Exception { 29 throw new Exception( 30 "Cannot call this function on this implementation of ITriangle Matrix"); 31 32 } 33 34 @Override 33 35 public void initialize(float value) { 34 for (int i =0; i < matrix.length; i++) {36 for (int i = 0; i < matrix.length; i++) { 35 37 matrix[i] = value; 36 38 } 37 39 } 38 39 40 40 41 @Override 42 public void set(int first, int second, float value) { 43 final int row = Math.min(first, second); 44 final int col = Math.max(first, second); 45 matrix[(row * size) - (((row * (row + 1)) / 2) - (size - col))] = value; 46 } 47 48 @Override 49 public int size() { 50 return size; 51 } 52 53 @Override 41 54 public String toString() { 42 55 String result = ""; 43 56 for (int i = 0; i < size; i++) { 44 for (int j = 0; j< size; j++) {45 if (i<j) {46 if (Float.isInfinite(this.get(i,j))) {57 for (int j = 0; j < size; j++) { 58 if (i < j) { 59 if (Float.isInfinite(this.get(i, j))) { 47 60 result = result + " -------"; 61 } else { 62 result = result 63 + String.format("%+8.2f", this.get(i, j)); 48 64 } 49 else { 50 result = result + String.format("%+8.2f",this.get(i,j)); 51 } 52 } 53 else { 65 } else { 54 66 result = result + (" "); 55 67 } … … 59 71 return result; 60 72 } 61 62 @Override63 public void increaseSize(int count) throws Exception {64 throw new Exception("Cannot call this function on this implementation of ITriangle Matrix");65 66 }67 68 @Override69 public int size() {70 return size;71 }72 73 }
Note: See TracChangeset
for help on using the changeset viewer.