This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable.just("Hello, world!") | |
.subscribe(new Action1<String>() { | |
@Override | |
public void call(String s) { | |
System.out.println(s); | |
} | |
}); | |
Observable.just("Hello, world!") | |
.subscribe(s -> System.out.println(s)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// no DI | |
public class Refrigerator { | |
private PowerSource powerSource; | |
public Refrigerator() { | |
powerSource = new AcPowerSource(); | |
} | |
} | |
// with DI (manual) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
private Fragment savedFragment; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
if (savedInstanceState != null) { | |
savedFragment = getSupportFragmentManager().getFragment(savedInstanceState, "content"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Enum<E extends Enum<E>> { ... } | |
<T extends Object & Comparable<? super T>> T Collections.max(Collection<? extends T>) { ... } | |
public <V extends Wrapper<? extends Comparable<T>>> | |
Comparator<V> comparator() { ... } | |
error: equalTo(Box<capture of ?>) in Box<capture of ?> cannot be applied to (Box<capture of ?>) | |
equal = unknownBox.equalTo(unknownBox) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (int i = 0, remaining = 5; i < colorBucket.size() && remaining > 0; i++, remaining--) { | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private <T> int picker(List<T> src, List<T> dst, int limit) { | |
Iterator<T> iterator = src.iterator(); | |
while (iterator.hasNext() && limit > 0) { | |
dst.add(iterator.next()); | |
limit--; | |
} | |
return limit; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Item> allBucket = ... | |
List<Item> genderBucket = ... | |
List<Item> sizeBucket = ... | |
List<Item> colorBucket = ... | |
List<Item> recommendations = new ArrayList<>(); | |
picker(recommendations, limit, colorBucket, sizeBucket, genderBucket, allBucket); | |
private <T> int picker(List<T> src, List<T> dst, int limit) { | |
Iterator<T> iterator = src.iterator(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BehaviorSubject<Integer> timerSubject = BehaviorSubject.create(1); | |
timerSubject | |
.switchMap(interval -> Observable.timer(interval, TimeUnit.SECONDS, Schedulers.newThread())) | |
.flatMap(i -> Observable.just(randomInt())) | |
.doOnNext(timerSubject::onNext) | |
.subscribe(System.out::println); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable.just(1, 2, 3, 4, 5) | |
.groupBy(i -> i % 2 == 0 ? "even" : "odd") | |
.subscribe(obs -> { | |
if (obs.getKey().equals("even")) { | |
obs.subscribe(i -> System.out.println("even: " + i)); | |
} else { | |
obs.subscribe(i -> System.out.println("odd: " + i)); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<android.support.v7.widget.RecyclerView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:padding="16dp" | |
android:clipToPadding="false" /> |
OlderNewer