本文整理汇总了Java中com.couchbase.lite.Mapper.map方法的典型用法代码示例。如果您正苦于以下问题:Java Mapper.map方法的具体用法?Java Mapper.map怎么用?Java Mapper.map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.couchbase.lite.Mapper
的用法示例。
在下文中一共展示了Mapper.map方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test200SimpleNativeView
import com.couchbase.lite.Mapper; //导入方法依赖的package包/类
public void test200SimpleNativeView() {
MockEmiter nativeEmiter = new MockEmiter();
Map doc = new HashMap();
doc.put("_id", "foo");
Mapper nativeMap = new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
emitter.emit(document.get("_id"), null);
}
};
for (int i = 0; i < 20000; i++) {
nativeMap.map(doc, nativeEmiter);
}
assertEquals(20000, nativeEmiter.count());
}
示例2: testScopeSeparation
import com.couchbase.lite.Mapper; //导入方法依赖的package包/类
public void testScopeSeparation() {
Map doc = new HashMap();
doc.put("_id", "foo");
// try to put a var "x" into global scope
Mapper map = viewCompiler.compileMap("function(doc){var x = x || 0; emit(x++,null);}", "javascript");
map.map(doc, emiter);
map.map(doc, emiter);
map.map(doc, emiter);
assertEquals(3, emiter.count());
assertEquals(new EmitPair(0.0, null), emiter.get(0));
assertEquals(new EmitPair(0.0, null), emiter.get(1));
assertEquals(new EmitPair(0.0, null), emiter.get(2));
}
示例3: testJavaScriptDesignDocument
import com.couchbase.lite.Mapper; //导入方法依赖的package包/类
public void testJavaScriptDesignDocument() {
Map<String, Object> doc1 = new HashMap<String, Object>();
doc1.put("_id", "doc1");
doc1.put("message", "hello");
Map<String, Object> doc2 = new HashMap<String, Object>();
doc2.put("_id", "doc2");
doc2.put("message", "guten tag");
Map<String, Object> doc3 = new HashMap<String, Object>();
doc3.put("_id", "doc3");
doc3.put("message", "bonjour");
Mapper map = viewCompiler.compileMap("function(doc) { if(doc.message) { emit(doc.message, 1); } }", "javascript");
map.map(doc1, emiter);
map.map(doc2, emiter);
map.map(doc3, emiter);
assertEquals(3, emiter.count());
assertEquals(new EmitPair("hello", 1.0), emiter.get(0));
assertEquals(new EmitPair("guten tag", 1.0), emiter.get(1));
assertEquals(new EmitPair("bonjour", 1.0), emiter.get(2));
}
示例4: test200SimpleJavaScriptView
import com.couchbase.lite.Mapper; //导入方法依赖的package包/类
public void test200SimpleJavaScriptView() {
MockEmiter jsEmiter = new MockEmiter();
Map doc = new HashMap();
doc.put("_id", "foo");
Mapper jsMap = viewCompiler.compileMap("function(doc){emit(doc._id,null);}", "javascript");
for (int i = 0; i < 20000; i++) {
jsMap.map(doc, jsEmiter);
}
assertEquals(20000, jsEmiter.count());
}
示例5: testSimpleJavaScriptView
import com.couchbase.lite.Mapper; //导入方法依赖的package包/类
public void testSimpleJavaScriptView() {
Map doc = new HashMap();
doc.put("_id", "foo");
Mapper map = viewCompiler.compileMap("function(doc){emit(doc._id,null);}", "javascript");
map.map(doc, emiter);
assertEquals(1, emiter.count());
assertEquals(new EmitPair("foo", null), emiter.get(0));
}
示例6: testRealJavaScriptDesignDocument
import com.couchbase.lite.Mapper; //导入方法依赖的package包/类
public void testRealJavaScriptDesignDocument() {
Map<String, Object> doc1 = new HashMap<String, Object>();
doc1.put("_id", "doc1");
List<String> cat1 = new ArrayList<String>();
cat1.add("apple");
cat1.add("bannana");
doc1.put("categories", cat1);
Map<String, Object> doc2 = new HashMap<String, Object>();
doc2.put("_id", "doc2");
List<String> cat2 = new ArrayList<String>();
cat2.add("clock");
cat2.add("dill");
doc2.put("categories", cat2);
Map<String, Object> doc3 = new HashMap<String, Object>();
doc3.put("_id", "doc3");
List<String> cat3 = new ArrayList();
cat3.add("elephant");
cat3.add("fun");
cat3.add("apple");
doc3.put("categories", cat3);
Mapper map = viewCompiler.compileMap("function(doc) { if (doc.categories) { for (i in doc.categories) { emit(doc.categories[i], 1); } } }", "javascript");
map.map(doc1, emiter);
map.map(doc2, emiter);
map.map(doc3, emiter);
assertEquals(7, emiter.count());
assertEquals(new EmitPair("apple", 1.0), emiter.get(0));
assertEquals(new EmitPair("bannana", 1.0), emiter.get(1));
assertEquals(new EmitPair("clock", 1.0), emiter.get(2));
assertEquals(new EmitPair("dill", 1.0), emiter.get(3));
assertEquals(new EmitPair("elephant", 1.0), emiter.get(4));
assertEquals(new EmitPair("fun", 1.0), emiter.get(5));
assertEquals(new EmitPair("apple", 1.0), emiter.get(6));
}
示例7: testJavaScriptDesignDocumentThatDealsWithArrays
import com.couchbase.lite.Mapper; //导入方法依赖的package包/类
public void testJavaScriptDesignDocumentThatDealsWithArrays() {
Map<String, Object> doc1 = new HashMap<String, Object>();
doc1.put("_id", "doc1");
List<String> producers1 = new ArrayList<String>();
producers1.add("abc");
doc1.put("producers", producers1);
doc1.put("collection", "product");
Mapper map = viewCompiler.compileMap("function(doc) { if ('product' === doc.collection && doc.producers) { doc.producers.forEach(function(each) { emit(each, doc); }); } }", "javascript");
map.map(doc1, emiter);
assertEquals(1, emiter.count());
assertEquals(new EmitPair("abc", doc1), emiter.get(0));
}
示例8: testShouldLeaveOutDocumentsWhenMapBlockThrowsAnException
import com.couchbase.lite.Mapper; //导入方法依赖的package包/类
public void testShouldLeaveOutDocumentsWhenMapBlockThrowsAnException() {
Map<String, Object> doc1 = new HashMap<String, Object>();
doc1.put("_id", "good");
Map<String, Object> doc2 = new HashMap<String, Object>();
doc2.put("_id", "bad");
Mapper map = viewCompiler.compileMap("function(doc) { if (doc._id === 'bad') throw new Error('gotcha!'); emit(1, doc); }", "javascript");
map.map(doc1, emiter);
map.map(doc2, emiter);
assertEquals(1, emiter.count());
assertEquals(new EmitPair(1.0, doc1), emiter.get(0));
}
示例9: testShouldReturnEmptyViewIfJavaScriptIsErranous
import com.couchbase.lite.Mapper; //导入方法依赖的package包/类
public void testShouldReturnEmptyViewIfJavaScriptIsErranous() {
Map<String, Object> doc1 = new HashMap<String, Object>();
doc1.put("_id", "good");
Mapper map = viewCompiler.compileMap("function(doc) { }", "javascript");
map.map(doc1, emiter);
assertEquals(0, emiter.count());
}