View Javadoc
1   /*
2    * Copyright 2007 Kasper B. Graversen
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.supercsv.comment;
17  
18  /**
19   * CommentMatcher that matches lines that begin with a specified String.
20   */
21  public class CommentStartsWith implements CommentMatcher {
22  	
23  	private final String value;
24  	
25  	/**
26  	 * Constructs a new <tt>CommentStartsWith</tt> comment matcher.
27  	 * 
28  	 * @param value
29  	 *            the String a line must start with to be a comment
30  	 * @throws NullPointerException
31  	 *             if value is null
32  	 * @throws IllegalArgumentException
33  	 *             if value is empty
34  	 */
35  	public CommentStartsWith(final String value) {
36  		if( value == null ) {
37  			throw new NullPointerException("value should not be null");
38  		} else if( value.length() == 0 ) {
39  			throw new IllegalArgumentException("value should not be empty");
40  		}
41  		this.value = value;
42  	}
43  	
44  	/**
45  	 * {@inheritDoc}
46  	 */
47  	public boolean isComment(String line) {
48  		return line.startsWith(value);
49  	}
50  	
51  }