View Javadoc
1   /*
2    * Copyright 2009-2013 the original author or authors.
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  
17  package com.orangesignal.csv.filters;
18  
19  import java.io.IOException;
20  import java.util.Comparator;
21  
22  /**
23   * 指定された Java プログラム要素のフィールド値が下限値から上限値の範囲かどうかでフィルタを適用する Java プログラム要素フィルタの実装です。
24   * 
25   * @author Koji Sugisawa
26   * @since 1.2.3
27   */
28  public class BeanBetweenExpression extends BeanExpression {
29  
30  	/**
31  	 * 下限値を保持します。
32  	 */
33  	private Object low;
34  
35  	/**
36  	 * 上限値を保持します。
37  	 */
38  	private Object high;
39  
40  	/**
41  	 * コンパレータを保持します。
42  	 */
43  	@SuppressWarnings("rawtypes")
44  	private Comparator comparator;
45  
46  	/**
47  	 * コンストラクタです。
48  	 * 
49  	 * @param name フィールド名
50  	 * @param low 下限値
51  	 * @param high 上限値
52  	 * @throws IllegalArgumentException パラメータが <code>null</code> の場合
53  	 */
54  	protected BeanBetweenExpression(final String name, final Object low, final Object high) {
55  		this(name, low, high, null);
56  	}
57  
58  	/**
59  	 * コンストラクタです。
60  	 * 
61  	 * @param name フィールド名
62  	 * @param low 下限値
63  	 * @param high 上限値
64  	 * @param comparator コンパレータ (オプション)
65  	 * @throws IllegalArgumentException パラメータが <code>null</code> の場合
66  	 */
67  	protected BeanBetweenExpression(final String name, final Object low, final Object high, @SuppressWarnings("rawtypes") final Comparator comparator) {
68  		super(name);
69  		if (low == null || high == null) {
70  			throw new IllegalArgumentException("Low or High must not be null");
71  		}
72  		this.low = low;
73  		this.high = high;
74  		this.comparator = comparator;
75  	}
76  
77  	@Override
78  	public boolean accept(final Object bean) throws IOException {
79  		return BeanExpressionUtils.between(bean, name, low, high, comparator);
80  	}
81  
82  }