source: branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/DynamicTriangleMatrix.java

Last change on this file was 1734, checked in by rkrimmel, 10 years ago

Added automatically created javadoc, still needs to be commented properly though

File size: 2.8 KB
Line 
1/*
2 *
3 */
4package de.ugoe.cs.autoquest.tasktrees.alignment.matrix;
5
6import java.util.ArrayList;
7
8// TODO: Auto-generated Javadoc
9//Must be initialized!
10/**
11 * The Class DynamicTriangleMatrix.
12 */
13public class DynamicTriangleMatrix implements ITriangleMatrix {
14
15        /** The matrix. */
16        private final ArrayList<Float> matrix;
17       
18        /** The size. */
19        protected int size;
20       
21        /** The initalization value. */
22        private float initalizationValue;
23
24        /**
25         * Instantiates a new dynamic triangle matrix.
26         *
27         * @param size the size
28         */
29        public DynamicTriangleMatrix(int size) {
30                this.size = size;
31                matrix = new ArrayList<Float>();
32                matrix.ensureCapacity(size * (size + (1 / 2)));
33        }
34
35        /*
36         * (non-Javadoc)
37         *
38         * @see
39         * de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ITriangleMatrix#get(int,
40         * int)
41         */
42        @Override
43        public float get(int first, int second) {
44                final int row = Math.min(first, second);
45                final int col = Math.max(first, second);
46                return matrix.get((row * size)
47                                - (((row * (row + 1)) / 2) - (size - col)));
48
49        }
50
51        // Increases the size
52        /*
53         * (non-Javadoc)
54         *
55         * @see
56         * de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ITriangleMatrix#increaseSize
57         * (int)
58         */
59        @Override
60        public void increaseSize(int count) {
61                final int oldsize = size;
62                this.size += count;
63                matrix.ensureCapacity(size * (size + (1 / 2)));
64                for (int i = 0; i < ((oldsize * count) + ((count * (count + 1)) / 2)); i++) {
65                        matrix.add(this.initalizationValue);
66                }
67        }
68
69        /*
70         * (non-Javadoc)
71         *
72         * @see
73         * de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ITriangleMatrix#initialize
74         * (float)
75         */
76        @Override
77        public void initialize(float value) {
78                this.initalizationValue = value;
79                matrix.clear();
80                for (int i = 0; i < ((this.size * (this.size + 1)) / 2); i++) {
81                        matrix.add(value);
82                }
83        }
84
85        /*
86         * (non-Javadoc)
87         *
88         * @see
89         * de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ITriangleMatrix#set(int,
90         * int, float)
91         */
92        @Override
93        public void set(int first, int second, float value) {
94                final int row = Math.min(first, second);
95                final int col = Math.max(first, second);
96                matrix.set((row * size) - (((row * (row + 1)) / 2) - (size - col)),
97                                value);
98        }
99
100        /* (non-Javadoc)
101         * @see de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ITriangleMatrix#size()
102         */
103        @Override
104        public int size() {
105                return size;
106        }
107
108        /*
109         * (non-Javadoc)
110         *
111         * @see
112         * de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ITriangleMatrix#toString
113         * ()
114         */
115        @Override
116        public String toString() {
117                String result = "";
118                for (int i = 0; i < size; i++) {
119                        for (int j = 0; j < size; j++) {
120                                if (i < j) {
121                                        if (Float.isInfinite(this.get(i, j))) {
122                                                result = result + " -------";
123                                        } else {
124                                                result = result
125                                                                + String.format("%+8.2f", this.get(i, j));
126                                        }
127                                } else {
128                                        result = result + ("        ");
129                                }
130                        }
131                        result = result + "\n";
132                }
133                return result;
134        }
135}
Note: See TracBrowser for help on using the repository browser.