This file contains 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
@Module | |
public class SampleModule { | |
private static final int CONNECT_TIMEOUT = 15; | |
private static final int WRITE_TIMEOUT = 15; | |
private static final int READ_TIMEOUT = 15; | |
private static final String baseUrl; // your base url; | |
@Provides | |
@Singleton | |
Cache provideOkHttpCache(Application application) { |
This file contains 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
@Module | |
public class SampleModule { | |
private static final int CONNECT_TIMEOUT = 15; | |
private static final int WRITE_TIMEOUT = 15; | |
private static final int READ_TIMEOUT = 15; | |
private static final String baseUrl; // your base url; | |
@Provides | |
@Singleton | |
Cache provideOkHttpCache(Application application) { |
This file contains 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
Cart cart = response.getCart(); | |
if (cart != null) { | |
Product product = cart.getProduct(); | |
if (product != null) { | |
System.out.println(product.getName()); | |
} | |
} |
This file contains 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
Optional.ofNullable(response.getCart()).ifPresent(c -> { | |
Optional.ofNullable(c.getProduct()).ifPresent(p -> System.out.println(p.getName())); | |
}); |
This file contains 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
Optional<Cart> optional = Optional.ofNullable(response.getCart()).orElse(new Cart()); | |
Optional<Cart> optional = Optional.ofNullable(response.getCart()).orElseThrow(IllegalStateException::new); |
This file contains 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 (Product product : products) { | |
if (product.getId() == productId) { | |
return product; | |
} | |
} |
This file contains 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
Stream.of(products).filter(p -> p.getId() == productId).findFirst(); |
This file contains 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
Stream.of(products).filter(p -> p.getId() == productId).forEach(Product::printPrice); |
This file contains 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 int sum(int a, int b) { | |
return a + b; | |
} |
This file contains 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
fun sum(a: Int, b: Int): Int { | |
return a + b | |
} |