本文整理汇总了Java中android.databinding.ObservableArrayMap类的典型用法代码示例。如果您正苦于以下问题:Java ObservableArrayMap类的具体用法?Java ObservableArrayMap怎么用?Java ObservableArrayMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObservableArrayMap类属于android.databinding包,在下文中一共展示了ObservableArrayMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computableMapElementsAreComputable
import android.databinding.ObservableArrayMap; //导入依赖的package包/类
@Test
public void computableMapElementsAreComputable() throws Exception {
String key = "KEY";
String string1 = "STRING 1";
String string2 = "STRING 2";
StringClass stringClass = new StringClass(string1);
ObservableArrayMap<String, StringClass> strings = new ObservableArrayMap<>();
strings.put(key, stringClass);
ObservableField<String> computedString = Cinder.computeField(()->strings.get(key).element.get(),
Cinder.observable(strings, StringClass.class, "element")).immediate();
assertEquals(computedString.get(), string1);
strings.get(key).element.set(string2);
assertEquals(computedString.get(), string2);
}
示例2: simpleObservesObservableMaps
import android.databinding.ObservableArrayMap; //导入依赖的package包/类
@Test
public void simpleObservesObservableMaps() throws Exception {
String key1 = "KEY 1";
String string1 = "STRING 1";
String string2 = "STRING 2";
String stringMissing = "MISSING";
StringClass stringClass1 = new StringClass(string1);
StringClass stringClass2 = new StringClass(string2);
ObservableArrayMap<String, StringClass> observableMap = new ObservableArrayMap<>();
ObservableField<String> observingString = new ObservableField<>("");
Cinder.observe(()->
observingString.set((observableMap.get(key1) != null) ?
observableMap.get(key1).element.get() : stringMissing),
observableMap);
observableMap.put(key1, stringClass1);
assertEquals(observingString.get(), string1);
observableMap.put(key1, stringClass2);
assertEquals(observingString.get(), string2);
observableMap.remove(key1);
assertEquals(observingString.get(), stringMissing);
}
示例3: stopArrayMapStops
import android.databinding.ObservableArrayMap; //导入依赖的package包/类
@Test
public void stopArrayMapStops() throws Exception {
String string1 = "STRING 1";
String string2 = "STRING 2";
int TEST = 43;
ObservableArrayMap<String, TestClass> observed = new ObservableArrayMap<>();
TestClass testClass = new TestClass();
testClass.number.set(TEST);
observed.put(string1, testClass);
CinderComputable computing = Cinder.observable(observed, TestClass.class, "number").immediate();
CinderInt observing = Cinder.computeInt(()->
observed.get(string1).number.get(), computing).immediate();
assertEquals(TEST, observing.get());
computing.stop();
observed.get(string1).number.set(23);
assertEquals(TEST, observing.get());
observed.put(string2, new TestClass());
assertEquals(TEST, observing.get());
}
示例4: takeTakesCorrectTimes
import android.databinding.ObservableArrayMap; //导入依赖的package包/类
@Test
public void takeTakesCorrectTimes() throws Exception {
String key1 = "KEY 1";
String string1 = "STRING 1";
String string2 = "STRING 2";
String string3 = "STRING 3";
ObservableField<String> observed = new ObservableField<>(string1);
ObservableArrayMap<String, String> observing = Cinder.<String, String>computeArrayMap((list)->{
list.put(key1, observed.get());
}, observed).take(2).immediate();
assertEquals(string1, observing.get(key1));
observed.set(string2);
assertEquals(string2, observing.get(key1));
observed.set(string3);
assertEquals(string2, observing.get(key1));
}
示例5: takeWhileTakesWhileTrue
import android.databinding.ObservableArrayMap; //导入依赖的package包/类
@Test
public void takeWhileTakesWhileTrue() throws Exception {
String badString = "BAD STRING";
String goodString = "GOOD STRING";
String gooderString = "GOODER STRING";
ObservableField<String> observed = new ObservableField<>("");
ObservableArrayMap<String, String> observing = Cinder.<String, String>computeArrayMap((list)->{
list.put(key1, observed.get());
}, observed).takeWhile(()->observed.get().startsWith("GOOD"));
observed.set(goodString);
assertEquals(goodString, observing.get(key1));
observed.set(badString);
assertEquals(goodString, observing.get(key1));
observed.set(gooderString);
assertEquals(goodString, observing.get(key1));
}
示例6: skipWhileSkipsWhileTrue
import android.databinding.ObservableArrayMap; //导入依赖的package包/类
@Test
public void skipWhileSkipsWhileTrue() throws Exception {
String badString = "BAD STRING";
String goodString = "GOOD STRING";
String gooderString = "GOODER STRING";
ObservableField<String> observed = new ObservableField<>("");
ObservableArrayMap<String, String> observing = Cinder.<String, String>computeArrayMap((list)->{
list.put(key1, observed.get());
}, observed).skipWhile(()->observed.get().startsWith("BAD"));
observed.set(badString);
assertEquals(0, observing.size());
observed.set(goodString);
assertEquals(goodString, observing.get(key1));
observed.set(gooderString);
assertEquals(gooderString, observing.get(key1));
}
示例7: main
import android.databinding.ObservableArrayMap; //导入依赖的package包/类
public static void main(String[] args) {
ObservableModel user1 = new ObservableModel();
user1.firstName.set("Google");
int age = user1.age.get();
ObservableArrayMap<String, Object> user2 = new ObservableArrayMap<>();
user2.put("firstName", "Google");
user2.put("lastName", "Inc.");
user2.put("age", 17);
ObservableArrayList<Object> user3 = new ObservableArrayList<>();
user3.add("Google");
user3.add("Inc.");
user3.add(17);
}
示例8: Listener
import android.databinding.ObservableArrayMap; //导入依赖的package包/类
Listener(final ObservableArrayMap<K, V> observableArrayMap,
final Observer<? super ObservableArrayMapOnMapChangeEvent<K, V>> observer) {
this.observableArrayMap = observableArrayMap;
this.onMapChangedCallback =
new ObservableMap.OnMapChangedCallback<ObservableArrayMap<K, V>, K, V>() {
@Override public void onMapChanged(ObservableArrayMap<K, V> observableArrayMap, K key) {
observer.onNext(ObservableArrayMapOnMapChangeEvent.create(observableArrayMap, key));
}
};
}
示例9: mapChange
import android.databinding.ObservableArrayMap; //导入依赖的package包/类
@Test @UiThreadTest public void mapChange() {
final ObservableArrayMap<String, String> observableArrayMap = new ObservableArrayMap<>();
String key = "key";
String value = "value";
ObservableArrayMapOnMapChangeEvent<String, String> next;
RecordingObserver<ObservableArrayMapOnMapChangeEvent<String, String>> o =
new RecordingObserver<>();
RxObservableArrayMap.mapChanges(observableArrayMap).subscribe(o);
o.assertNoMoreEvents();
observableArrayMap.put(key, value);
next = o.takeNext();
assertEquals(observableArrayMap, next.observableArrayMap());
assertEquals(key, next.key());
value = "corrupted";
observableArrayMap.put(key, value);
next = o.takeNext();
assertEquals(observableArrayMap, next.observableArrayMap());
assertEquals(key, next.key());
observableArrayMap.put(key + "2", value + "2");
o.takeNext();
observableArrayMap.remove(key);
next = o.takeNext();
assertEquals(observableArrayMap, next.observableArrayMap());
assertEquals(key, next.key());
observableArrayMap.clear();
next = o.takeNext();
assertEquals(observableArrayMap, next.observableArrayMap());
assertNull(next.key());
o.dispose();
observableArrayMap.put(key, value);
o.assertNoMoreEvents();
}
示例10: computableMapsAreComputable
import android.databinding.ObservableArrayMap; //导入依赖的package包/类
@Test
public void computableMapsAreComputable() throws Exception {
String key1 = "KEY 1";
String key2 = "KEY 2";
String value1 = "VALUE 1";
String value2 = "VALUE 2";
ObservableArrayMap<String, String> strings = new ObservableArrayMap<>();
strings.put(key1, value1);
ObservableInt computedCount = Cinder.computeInt(()->strings.size(),
Cinder.observable(strings)).immediate();
assertEquals(computedCount.get(), 1);
strings.put(key2, value2);
assertEquals(computedCount.get(), 2);
}
示例11: observesObservableMaps
import android.databinding.ObservableArrayMap; //导入依赖的package包/类
@Test
public void observesObservableMaps() throws Exception {
String key1 = "KEY 1";
String string1 = "STRING 1";
String string2 = "STRING 2";
String string3 = "STRING 3";
String stringMissing = "MISSING";
StringClass stringClass1 = new StringClass(string1);
StringClass stringClass2 = new StringClass(string2);
ObservableArrayMap<String, StringClass> observableMap = new ObservableArrayMap<>();
ObservableField<String> observingString = new ObservableField<>("");
Cinder.observe(()->
observingString.set((observableMap.get(key1) != null) ?
observableMap.get(key1).element.get() : stringMissing),
observableMap, StringClass.class, "element");
observableMap.put(key1, stringClass1);
assertEquals(observingString.get(), string1);
observableMap.put(key1, stringClass2);
assertEquals(observingString.get(), string2);
stringClass2.element.set(string3);
assertEquals(observingString.get(), string3);
observableMap.remove(key1);
assertEquals(observingString.get(), stringMissing);
}
示例12: onceTakesOnce
import android.databinding.ObservableArrayMap; //导入依赖的package包/类
@Test
public void onceTakesOnce() throws Exception {
String string1 = "STRING 1";
String string2 = "STRING 2";
ObservableField<String> observed = new ObservableField<>(string1);
ObservableArrayMap<String, String> observing = Cinder.<String, String>computeArrayMap((list)->
list.put(key1, observed.get()), observed).once().immediate();
assertEquals(string1, observing.get(key1));
observed.set(string2);
assertEquals(string1, observing.get(key1));
}
示例13: skipSkipsCorrectTimes
import android.databinding.ObservableArrayMap; //导入依赖的package包/类
@Test
public void skipSkipsCorrectTimes() throws Exception {
String string1 = "STRING 1";
String string2 = "STRING 2";
ObservableField<String> observed = new ObservableField<>();
ObservableArrayMap<String, String> observing = Cinder.<String, String>computeArrayMap((list)->{
list.put(key1, observed.get());
}, observed).skip(1);
observed.set(string1);
assertEquals(0, observing.size());
observed.set(string2);
assertEquals(string2, observing.get(key1));
}
示例14: filterFilters
import android.databinding.ObservableArrayMap; //导入依赖的package包/类
@Test
public void filterFilters() throws Exception {
String badString = "BAD STRING";
String goodString = "GOOD STRING";
ObservableField<String> observed = new ObservableField<>("");
ObservableArrayMap<String, String> observing = Cinder.<String, String>computeArrayMap((list)->{
list.put(key1, observed.get());
}, observed).filter(()->observed.get().startsWith("GOOD"));
observed.set(badString);
assertEquals(0, observing.size());
observed.set(goodString);
assertEquals(goodString, observing.get(key1));
}
示例15: withDefaultAssignsDefault
import android.databinding.ObservableArrayMap; //导入依赖的package包/类
@Test
public void withDefaultAssignsDefault() throws Exception {
String testString = "TEST";
ArrayMap<String, String> defaultValue = new ArrayMap<>();
defaultValue.put(key1, testString);
ObservableArrayMap<String, String> observing = Cinder.<String, String>computeArrayMap((list)->{
}).withDefault(defaultValue);
assertEquals(testString, observing.get(key1));
}