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.LinkedList; 019import java.util.List; 020import org.modeshape.common.annotation.NotThreadSafe; 021 022/** 023 * A simple {@link Problems} collection. The problems will be {@link #iterator() returned} in the order in which they were 024 * encountered (although this cannot be guaranteed in contexts involving multiple threads or processes). 025 */ 026@NotThreadSafe 027public class SimpleProblems extends AbstractProblems { 028 private static final long serialVersionUID = 1L; 029 030 private List<Problem> problems; 031 032 @Override 033 protected void addProblem( Problem problem ) { 034 if (problem == null) return; 035 if (problems == null) problems = new LinkedList<Problem>(); 036 problems.add(problem); 037 } 038 039 @Override 040 protected List<Problem> getProblems() { 041 return this.problems != null ? problems : EMPTY_PROBLEMS; 042 } 043 044 @Override 045 public void addAll( Iterable<Problem> problems ) { 046 if (problems != null) { 047 if (problems == this) return; 048 if (this.problems == null) this.problems = new LinkedList<Problem>(); 049 for (Problem problem : problems) { 050 this.problems.add(problem); 051 } 052 } 053 } 054}