View Javadoc

1   package org.sat4j.core;
2   
3   /*******************************************************************************
4    * SAT4J: a SATisfiability library for Java Copyright (C) 2004-2008 Daniel Le Berre
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of the Eclipse Public License v1.0
8    * which accompanies this distribution, and is available at
9    * http://www.eclipse.org/legal/epl-v10.html
10   *
11   * Alternatively, the contents of this file may be used under the terms of
12   * either the GNU Lesser General Public License Version 2.1 or later (the
13   * "LGPL"), in which case the provisions of the LGPL are applicable instead
14   * of those above. If you wish to allow use of your version of this file only
15   * under the terms of the LGPL, and not to allow others to use your version of
16   * this file under the terms of the EPL, indicate your decision by deleting
17   * the provisions above and replace them with the notice and other provisions
18   * required by the LGPL. If you do not delete the provisions above, a recipient
19   * may use your version of this file under the terms of the EPL or the LGPL.
20   * 
21   * Based on the original MiniSat specification from:
22   * 
23   * An extensible SAT solver. Niklas Een and Niklas Sorensson. Proceedings of the
24   * Sixth International Conference on Theory and Applications of Satisfiability
25   * Testing, LNCS 2919, pp 502-518, 2003.
26   *
27   * See www.minisat.se for the original solver in C++.
28   * 
29   *******************************************************************************/
30  import java.util.Comparator;
31  import java.util.Iterator;
32  
33  import org.sat4j.specs.IVec;
34  
35  /**
36   * Utility class to allow Read Only access to an IVec<T>.
37   * 
38   * @author daniel
39   * 
40   * @param <T>
41   *            the type of the container.
42   */
43  public final class ReadOnlyVec<T> implements IVec<T> {
44  
45  	/**
46  	 * 
47  	 */
48  	private static final long serialVersionUID = 1L;
49  
50  	private final IVec<T> vec;
51  
52  	public ReadOnlyVec(IVec<T> vec) {
53  		this.vec = vec;
54  	}
55  
56  	public void clear() {
57  		throw new UnsupportedOperationException();
58  	}
59  
60  	public void copyTo(IVec<T> copy) {
61  		vec.copyTo(copy);
62  	}
63  
64  	public <E> void copyTo(E[] dest) {
65  		vec.copyTo(dest);
66  	}
67  
68  	public T delete(int i) {
69  		throw new UnsupportedOperationException();
70  	}
71  
72  	public void ensure(int nsize) {
73  		throw new UnsupportedOperationException();
74  
75  	}
76  
77  	public T get(int i) {
78  		return vec.get(i);
79  	}
80  
81  	public void growTo(int newsize, T pad) {
82  		throw new UnsupportedOperationException();
83  	}
84  
85  	public void insertFirst(T elem) {
86  		throw new UnsupportedOperationException();
87  	}
88  
89  	public void insertFirstWithShifting(T elem) {
90  		throw new UnsupportedOperationException();
91  	}
92  
93  	public boolean isEmpty() {
94  		return vec.isEmpty();
95  	}
96  
97  	public Iterator<T> iterator() {
98  		return vec.iterator();
99  	}
100 
101 	public T last() {
102 		return vec.last();
103 	}
104 
105 	public void moveTo(IVec<T> dest) {
106 		throw new UnsupportedOperationException();
107 	}
108 
109 	public void moveTo(int dest, int source) {
110 		throw new UnsupportedOperationException();
111 	}
112 
113 	public void pop() {
114 		throw new UnsupportedOperationException();
115 	}
116 
117 	public IVec<T> push(T elem) {
118 		throw new UnsupportedOperationException();
119 	}
120 
121 	public void remove(T elem) {
122 		throw new UnsupportedOperationException();
123 	}
124 
125 	public void set(int i, T o) {
126 		throw new UnsupportedOperationException();
127 	}
128 
129 	public void shrink(int nofelems) {
130 		throw new UnsupportedOperationException();
131 	}
132 
133 	public void shrinkTo(int newsize) {
134 		throw new UnsupportedOperationException();
135 	}
136 
137 	public int size() {
138 		return vec.size();
139 	}
140 
141 	public void sort(Comparator<T> comparator) {
142 		throw new UnsupportedOperationException();
143 	}
144 
145 	public void sortUnique(Comparator<T> comparator) {
146 		throw new UnsupportedOperationException();
147 	}
148 
149 	@SuppressWarnings("unchecked")
150 	public T[] toArray() {
151 		T[] array = (T[]) new Object[vec.size()];
152 		vec.copyTo(array);
153 		return array;
154 	}
155 
156 	public void unsafePush(T elem) {
157 		throw new UnsupportedOperationException();
158 	}
159 
160 	/**
161 	 * @since 2.1
162 	 */
163 	public boolean contains(T element) {
164 		return vec.contains(element);
165 	}
166 
167 	/**
168 	 * @since 2.2
169 	 */
170 	public int indexOf(T element) {
171 		return vec.indexOf(element);
172 	}
173 
174 	@Override
175 	public String toString() {
176 		return vec.toString();
177 	}
178 
179 }