Skip to content

Commit 67b82f2

Browse files
committed
Merge pull request 'Get source code updated for new package' (#10) from active_mq into main
Reviewed-on: https://src.isharkfly.com/iSharkFly-Docs/java-tutorials/pulls/10
2 parents d52cd0c + 899c4d7 commit 67b82f2

File tree

50 files changed

+1545
-32
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1545
-32
lines changed

.idea/compiler.xml

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core-java-modules/core-java-collections-list-2/README.md

-15
This file was deleted.

core-java-modules/core-java-collections-list/README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@
1212
- [How to Find an Element in a List with Java](http://www.baeldung.com/find-list-element-java)
1313
- [Finding Max/Min of a List or Collection](http://www.baeldung.com/java-collection-min-max)
1414
- [Remove All Occurrences of a Specific Value from a List](https://www.baeldung.com/java-remove-value-from-list)
15-
- [[Next -->]](/core-java-modules/core-java-collections-list-2)
15+
- [Check If Two Lists are Equal in Java](https://www.baeldung.com/java-test-a-list-for-ordinality-and-equality)
16+
- [Java 8 Streams: Find Items From One List Based On Values From Another List](https://www.baeldung.com/java-streams-find-list-items)
17+
- [A Guide to the Java LinkedList](https://www.baeldung.com/java-linkedlist)
18+
- [Java List UnsupportedOperationException](https://www.baeldung.com/java-list-unsupported-operation-exception)
19+
- [Java List Initialization in One Line](https://www.baeldung.com/java-init-list-one-line)
20+
- [Ways to Iterate Over a List in Java](https://www.baeldung.com/java-iterate-list)
21+
- [Flattening Nested Collections in Java](https://www.baeldung.com/java-flatten-nested-collections)
22+
- [Intersection of Two Lists in Java](https://www.baeldung.com/java-lists-intersection)
23+
- [Searching for a String in an ArrayList](https://www.baeldung.com/java-search-string-arraylist)
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ossez.java.list;
1+
package com.ossez.list;
22

33
import java.util.Arrays;
44
import java.util.Iterator;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ossez.array.converter;
1+
package com.ossez.converter;
22

33
import org.junit.Test;
44

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ossez.list.flattennestedlist;
1+
package com.ossez.flattennestedlist;
22

33
import static java.util.Arrays.asList;
44
import static org.junit.Assert.assertNotNull;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Lambdas 函数
2+
3+
本文件夹中包含有所有 Java 相关的 Lambdas 函数及其示例
4+
5+
- [Why Do Local Variables Used in Lambdas Have to Be Final or Effectively Final?](https://www.baeldung.com/java-lambda-effectively-final-local-variables)
6+
- [Java 8 – Powerful Comparison with Lambdas](http://www.baeldung.com/java-8-sort-lambda)
7+
- [Functional Interfaces in Java 8](http://www.baeldung.com/java-8-functional-interfaces)
8+
- [Lambda Expressions and Functional Interfaces: Tips and Best Practices](http://www.baeldung.com/java-8-lambda-expressions-tips)
9+
- [Exceptions in Java 8 Lambda Expressions](http://www.baeldung.com/java-lambda-exceptions)
10+
- [Method References in Java](https://www.baeldung.com/java-method-references)
11+
- [The Double Colon Operator in Java 8](https://www.baeldung.com/java-8-double-colon-operator)
12+
- [Serialize a Lambda in Java](https://www.baeldung.com/java-serialize-lambda)
13+
- [Convert Anonymous Class into Lambda in Java](https://www.baeldung.com/java-from-anonymous-class-to-lambda)
14+
- [When to Use Callable and Supplier in Java](https://www.baeldung.com/java-callable-vs-supplier)

core-java-modules/core-java-collections-list-2/pom.xml renamed to core-java-modules/core-java-lambdas/pom.xml

+4-11
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
6-
<artifactId>core-java-collections-list-2</artifactId>
7-
<version>0.1.0-SNAPSHOT</version>
8-
<name>core-java-collections-list-2</name>
6+
<artifactId>core-java-lambdas</artifactId>
97
<packaging>jar</packaging>
8+
<name>core-java-lambdas</name>
109

1110
<parent>
1211
<groupId>com.ossez.core-java-modules</groupId>
@@ -18,14 +17,8 @@
1817
<dependencies>
1918
<dependency>
2019
<groupId>org.apache.commons</groupId>
21-
<artifactId>commons-collections4</artifactId>
22-
<version>${commons-collections4.version}</version>
23-
</dependency>
24-
<dependency>
25-
<groupId>org.projectlombok</groupId>
26-
<artifactId>lombok</artifactId>
27-
<version>${lombok.version}</version>
28-
<scope>provided</scope>
20+
<artifactId>commons-lang3</artifactId>
21+
<version>${commons-lang3.version}</version>
2922
</dependency>
3023
</dependencies>
3124

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.ossez.doublecolon;
2+
3+
public class Computer {
4+
5+
private Integer age;
6+
private String color;
7+
private Integer healty;
8+
9+
Computer(final int age, final String color) {
10+
this.age = age;
11+
this.color = color;
12+
}
13+
14+
Computer(final Integer age, final String color, final Integer healty) {
15+
this.age = age;
16+
this.color = color;
17+
this.healty = healty;
18+
}
19+
20+
public Computer() {
21+
}
22+
23+
public Integer getAge() {
24+
return age;
25+
}
26+
27+
public void setAge(final Integer age) {
28+
this.age = age;
29+
}
30+
31+
String getColor() {
32+
return color;
33+
}
34+
35+
public void setColor(final String color) {
36+
this.color = color;
37+
}
38+
39+
Integer getHealty() {
40+
return healty;
41+
}
42+
43+
void setHealty(final Integer healty) {
44+
this.healty = healty;
45+
}
46+
47+
public void turnOnPc() {
48+
System.out.println("Computer turned on");
49+
}
50+
51+
public void turnOffPc() {
52+
System.out.println("Computer turned off");
53+
}
54+
55+
public Double calculateValue(Double initialValue) {
56+
return initialValue / 1.50;
57+
}
58+
59+
@Override
60+
public String toString() {
61+
return "Computer{" + "age=" + age + ", color='" + color + '\'' + ", healty=" + healty + '}';
62+
}
63+
64+
@Override
65+
public boolean equals(final Object o) {
66+
if (this == o) {
67+
return true;
68+
}
69+
if (o == null || getClass() != o.getClass()) {
70+
return false;
71+
}
72+
73+
final Computer computer = (Computer) o;
74+
75+
return (age != null ? age.equals(computer.age) : computer.age == null) && (color != null ? color.equals(computer.color) : computer.color == null);
76+
77+
}
78+
79+
@Override
80+
public int hashCode() {
81+
int result = age != null ? age.hashCode() : 0;
82+
result = 31 * result + (color != null ? color.hashCode() : 0);
83+
return result;
84+
}
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.ossez.doublecolon;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import com.ossez.doublecolon.function.ComputerPredicate;
7+
8+
public class ComputerUtils {
9+
10+
static final ComputerPredicate after2010Predicate = (c) -> (c.getAge() > 2010);
11+
static final ComputerPredicate blackPredicate = (c) -> "black".equals(c.getColor());
12+
13+
public static List<Computer> filter(final List<Computer> inventory, final ComputerPredicate p) {
14+
15+
final List<Computer> result = new ArrayList<>();
16+
inventory.stream().filter(p::filter).forEach(result::add);
17+
18+
return result;
19+
}
20+
21+
static void repair(final Computer computer) {
22+
if (computer.getHealty() < 50) {
23+
computer.setHealty(100);
24+
}
25+
}
26+
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.ossez.doublecolon;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import java.util.function.Function;
7+
8+
public class MacbookPro extends Computer {
9+
10+
private static final Logger LOG = LoggerFactory.getLogger(MacbookPro.class);
11+
12+
public MacbookPro(int age, String color) {
13+
super(age, color);
14+
}
15+
16+
MacbookPro(Integer age, String color, Integer healty) {
17+
super(age, color, healty);
18+
}
19+
20+
@Override
21+
public void turnOnPc() {
22+
LOG.debug("MacbookPro turned on");
23+
}
24+
25+
@Override
26+
public void turnOffPc() {
27+
LOG.debug("MacbookPro turned off");
28+
}
29+
30+
@Override
31+
public Double calculateValue(Double initialValue) {
32+
33+
Function<Double, Double> function = super::calculateValue;
34+
final Double pcValue = function.apply(initialValue);
35+
LOG.debug("First value is:" + pcValue);
36+
return pcValue + (initialValue / 10);
37+
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.ossez.doublecolon.function;
2+
3+
import com.ossez.doublecolon.Computer;
4+
5+
@FunctionalInterface
6+
public interface ComputerPredicate {
7+
8+
boolean filter(Computer c);
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.ossez.doublecolon.function;
2+
3+
import java.util.Objects;
4+
import java.util.function.Function;
5+
6+
@FunctionalInterface
7+
public interface TriFunction<A, B, C, R> {
8+
9+
R apply(A a, B b, C c);
10+
11+
default <V> TriFunction<A, B, C, V> andThen(final Function<? super R, ? extends V> after) {
12+
Objects.requireNonNull(after);
13+
return (final A a, final B b, final C c) -> after.apply(apply(a, b, c));
14+
}
15+
}

0 commit comments

Comments
 (0)