/*
 * Copyright (C) 2014 Dell, Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.dell.doradus.olap.aggregate.mr;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.dell.doradus.search.aggregate.AggregationGroup;

public class AggregationIncludeExclude {
	private List<Set<String>> m_exclude = new ArrayList<Set<String>>();
	private List<Set<String>> m_include = new ArrayList<Set<String>>();
	
	public AggregationIncludeExclude(List<AggregationGroup> groups) {
		for(int i = 0; i < groups.size(); i++) {
			List<String> exclude = groups.get(i).exclude;
			if(exclude == null) m_exclude.add(null);
			else {
				for(int j = 0; j < exclude.size(); j++) exclude.set(j, exclude.get(j).toLowerCase());
				m_exclude.add(new HashSet<String>(exclude));
			}
			
			List<String> include = groups.get(i).include;
			if(include == null) m_include.add(null);
			else {
				for(int j = 0; j < include.size(); j++) include.set(j, include.get(j).toLowerCase());
				m_include.add(new HashSet<String>(include));
			}
		}
	}
	
	public boolean accept(MGName name, int level) {
		Set<String> excl = m_exclude.get(level);
		if(excl != null && name.name != null && excl.contains(name.name.toLowerCase())) return false;
		Set<String> incl = m_include.get(level);
		if(incl != null && (name.name == null || !incl.contains(name.name.toLowerCase()))) return false;
		return true;
	}
	
}

@@ -1202,77 +1202,126 @@
 %09%09%09%09
-for(int j = 0; j %3C exclude.size(); j++) exclude.set(j, exclude.get(j)
+HashSet%3CString%3E hs = new HashSet%3CString%3E(exclude.size());%0A%09%09%09%09for(String str: exclude) hs.add(str == null ? null : str
 .toL
@@ -1355,36 +1355,10 @@
 add(
-new HashSet%3CString%3E(exclude)
+hs
 );%0A%09
@@ -1476,77 +1476,126 @@
 %09%09%09%09
-for(int j = 0; j %3C include.size(); j++) include.set(j, include.get(j)
+HashSet%3CString%3E hs = new HashSet%3CString%3E(include.size());%0A%09%09%09%09for(String str: include) hs.add(str == null ? null : str
 .toL
@@ -1629,36 +1629,10 @@
 add(
-new HashSet%3CString%3E(include)
+hs
 );%0A%09
@@ -1693,16 +1693,84 @@
 evel) %7B%0A
+%09%09String text = name.name == null ? null : name.name.toLowerCase();%0A
 %09%09Set%3CSt
@@ -1829,66 +1829,26 @@
  && 
-name.name != null && excl.contains(name.name.toLowerCase()
+excl.contains(text
 )) r
@@ -1929,67 +1929,27 @@
 && (
-name.name == null %7C%7C !incl.contains(name.name.toLowerCase()
+!incl.contains(text
 ))) 

Support NULL keyword in OLAP aggregate