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.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.Collection;
22
23 /**
24 * 区切り文字形式データの項目名リストと値リストでフィルタする区切り文字形式データフィルタを論理演算する区切り文字形式データフィルタの基底クラスを提供します。
25 *
26 * @author Koji Sugisawa
27 * @since 1.2.3
28 */
29 public abstract class CsvNamedValueLogicalExpression implements CsvNamedValueFilter {
30
31 /**
32 * 区切り文字形式データフィルタのコレクションを保持します。
33 */
34 protected final Collection<CsvNamedValueFilter> filters;
35
36 /**
37 * デフォルトコンストラクタです。
38 */
39 protected CsvNamedValueLogicalExpression() {
40 filters = new ArrayList<CsvNamedValueFilter>();
41 }
42
43 /**
44 * コンストラクタです。
45 *
46 * @param filters 区切り文字形式データフィルタ群
47 * @throws IllegalArgumentException <code>filters</code> が <code>null</code> の場合
48 */
49 protected CsvNamedValueLogicalExpression(final CsvNamedValueFilter... filters) {
50 if (filters == null) {
51 throw new IllegalArgumentException(String.format("%s must not be null", CsvNamedValueFilter.class.getSimpleName()));
52 }
53 this.filters = Arrays.asList(filters);
54 }
55
56 /**
57 * 指定された区切り文字形式データフィルタを追加します。
58 *
59 * @param filter 区切り文字形式データフィルタ
60 */
61 public void add(final CsvNamedValueFilter filter) {
62 filters.add(filter);
63 }
64
65 @Override
66 public String toString() {
67 final String name = getClass().getName();
68 final int period = name.lastIndexOf('.');
69 return period > 0 ? name.substring(period + 1) : name;
70 }
71
72 }