Share
Embed
Transcript
26 slides
-
public final Observable<T> takeLast(long count, long time, TimeUnit unit, Scheduler
scheduler, boolean delayError, int bufferSize) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); if (count < 0) { throw new IndexOutOfBoundsException( "count >= 0 required but it was " + count); } return RxJavaPlugins.onAssembly(new ObservableTakeLastTimed<T>(this, count, time, unit, scheduler, bufferSize, delayError)); } RxJava.Observable -
public final Observable<T> takeLast(long count, long time, TimeUnit unit, Scheduler
scheduler, boolean delayError, int bufferSize) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); if (count < 0) { throw new IndexOutOfBoundsException( "count >= 0 required but it was " + count); } return RxJavaPlugins.onAssembly(new ObservableTakeLastTimed<T>(this, count, time, unit, scheduler, bufferSize, delayError)); } RxJava.Observable -
ࣄલ݅Λද໌͢ΔϝϦοτ • ϝιου༷ͷΘΓʹͳΔ • ίʔυΛΈΔػձ͕ଟ͍߹ʹ༗ޮ • σόοά͕༰қʹͳΔ - ྫ֎Λ͛Δ߹ •
ܖ͕ഁΒΕͨ࣌ʹྫ֎Λ͛ΔͨΊ • ϝιουΛݺͿଆͱݺΕΔଆͷؒͰྖҬΛ໌֬ʹͰ͖Δ • ࣄલ͕݅कΒΕΔલఏͳͷͰඞཁҎ্ͷޚతॲཧΛ͠ͳͯ͘͢Ή -
public void doSomething(String foo) { if (foo == null) {
throw new IllegalArgumentException(""); } if (foo.length() > 100) { throw new IllegalArgumentException(""); } if (state != null) { throw new IllegalStateException(""); } // ... } If-Then-Throw ίʔυྔ͕ଟ͘ෳࡶ هड़తͰͳ͍ -
fun doSomething(foo: String) { requireNotNull(foo) { "" } // ࠓճͷέʔεͰෆཁͰ͋Δ͕
require(foo.length <= 100) { "" } checkNotNull(state) { "" } // ... } Precondition.kt in Kotlin ͪ͜Βͷ΄͏͕ΑΓهड़త -
public void doSomething(String foo) { requireNotNull(foo, ""); require(foo.length() <= 100,
""); checkNotNull(state != null, ""); // ... } PreconditionΛࣗ࡞ -
public final class Precondition { public static <T> T
requireNotNull(T value, String message) { if (value == null) { throw new IllegalArgumentException(message); } return value; } public static <T> void require(boolean condition, String message) { if (!condition) { throw new IllegalArgumentException(message); } } public static <T> T checkNotNull(T value, String message) { if (value == null) { throw new IllegalStateException(message); } return value; } } -
public final class Precondition { public static <T> T
requireNotNull(T value, String message) { if (value == null) { throw new IllegalArgumentException(message); } return value; } public static <T> void require(boolean condition, String message) { if (!condition) { throw new IllegalArgumentException(message); } } public static <T> T checkNotNull(T value, String message) { if (value == null) { throw new IllegalStateException(message); } return value; } } -
public static <T> T requireNotNull(T value, String message) { if
(value == null) { IllegalArgumentException iae = new IllegalArgumentException(message); StackTraceElement[] source = iae.getStackTrace(); StackTraceElement[] updated = new StackTraceElement[source.length - 1]; System.arraycopy(source, 1, updated, 0, updated.length); iae.setStackTrace(updated); throw iae; } return value; } ࢀߟݩ: Crash Fast: AndroidͷΫϥογϡʹର͢ΔSquareͷΞϓϩʔν -
public final Observable<T> takeLast(long count, long time, TimeUnit unit, Scheduler
scheduler, boolean delayError, int bufferSize) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); if (count < 0) { throw new IndexOutOfBoundsException( "count >= 0 required but it was " + count); } return RxJavaPlugins.onAssembly(new ObservableTakeLastTimed<T>(this, count, time, unit, scheduler, bufferSize, delayError)); } RxJava.Observable -
class Foo { private Bar state; void setState(Bar
state) { if (state == null) { throw new IllegalArgumentException("state must not be null."); } this.state = state; } void useState() { if (state == null) { throw new IllegalStateException("setState must be called."); } state.doSomething(); } } -
class Foo { private Bar state; void setState(Bar
state) { if (state == null) { throw new IllegalArgumentException("state must not be null."); } this.state = state; } void useState() { if (state == null) { throw new IllegalStateException("setState must be called."); } state.doSomething(); } } -
• ϥΠϒϥϦ • ࣄલ݅ͷද໌͕ͦͷ··༷ʹͳΓಘΔ • ঢ়ଶΛͭΫϥε • Πϯελϯε͕ෆਖ਼ͳঢ়ଶʹͳΔͷΛ͙ • σόοάΛ༰қʹ͢Δ
• υϝΠϯϞσϧ • ϏδωεϧʔϧΛຬͨͨ͢Ί -
final class EmailAddress { private final String address;
EmailAddress(String address) { if (address == null) { throw new IllegalArgumentException(); } if (address.length() == 0) { throw new IllegalArgumentException(); } if (address.length() > 100) { throw new IllegalArgumentException(); } if (!Pattern.matches("regex", address)) { throw new IllegalArgumentException(); } this.address = address; } } Ҿ༻ݩ: ࣮ફυϝΠϯۦಈઃܭ[5.3] -
• ϥΠϒϥϦ • ࣄલ݅ͷද໌͕ͦͷ··༷ʹͳΓಘΔ • ঢ়ଶΛͭΫϥε • Πϯελϯε͕ෆਖ਼ͳঢ়ଶʹͳΔͷΛ͙ • σόοάΛ༰қʹ͢Δ
• υϝΠϯϞσϧ • ϏδωεϧʔϧΛຬͨͨ͢Ί -
ࢀߟจݙɾࢿྉ • ΦϒδΣΫτࢦೖ ୈ2൛ ݪଇɾίϯηϓτ • https://goo.gl/O5M4Z7 • .̣̩̚ͷΤϯλʔϓϥΠζΞϓϦέʔγϣϯΞʔΩςΫνϟ •
https://goo.gl/iYF1DJ • ࣮ફυϝΠϯۦಈઃܭ • https://goo.gl/rxmrnC • Crash Fast: AndroidͷΫϥογϡʹର͢ΔSquareͷΞϓϩʔν • https://goo.gl/wCJaJW