001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.modeshape.common.collection;
017
018import java.util.EnumSet;
019import java.util.Iterator;
020import org.modeshape.common.annotation.Immutable;
021import org.modeshape.common.collection.Problem.Status;
022import org.modeshape.common.function.Consumer;
023import org.modeshape.common.i18n.I18n;
024import org.modeshape.common.logging.Logger;
025import org.modeshape.common.util.CheckArg;
026
027/**
028 * An immutable wrapper for a mutable {@link Problems}.
029 */
030@Immutable
031public class ImmutableProblems implements Problems {
032
033    private static final long serialVersionUID = 1L;
034    private final Problems delegate;
035
036    public ImmutableProblems( Problems delegate ) {
037        CheckArg.isNotNull(delegate, "delegate");
038        this.delegate = delegate;
039    }
040
041    @Override
042    public void addError( I18n message,
043                          Object... params ) {
044        throw new UnsupportedOperationException();
045    }
046
047    @Override
048    public void addError( String resource,
049                          String location,
050                          I18n message,
051                          Object... params ) {
052        throw new UnsupportedOperationException();
053    }
054
055    @Override
056    public void addError( int code,
057                          I18n message,
058                          Object... params ) {
059        throw new UnsupportedOperationException();
060    }
061
062    @Override
063    public void addError( int code,
064                          String resource,
065                          String location,
066                          I18n message,
067                          Object... params ) {
068        throw new UnsupportedOperationException();
069    }
070
071    @Override
072    public void addError( Throwable throwable,
073                          I18n message,
074                          Object... params ) {
075        throw new UnsupportedOperationException();
076    }
077
078    @Override
079    public void addError( Throwable throwable,
080                          String resource,
081                          String location,
082                          I18n message,
083                          Object... params ) {
084        throw new UnsupportedOperationException();
085    }
086
087    @Override
088    public void addError( Throwable throwable,
089                          int code,
090                          I18n message,
091                          Object... params ) {
092        throw new UnsupportedOperationException();
093    }
094
095    @Override
096    public void addError( Throwable throwable,
097                          int code,
098                          String resource,
099                          String location,
100                          I18n message,
101                          Object... params ) {
102        throw new UnsupportedOperationException();
103    }
104
105    @Override
106    public void addInfo( I18n message,
107                         Object... params ) {
108        throw new UnsupportedOperationException();
109    }
110
111    @Override
112    public void addInfo( String resource,
113                         String location,
114                         I18n message,
115                         Object... params ) {
116        throw new UnsupportedOperationException();
117    }
118
119    @Override
120    public void addInfo( int code,
121                         I18n message,
122                         Object... params ) {
123        throw new UnsupportedOperationException();
124    }
125
126    @Override
127    public void addInfo( int code,
128                         String resource,
129                         String location,
130                         I18n message,
131                         Object... params ) {
132        throw new UnsupportedOperationException();
133    }
134
135    @Override
136    public void addInfo( Throwable throwable,
137                         I18n message,
138                         Object... params ) {
139        throw new UnsupportedOperationException();
140    }
141
142    @Override
143    public void addInfo( Throwable throwable,
144                         String resource,
145                         String location,
146                         I18n message,
147                         Object... params ) {
148        throw new UnsupportedOperationException();
149    }
150
151    @Override
152    public void addInfo( Throwable throwable,
153                         int code,
154                         I18n message,
155                         Object... params ) {
156        throw new UnsupportedOperationException();
157    }
158
159    @Override
160    public void addInfo( Throwable throwable,
161                         int code,
162                         String resource,
163                         String location,
164                         I18n message,
165                         Object... params ) {
166        throw new UnsupportedOperationException();
167    }
168
169    @Override
170    public void addWarning( I18n message,
171                            Object... params ) {
172        throw new UnsupportedOperationException();
173    }
174
175    @Override
176    public void addWarning( String resource,
177                            String location,
178                            I18n message,
179                            Object... params ) {
180        throw new UnsupportedOperationException();
181    }
182
183    @Override
184    public void addWarning( int code,
185                            I18n message,
186                            Object... params ) {
187        throw new UnsupportedOperationException();
188    }
189
190    @Override
191    public void addWarning( int code,
192                            String resource,
193                            String location,
194                            I18n message,
195                            Object... params ) {
196        throw new UnsupportedOperationException();
197    }
198
199    @Override
200    public void addWarning( Throwable throwable,
201                            I18n message,
202                            Object... params ) {
203        throw new UnsupportedOperationException();
204    }
205
206    @Override
207    public void addWarning( Throwable throwable,
208                            String resource,
209                            String location,
210                            I18n message,
211                            Object... params ) {
212        throw new UnsupportedOperationException();
213    }
214
215    @Override
216    public void addWarning( Throwable throwable,
217                            int code,
218                            I18n message,
219                            Object... params ) {
220        throw new UnsupportedOperationException();
221    }
222
223    @Override
224    public void addWarning( Throwable throwable,
225                            int code,
226                            String resource,
227                            String location,
228                            I18n message,
229                            Object... params ) {
230        throw new UnsupportedOperationException();
231    }
232
233    @Override
234    public void addAll( Iterable<Problem> problems ) {
235        if (problems != null && problems != this && problems != delegate) this.delegate.addAll(problems);
236    }
237
238    @Override
239    public boolean hasErrors() {
240        return delegate.hasErrors();
241    }
242
243    @Override
244    public boolean hasInfo() {
245        return delegate.hasInfo();
246    }
247
248    @Override
249    public boolean hasProblems() {
250        return delegate.hasProblems();
251    }
252
253    @Override
254    public boolean hasWarnings() {
255        return delegate.hasWarnings();
256    }
257
258    @Override
259    public boolean isEmpty() {
260        return delegate.isEmpty();
261    }
262
263    @Override
264    public int errorCount() {
265        return delegate.errorCount();
266    }
267
268    @Override
269    public int problemCount() {
270        return delegate.problemCount();
271    }
272
273    @Override
274    public int warningCount() {
275        return delegate.warningCount();
276    }
277
278    @Override
279    public int infoCount() {
280        return delegate.infoCount();
281    }
282
283    @Override
284    public Iterator<Problem> iterator() {
285        return ReadOnlyIterator.around(delegate.iterator());
286    }
287
288    @Override
289    public int size() {
290        return delegate.size();
291    }
292
293    @Override
294    public String toString() {
295        return delegate.toString();
296    }
297
298    @Override
299    public void apply( Consumer<Problem> consumer ) {
300        delegate.apply(consumer);
301    }
302
303    @Override
304    public void apply( EnumSet<Status> statuses,
305                       Consumer<Problem> consumer ) {
306        delegate.apply(statuses, consumer);
307    }
308
309    @Override
310    public void apply( Status status,
311                       Consumer<Problem> consumer ) {
312        delegate.apply(status, consumer);
313    }
314
315    @Override
316    public void writeTo( Logger logger ) {
317        delegate.writeTo(logger);
318    }
319
320    @Override
321    public void writeTo( Logger logger,
322                         Status firstStatus,
323                         Status... additionalStatuses ) {
324        delegate.writeTo(logger, firstStatus, additionalStatuses);
325    }
326}