Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
VectorIAsSparseVector |
|
| 0.0;0 | ||||
VectorIAsSparseVector$VectorIEnumerationAsVectorIterator |
|
| 0.0;0 |
1 | /* | |
2 | This file is part of Combean. | |
3 | ||
4 | Combean is free software; you can redistribute it and/or modify | |
5 | it under the terms of the GNU General Public License as published by | |
6 | the Free Software Foundation; either version 2 of the License, or | |
7 | (at your option) any later version. | |
8 | ||
9 | Combean is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with Combean; if not, write to the Free Software | |
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | */ | |
18 | /* | |
19 | * Created on 22.04.2005 | |
20 | * | |
21 | */ | |
22 | package net.sourceforge.combean.adapters.drasys.lp; | |
23 | ||
24 | import java.util.Enumeration; | |
25 | ||
26 | import net.sourceforge.combean.interfaces.mathprog.linalg.SparseVector; | |
27 | import net.sourceforge.combean.interfaces.mathprog.linalg.VectorIterator; | |
28 | import net.sourceforge.combean.interfaces.mathprog.linalg.VectorValue; | |
29 | import net.sourceforge.combean.interfaces.mathprog.lp.model.NoLabel; | |
30 | import net.sourceforge.combean.util.except.UnsupportedMethodException; | |
31 | import drasys.or.matrix.VectorElementI; | |
32 | import drasys.or.matrix.VectorI; | |
33 | ||
34 | /** | |
35 | * Wrap a VectorI as SparseVec. | |
36 | * | |
37 | * @author schickin | |
38 | * | |
39 | */ | |
40 | public class VectorIAsSparseVector implements SparseVector { | |
41 | ||
42 | 20 | private VectorI draVec = null; |
43 | ||
44 | /** | |
45 | * Constructor. | |
46 | * | |
47 | * @param draVec the VectorI to be wrapped. | |
48 | */ | |
49 | public VectorIAsSparseVector(VectorI draVec) { | |
50 | 20 | super(); |
51 | ||
52 | 20 | this.draVec = draVec; |
53 | 20 | } |
54 | ||
55 | /* (non-Javadoc) | |
56 | * @see net.sourceforge.combean.interfaces.mathprog.SparseVector#getDimension() | |
57 | */ | |
58 | public int getDimension() { | |
59 | 0 | return this.draVec.size(); |
60 | } | |
61 | ||
62 | /** | |
63 | * A private class, representing a suitable VectorIterator-implementation | |
64 | * | |
65 | * @author schickin | |
66 | * | |
67 | */ | |
68 | 111 | private class VectorIEnumerationAsVectorIterator |
69 | implements VectorIterator<NoLabel> { | |
70 | ||
71 | 20 | private Enumeration vecEnum = null; |
72 | ||
73 | /** | |
74 | * Constructor | |
75 | * | |
76 | * @param vec the vector to be iterated through. | |
77 | */ | |
78 | 20 | public VectorIEnumerationAsVectorIterator(VectorI vec) { |
79 | 20 | super(); |
80 | ||
81 | 20 | this.vecEnum = vec.elements(); |
82 | 20 | } |
83 | ||
84 | /* (non-Javadoc) | |
85 | * @see net.sourceforge.combean.interfaces.mathprog.lp.VectorIterator#hasNext() | |
86 | */ | |
87 | public boolean hasNext() { | |
88 | 131 | return this.vecEnum.hasMoreElements(); |
89 | } | |
90 | ||
91 | /* (non-Javadoc) | |
92 | * @see net.sourceforge.combean.interfaces.mathprog.lp.VectorIterator#next() | |
93 | */ | |
94 | public VectorValue<NoLabel> next() { | |
95 | 111 | VectorElementI elem = (VectorElementI) this.vecEnum.nextElement(); |
96 | 111 | return new VectorElementIAsVectorValue(elem); |
97 | } | |
98 | ||
99 | /* (non-Javadoc) | |
100 | * @see java.util.Iterator#remove() | |
101 | */ | |
102 | public void remove() { | |
103 | 0 | throw new UnsupportedMethodException(); |
104 | // TODO Auto-generated method stub | |
105 | /* | |
106 | */ | |
107 | } | |
108 | } | |
109 | ||
110 | /* (non-Javadoc) | |
111 | * @see net.sourceforge.combean.interfaces.mathprog.lp.SparseVector#getIterator() | |
112 | */ | |
113 | public VectorIterator<NoLabel> iterator() { | |
114 | 20 | return new VectorIEnumerationAsVectorIterator(this.draVec); |
115 | } | |
116 | ||
117 | /* (non-Javadoc) | |
118 | * @see net.sourceforge.combean.interfaces.mathprog.lp.SparseVector#getNumNonZeroEntries() | |
119 | */ | |
120 | public int getNumIterations() { | |
121 | 0 | return this.draVec.sizeOfElements(); |
122 | } | |
123 | } |