package org.lumongo.doc;

import org.lumongo.LumongoConstants;
import org.lumongo.cluster.message.Lumongo.LMDoc;
import org.lumongo.cluster.message.Lumongo.LMField;
import org.lumongo.util.StringUtil;

public class IndexedDocBuilder {

	private LMDoc.Builder indexedDocBuilder;

	public static IndexedDocBuilder newBuilder() {
		return new IndexedDocBuilder();
	}

	public IndexedDocBuilder() {
		indexedDocBuilder = LMDoc.newBuilder();
	}

	public IndexedDocBuilder addField(String fieldName, String... values) {

		for (String value : values) {
			indexedDocBuilder.addIndexedField(LMField.newBuilder().setFieldName(fieldName).addFieldValue(value));
		}

		return this;
	}

	public IndexedDocBuilder addField(String fieldName, Integer... values) {

		for (Integer value : values) {
			indexedDocBuilder.addIndexedField(LMField.newBuilder().setFieldName(fieldName).addIntValue(value));
		}

		return this;
	}

	public IndexedDocBuilder addField(String fieldName, Float... values) {

		for (Float value : values) {
			indexedDocBuilder.addIndexedField(LMField.newBuilder().setFieldName(fieldName).addFloatValue(value));
		}
		return this;
	}

	public IndexedDocBuilder addField(String fieldName, Double... values) {

		for (Double value : values) {
			indexedDocBuilder.addIndexedField(LMField.newBuilder().setFieldName(fieldName).addDoubleValue(value));
		}
		return this;
	}

	public void addFacet(String... path) {
		indexedDocBuilder.addFacet(StringUtil.join(LumongoConstants.FACET_DELIMITER, path));
	}

	public IndexedDocBuilder clearFields() {
		indexedDocBuilder.clearIndexedField();
		return this;
	}

	public IndexedDocBuilder clearFacets() {
		indexedDocBuilder.clearFacet();
		return this;
	}

	public IndexedDocBuilder clear() {
		indexedDocBuilder.clear();
		return this;
	}

	public LMDoc getIndexedDoc() {
		return indexedDocBuilder.build();
	}

}

@@ -19,16 +19,40 @@
 o.doc;%0A%0A
+import java.util.Date;%0A%0A
 import o
@@ -80,16 +80,16 @@
 stants;%0A
-
 import o
@@ -252,17 +252,18 @@
 ilder %7B%0A
+%09
 %0A
-
 %09private
@@ -296,17 +296,18 @@
 uilder;%0A
+%09
 %0A
-
 %09public 
@@ -375,33 +375,34 @@
 ocBuilder();%0A%09%7D%0A
+%09
 %0A
-
 %09public IndexedD
@@ -456,25 +456,26 @@
 ilder();%0A%09%7D%0A
+%09
 %0A
-
 %09public Inde
@@ -531,25 +531,27 @@
 . values) %7B%0A
+%09%09
 %0A
-
 %09%09for (Strin
@@ -671,33 +671,35 @@
 ue(value));%0A%09%09%7D%0A
+%09%09
 %0A
-
 %09%09return this;%0A%09
@@ -692,33 +692,34 @@
 return this;%0A%09%7D%0A
+%09
 %0A
-
 %09public IndexedD
@@ -772,25 +772,27 @@
 . values) %7B%0A
+%09%09
 %0A
-
 %09%09for (Integ
@@ -919,17 +919,19 @@
 ));%0A%09%09%7D%0A
+%09%09
 %0A
-
 %09%09return
@@ -932,33 +932,269 @@
 return this;%0A%09%7D%0A
+%09%0A%09public IndexedDocBuilder addField(String fieldName, Long... values) %7B%0A%09%09%0A%09%09for (Long value : values) %7B%0A%09%09%09indexedDocBuilder.addIndexedField(LMField.newBuilder().setFieldName(fieldName).addLongValue(value));%0A%09%09%7D%0A%09%09%0A%09%09return this;%0A%09%7D%0A%09
 %0A
-
 %09public IndexedD
@@ -1245,25 +1245,27 @@
 . values) %7B%0A
+%09%09
 %0A
-
 %09%09for (Float
@@ -1402,33 +1402,34 @@
 return this;%0A%09%7D%0A
+%09
 %0A
-
 %09public IndexedD
@@ -1485,17 +1485,19 @@
 lues) %7B%0A
+%09%09
 %0A
-
 %09%09for (D
@@ -1640,33 +1640,276 @@
 return this;%0A%09%7D%0A
+%09%0A%09public IndexedDocBuilder addField(String fieldName, Date... values) %7B%0A%09%09%0A%09%09for (Date value : values) %7B%0A%09%09%09indexedDocBuilder.addIndexedField(LMField.newBuilder().setFieldName(fieldName).addLongValue(value.getTime()));%0A%09%09%7D%0A%09%09return this;%0A%09%7D%0A%09
 %0A
-
 %09public void add
@@ -2018,25 +2018,26 @@
  path));%0A%09%7D%0A
+%09
 %0A
-
 %09public Inde
@@ -2117,33 +2117,34 @@
 return this;%0A%09%7D%0A
+%09
 %0A
-
 %09public IndexedD
@@ -2213,33 +2213,34 @@
 return this;%0A%09%7D%0A
+%09
 %0A
-
 %09public IndexedD
@@ -2306,17 +2306,18 @@
 his;%0A%09%7D%0A
+%09
 %0A
-
 %09public 
@@ -2379,11 +2379,12 @@
 d();%0A%09%7D%0A
+%09
 %0A%7D%0A

add long and date to indexeddocbuilder