147d431f63a66505a645f282416659a9758a91f1cBrett Chabot/*
247d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Copyright 2001-2009 OFFIS, Tammo Freese
347d431f63a66505a645f282416659a9758a91f1cBrett Chabot *
447d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Licensed under the Apache License, Version 2.0 (the "License");
547d431f63a66505a645f282416659a9758a91f1cBrett Chabot * you may not use this file except in compliance with the License.
647d431f63a66505a645f282416659a9758a91f1cBrett Chabot * You may obtain a copy of the License at
747d431f63a66505a645f282416659a9758a91f1cBrett Chabot *
847d431f63a66505a645f282416659a9758a91f1cBrett Chabot *     http://www.apache.org/licenses/LICENSE-2.0
947d431f63a66505a645f282416659a9758a91f1cBrett Chabot *
1047d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Unless required by applicable law or agreed to in writing, software
1147d431f63a66505a645f282416659a9758a91f1cBrett Chabot * distributed under the License is distributed on an "AS IS" BASIS,
1247d431f63a66505a645f282416659a9758a91f1cBrett Chabot * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1347d431f63a66505a645f282416659a9758a91f1cBrett Chabot * See the License for the specific language governing permissions and
1447d431f63a66505a645f282416659a9758a91f1cBrett Chabot * limitations under the License.
1547d431f63a66505a645f282416659a9758a91f1cBrett Chabot */
1647d431f63a66505a645f282416659a9758a91f1cBrett Chabotpackage org.easymock.internal.matchers;
1747d431f63a66505a645f282416659a9758a91f1cBrett Chabot
1847d431f63a66505a645f282416659a9758a91f1cBrett Chabotimport java.io.Serializable;
1947d431f63a66505a645f282416659a9758a91f1cBrett Chabotimport java.util.Iterator;
2047d431f63a66505a645f282416659a9758a91f1cBrett Chabotimport java.util.List;
2147d431f63a66505a645f282416659a9758a91f1cBrett Chabot
2247d431f63a66505a645f282416659a9758a91f1cBrett Chabotimport org.easymock.IArgumentMatcher;
2347d431f63a66505a645f282416659a9758a91f1cBrett Chabot
2447d431f63a66505a645f282416659a9758a91f1cBrett Chabotpublic class And implements IArgumentMatcher, Serializable {
2547d431f63a66505a645f282416659a9758a91f1cBrett Chabot
2647d431f63a66505a645f282416659a9758a91f1cBrett Chabot    private static final long serialVersionUID = 3874580646798403818L;
2747d431f63a66505a645f282416659a9758a91f1cBrett Chabot
2847d431f63a66505a645f282416659a9758a91f1cBrett Chabot    private final List<IArgumentMatcher> matchers;
2947d431f63a66505a645f282416659a9758a91f1cBrett Chabot
3047d431f63a66505a645f282416659a9758a91f1cBrett Chabot    public And(List<IArgumentMatcher> matchers) {
3147d431f63a66505a645f282416659a9758a91f1cBrett Chabot        this.matchers = matchers;
3247d431f63a66505a645f282416659a9758a91f1cBrett Chabot    }
3347d431f63a66505a645f282416659a9758a91f1cBrett Chabot
3447d431f63a66505a645f282416659a9758a91f1cBrett Chabot    public boolean matches(Object actual) {
3547d431f63a66505a645f282416659a9758a91f1cBrett Chabot        for (IArgumentMatcher matcher : matchers) {
3647d431f63a66505a645f282416659a9758a91f1cBrett Chabot            if (!matcher.matches(actual)) {
3747d431f63a66505a645f282416659a9758a91f1cBrett Chabot                return false;
3847d431f63a66505a645f282416659a9758a91f1cBrett Chabot            }
3947d431f63a66505a645f282416659a9758a91f1cBrett Chabot        }
4047d431f63a66505a645f282416659a9758a91f1cBrett Chabot        return true;
4147d431f63a66505a645f282416659a9758a91f1cBrett Chabot    }
4247d431f63a66505a645f282416659a9758a91f1cBrett Chabot
4347d431f63a66505a645f282416659a9758a91f1cBrett Chabot    public void appendTo(StringBuffer buffer) {
4447d431f63a66505a645f282416659a9758a91f1cBrett Chabot        buffer.append("and(");
4547d431f63a66505a645f282416659a9758a91f1cBrett Chabot        for (Iterator<IArgumentMatcher> it = matchers.iterator(); it.hasNext();) {
4647d431f63a66505a645f282416659a9758a91f1cBrett Chabot            it.next().appendTo(buffer);
4747d431f63a66505a645f282416659a9758a91f1cBrett Chabot            if (it.hasNext()) {
4847d431f63a66505a645f282416659a9758a91f1cBrett Chabot                buffer.append(", ");
4947d431f63a66505a645f282416659a9758a91f1cBrett Chabot            }
5047d431f63a66505a645f282416659a9758a91f1cBrett Chabot        }
5147d431f63a66505a645f282416659a9758a91f1cBrett Chabot        buffer.append(")");
5247d431f63a66505a645f282416659a9758a91f1cBrett Chabot    }
5347d431f63a66505a645f282416659a9758a91f1cBrett Chabot}
54