001/*-------------------------------------------------------------------------+ 002| | 003| Copyright 2005-2011 the ConQAT Project | 004| | 005| Licensed under the Apache License, Version 2.0 (the "License"); | 006| you may not use this file except in compliance with the License. | 007| You may obtain a copy of the License at | 008| | 009| http://www.apache.org/licenses/LICENSE-2.0 | 010| | 011| Unless required by applicable law or agreed to in writing, software | 012| distributed under the License is distributed on an "AS IS" BASIS, | 013| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 014| See the License for the specific language governing permissions and | 015| limitations under the License. | 016+-------------------------------------------------------------------------*/ 017package eu.cqse.check.framework.util.tokens; 018 019/** 020 * Matches if the given pattern does not match. Does not advance the token 021 * stream. 022 */ 023public class NotFollowedByPattern extends ZeroLengthTokenPatternBase { 024 025 /** The matcher that should not match at the current position. */ 026 private final TokenPatternBase matcher; 027 028 /** Constructor. */ 029 public NotFollowedByPattern(TokenPatternBase matcher) { 030 this.matcher = matcher; 031 } 032 033 /** {@inheritDoc} */ 034 @Override 035 protected boolean conditionApplies(TokenStream stream) { 036 if (stream.isExhausted()) { 037 return true; 038 } 039 return matcher.matches(stream) == null; 040 } 041 042 /** {@inheritDoc} */ 043 @Override 044 public String toString() { 045 return "NotFollowedBy " + matcher.toString(); 046 } 047}