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
Output of `brew install`: | |
~ $ HOMEBREW_MAKE_JOBS=1 VERBOSE=1 brew install rpm 2>&1 | |
==> Installing rpm dependency: rpm2cpio | |
==> Downloading http://svnweb.freebsd.org/ports/head/archivers/rpm2cpio/files/rpm2cpio?revision=259745&view=co | |
Already downloaded: /Library/Caches/Homebrew/rpm2cpio-1.3 | |
Error: rpm2cpio?revision=259745 does not exist | |
~ $ | |
~ $ | |
~ $ |
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 class MyClass { | |
@Configuration("path.prefix") // this is wrong! | |
private static final String PATH_PREFIX = null; | |
private String fileName; | |
public MyClass(String fileName) { | |
this.fileName = PATH_PREFIX + fileName; | |
} | |
} |
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 class MyClass { | |
@Configuration("path.prefix") | |
private String pathPrefix; | |
private String fileName; | |
public MyClass(String fileName) { | |
this.fileName = fileName; //here we simply store it | |
} | |
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 Optional<Integer> max(Collection<Integer> collection) { | |
return collection.stream().max(Integer::max); | |
} | |
// usage | |
List<Integer> list = ...; | |
int m = max(list).orElse(0); |
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 Integer max(Collection<Integer> collection) { | |
if( collection == null || collection.isEmpty() ) return null; | |
Iterator<Integer> i = collection.iterator(); | |
int max = i.next(); | |
while (i.hasNext()) { | |
int n = i.next(); | |
if (max < n) max = n; | |
} | |
return max; | |
} |
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
static class Employee { | |
String firstName; | |
String surname; | |
double salary; //yeah, right! | |
} | |
public Optional<Employee> max(Collection<Employee> collection) { | |
if (collection == null || collection.isEmpty()) return Optional.empty(); | |
Iterator<Employee> employeeIterator = collection.iterator(); |
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
static class Employee { | |
String firstName; | |
String surname; | |
double salary; //yeah, right! | |
} | |
public Optional<Employee> max(Collection<Employee> collection) { | |
return collection.stream().max((e1, e2) -> (int) Math.signum(e1.salary - e2.salary)); | |
} |
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 Collection<Employee> findName(Collection<Employee> collection, String name) { | |
List<Employee> list = new ArrayList<>(); | |
if (collection == null || collection.isEmpty()) return list; | |
for (Employee e : collection) { | |
if (e.firstName.equals(name)) list.add(e); | |
} | |
return list; | |
} | |
// usage |
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
// this returns a list | |
public Collection<Employee> findName(Collection<Employee> collection, String name) { | |
return collection.stream().filter(e -> e.firstName.equals(name)).collect(Collectors.toList()); | |
} | |
// if we want to return a set (and therefore guarantee uniqueness) | |
public Collection<Employee> findName(Collection<Employee> collection, String name) { | |
return collection.stream().filter(e -> e.firstName.equals(name)).collect(Collectors.toList()); | |
} |
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 Collection<Double> extract(Collection<Employee> collection) { | |
Collection<Double> list = new ArrayList<>(); | |
if( collection == null || collection.isEmpty() ) return list; | |
for( Employee e : collection ) { | |
list.add(e.salary); | |
} | |
return list; | |
} |
OlderNewer