/*
 * 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.search.builder;

import java.util.ArrayList;
import java.util.Set;

import com.dell.doradus.core.ObjectID;
import com.dell.doradus.search.FilteredIterable;
import com.dell.doradus.search.IDHelper;
import com.dell.doradus.search.aggregate.Entity;
import com.dell.doradus.search.filter.Filter;
import com.dell.doradus.search.query.IdQuery;
import com.dell.doradus.search.query.Query;

public class BuilderId extends SearchBuilder {
    
	@Override public FilteredIterable search(Query query) {
		IdQuery qu = (IdQuery)query;
        ArrayList<ObjectID> ids = new ArrayList<ObjectID>(1);
        ids.add(IDHelper.createID(qu.id));
        return create(ids, null);
	}
	
	@Override public Filter filter(Query query) {
		IdQuery qu = (IdQuery)query;
        final ObjectID id = IDHelper.createID(qu.id.toString());
        return new Filter() {
            @Override public boolean check(Entity entity) {
                return id.equals(entity.id());
            }

			@Override public void addFields(Set<String> fields) {}
		};
	}
   
}

@@ -684,16 +684,63 @@
 yList;%0D%0A
+import java.util.List;%0D%0Aimport java.util.Map;%0D%0A
 import j
@@ -754,16 +754,16 @@
 l.Set;%0D%0A
-
 %0D%0Aimport
@@ -1076,16 +1076,70 @@
 .Query;%0D
+%0Aimport com.dell.doradus.service.spider.SpiderHelper;%0D
 %0A%0D%0Apubli
@@ -1336,24 +1336,24 @@
 ectID%3E(1);%0D%0A
-
         ids.
@@ -1380,24 +1380,274 @@
 D(qu.id));%0D%0A
+        List%3CString%3E fields = new ArrayList%3CString%3E(1);%0D%0A        fields.add(%22_ID%22);%0D%0A        Map%3CObjectID, Map%3CString, String%3E%3E result = SpiderHelper.getScalarValues(m_table, ids, fields);%0D%0A        ids.clear();%0D%0A        ids.addAll(result.keySet());%0D%0A
         retu

query ID=x should not return object if x does not exist