Last active
February 28, 2020 12:21
-
-
Save antonarhipov/d44e73e725bc02f49c736a5c0a821ee7 to your computer and use it in GitHub Desktop.
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
// Initialization-on-demand holder implementation of a lazy singleton | |
public class Something { | |
private Something() {} | |
private static class LazyHolder { | |
static final Something INSTANCE = new Something(); | |
} | |
public static Something getInstance() { | |
return LazyHolder.INSTANCE; | |
} | |
} | |
// Filtering positive integers | |
List<Integer> positiveNumbers = | |
integers.stream().filter(i -> i > 0).collect(Collectors.toList()); | |
// Simple POJO | |
public class CustomerX { | |
private final String name; | |
private final String email; | |
private final String company; | |
public CustomerX(@NotNull String name, @NotNull String email, @NotNull String company) { | |
this.name = name; | |
this.email = email; | |
this.company = company; | |
} | |
@Override | |
public boolean equals(Object o) { | |
if (this == o) return true; | |
if (o == null || getClass() != o.getClass()) return false; | |
CustomerX customer = (CustomerX) o; | |
return name.equals(customer.name) && | |
email.equals(customer.email) && | |
company.equals(customer.company); | |
} | |
@Override | |
public int hashCode() { | |
return Objects.hash(name, email, company); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment