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

Last change on this file since 1748 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
RevLine 
[1734]1/*
2 *
3 */
[1702]4package de.ugoe.cs.autoquest.tasktrees.alignment.matrix;
5
6import java.util.ArrayList;
7
[1734]8// TODO: Auto-generated Javadoc
[1702]9//Must be initialized!
[1734]10/**
11 * The Class DynamicTriangleMatrix.
12 */
[1702]13public class DynamicTriangleMatrix implements ITriangleMatrix {
[1733]14
[1734]15        /** The matrix. */
[1733]16        private final ArrayList<Float> matrix;
[1734]17       
18        /** The size. */
[1702]19        protected int size;
[1734]20       
21        /** The initalization value. */
[1702]22        private float initalizationValue;
23
[1734]24        /**
25         * Instantiates a new dynamic triangle matrix.
26         *
27         * @param size the size
28         */
[1702]29        public DynamicTriangleMatrix(int size) {
30                this.size = size;
31                matrix = new ArrayList<Float>();
[1733]32                matrix.ensureCapacity(size * (size + (1 / 2)));
[1702]33        }
34
[1733]35        /*
36         * (non-Javadoc)
37         *
38         * @see
39         * de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ITriangleMatrix#get(int,
40         * int)
[1702]41         */
42        @Override
43        public float get(int first, int second) {
[1733]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
[1702]49        }
[1733]50
51        // Increases the size
52        /*
53         * (non-Javadoc)
54         *
55         * @see
56         * de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ITriangleMatrix#increaseSize
57         * (int)
[1702]58         */
59        @Override
[1733]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                }
[1702]67        }
68
[1733]69        /*
70         * (non-Javadoc)
71         *
72         * @see
73         * de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ITriangleMatrix#initialize
74         * (float)
[1702]75         */
76        @Override
77        public void initialize(float value) {
78                this.initalizationValue = value;
79                matrix.clear();
[1733]80                for (int i = 0; i < ((this.size * (this.size + 1)) / 2); i++) {
[1702]81                        matrix.add(value);
82                }
83        }
[1733]84
85        /*
86         * (non-Javadoc)
87         *
88         * @see
89         * de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ITriangleMatrix#set(int,
90         * int, float)
[1702]91         */
92        @Override
[1733]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
[1734]100        /* (non-Javadoc)
101         * @see de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ITriangleMatrix#size()
102         */
[1733]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
[1702]116        public String toString() {
117                String result = "";
118                for (int i = 0; i < size; i++) {
[1733]119                        for (int j = 0; j < size; j++) {
120                                if (i < j) {
121                                        if (Float.isInfinite(this.get(i, j))) {
[1702]122                                                result = result + " -------";
[1733]123                                        } else {
124                                                result = result
125                                                                + String.format("%+8.2f", this.get(i, j));
[1702]126                                        }
[1733]127                                } else {
[1702]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.