View Javadoc

1   package org.sat4j.core;
2   
3   /*******************************************************************************
4    * SAT4J: a SATisfiability library for Java Copyright (C) 2004, 2012 Artois University and CNRS
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   * Contributors:
30   *   CRIL - initial API and implementation
31   *******************************************************************************/
32  import java.util.Comparator;
33  import java.util.Iterator;
34  
35  import org.sat4j.specs.IVec;
36  
37  /**
38   * Utility class to allow Read Only access to an IVec<T>.
39   * 
40   * @author daniel
41   * 
42   * @param <T>
43   *            the type of the container.
44   */
45  public final class ReadOnlyVec<T> implements IVec<T> {
46  
47      /**
48  	 * 
49  	 */
50      private static final long serialVersionUID = 1L;
51  
52      private final IVec<T> vec;
53  
54      public ReadOnlyVec(IVec<T> vec) {
55          this.vec = vec;
56      }
57  
58      public void clear() {
59          throw new UnsupportedOperationException();
60      }
61  
62      public void copyTo(IVec<T> copy) {
63          this.vec.copyTo(copy);
64      }
65  
66      public <E> void copyTo(E[] dest) {
67          this.vec.copyTo(dest);
68      }
69  
70      public T delete(int i) {
71          throw new UnsupportedOperationException();
72      }
73  
74      public void ensure(int nsize) {
75          throw new UnsupportedOperationException();
76  
77      }
78  
79      public T get(int i) {
80          return this.vec.get(i);
81      }
82  
83      public void growTo(int newsize, T pad) {
84          throw new UnsupportedOperationException();
85      }
86  
87      public void insertFirst(T elem) {
88          throw new UnsupportedOperationException();
89      }
90  
91      public void insertFirstWithShifting(T elem) {
92          throw new UnsupportedOperationException();
93      }
94  
95      public boolean isEmpty() {
96          return this.vec.isEmpty();
97      }
98  
99      public Iterator<T> iterator() {
100         return this.vec.iterator();
101     }
102 
103     public T last() {
104         return this.vec.last();
105     }
106 
107     public void moveTo(IVec<T> dest) {
108         throw new UnsupportedOperationException();
109     }
110 
111     public void moveTo(int dest, int source) {
112         throw new UnsupportedOperationException();
113     }
114 
115     public void pop() {
116         throw new UnsupportedOperationException();
117     }
118 
119     public IVec<T> push(T elem) {
120         throw new UnsupportedOperationException();
121     }
122 
123     public void remove(T elem) {
124         throw new UnsupportedOperationException();
125     }
126 
127     public void set(int i, T o) {
128         throw new UnsupportedOperationException();
129     }
130 
131     public void shrink(int nofelems) {
132         throw new UnsupportedOperationException();
133     }
134 
135     public void shrinkTo(int newsize) {
136         throw new UnsupportedOperationException();
137     }
138 
139     public int size() {
140         return this.vec.size();
141     }
142 
143     public void sort(Comparator<T> comparator) {
144         throw new UnsupportedOperationException();
145     }
146 
147     public void sortUnique(Comparator<T> comparator) {
148         throw new UnsupportedOperationException();
149     }
150 
151     @SuppressWarnings("unchecked")
152     public T[] toArray() {
153         T[] array = (T[]) new Object[this.vec.size()];
154         this.vec.copyTo(array);
155         return array;
156     }
157 
158     public void unsafePush(T elem) {
159         throw new UnsupportedOperationException();
160     }
161 
162     /**
163      * @since 2.1
164      */
165     public boolean contains(T element) {
166         return this.vec.contains(element);
167     }
168 
169     /**
170      * @since 2.2
171      */
172     public int indexOf(T element) {
173         return this.vec.indexOf(element);
174     }
175 
176     @Override
177     public String toString() {
178         return this.vec.toString();
179     }
180 
181 }