diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml new file mode 100644 index 00000000..dab69fef --- /dev/null +++ b/.github/workflows/maven-publish.yml @@ -0,0 +1,34 @@ +# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created +# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path + +name: Maven Package + +on: + release: + types: [created] + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + server-id: github # Value of the distributionManagement/repository/id field of the pom.xml + settings-path: ${{ github.workspace }} # location for the settings.xml file + + - name: Build with Maven + run: mvn -B package --file pom.xml + + - name: Publish to GitHub Packages Apache Maven + run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml + env: + GITHUB_TOKEN: ${{ github.token }} diff --git a/README.md b/README.md index 9ee848d5..f5fa67eb 100644 --- a/README.md +++ b/README.md @@ -1,59 +1,6 @@ -Java8InAction -=============== +# README -This repository contains all the source code for the examples and quizzes in the book Java 8 in Action: Lambdas, Streams and functional-style programming. +jdk必须是11 -You can purchase the book here: [http://manning.com/urma/](http://manning.com/urma/) or on Amazon - -The source code for all examples can be found in the directory [src/main/java/lambdasinaction](https://github.com/java8/Java8InAction/tree/master/src/main/java/lambdasinaction) - -* Chapter 1: Java 8: why should you care? -* Chapter 2: Passing code with behavior parameterization -* Chapter 3: Lambda expressions -* Chapter 4: Working with Streams -* Chapter 5: Processing data with streams -* Chapter 6: Collecting data with streams -* Chapter 7: Parallel data processing and performance -* Chapter 8: Refactoring, testing, debugging -* Chapter 9: Default methods -* Chapter 10: Using Optional as a better alternative to null -* Chapter 11: CompletableFuture: composable asynchronous programming -* Chapter 12: New Date and Time API -* Chapter 13: Thinking functionally -* Chapter 14: Functional programming techniques -* Chapter 15: Blending OOP and FP: comparing Java 8 and Scala -* Chapter 16: Conclusions and "where next" for Java -* Appendix A: Miscellaneous language updates -* Appendix B: Miscellaneous library updates -* Appendix C: Performing multiple operations in parallel on a Stream -* Appendix D: Lambdas and JVM bytecode -We will update the repository as we update the book. Stay tuned! - -### Make sure to have JDK8 installed -The latest binary can be found here: http://www.oracle.com/technetwork/java/javase/overview/java8-2100321.html - -$ java -version - -java version "1.8.0_05" -Java(TM) SE Runtime Environment (build 1.8.0_05-b13) -Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode) - - -You can download a preview version here: https://jdk8.java.net/ - -### Compile/Run the examples -Using maven: - -$ mvn compile - -$ cd target/classes - -$ java lambdasinaction/chap1/FilteringApples - - -Alternatively you can compile the files manually inside the directory src/main/java - -You can also import the project in your favorite IDE: - * In IntelliJ use "File->Open" menu and navigate to the folder where the project resides - * In Eclipse use "File->Import->Existing Maven Projects" (also modify "Reduntant super interfaces" to report as Warnings instead of Errors - * In Netbeans use "File->Open Project" menu \ No newline at end of file +tools.jar 没了 +模块化 diff --git a/README_my.md b/README_my.md new file mode 100644 index 00000000..f6ab100d --- /dev/null +++ b/README_my.md @@ -0,0 +1,10 @@ +# README + +## Chap. 1 +- lambdasinaction.chap1.FilteringApples +- java.util.function.Predicate +- java.util.Spliterator +- + + +java.util.function包下面一堆接口 diff --git a/imgs/Predicate.png b/imgs/Predicate.png new file mode 100644 index 00000000..18ddd49d Binary files /dev/null and b/imgs/Predicate.png differ diff --git a/imgs/Spliterator.png b/imgs/Spliterator.png new file mode 100644 index 00000000..46f5e343 Binary files /dev/null and b/imgs/Spliterator.png differ diff --git a/pom.xml b/pom.xml index 10e5035e..487b505a 100644 --- a/pom.xml +++ b/pom.xml @@ -10,6 +10,8 @@ UTF-8 + 11 + 11 @@ -37,8 +39,8 @@ maven-compiler-plugin 3.1 - 1.9 - 1.9 + 11 + 11 diff --git a/src/main/java/lambdasinaction/chap1/FilteringApples.java b/src/main/java/lambdasinaction/chap1/FilteringApples.java index 51afc8cb..5e4c560d 100644 --- a/src/main/java/lambdasinaction/chap1/FilteringApples.java +++ b/src/main/java/lambdasinaction/chap1/FilteringApples.java @@ -1,6 +1,8 @@ package lambdasinaction.chap1; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.function.Predicate; public class FilteringApples{ @@ -9,7 +11,8 @@ public static void main(String ... args){ List inventory = Arrays.asList(new Apple(80,"green"), new Apple(155, "green"), - new Apple(120, "red")); + new Apple(120, "red")); + System.out.println(inventory.getClass().getName());//java.util.Arrays$ArrayList // [Apple{color='green', weight=80}, Apple{color='green', weight=155}] List greenApples = filterApples(inventory, FilteringApples::isGreenApple); @@ -96,6 +99,7 @@ public void setColor(String color) { this.color = color; } + @Override public String toString() { return "Apple{" + "color='" + color + '\'' + diff --git a/src/main/java/lambdasinaction/chap2/FilteringApples.java b/src/main/java/lambdasinaction/chap2/FilteringApples.java index 0f61fd08..c4dd542f 100644 --- a/src/main/java/lambdasinaction/chap2/FilteringApples.java +++ b/src/main/java/lambdasinaction/chap2/FilteringApples.java @@ -1,12 +1,15 @@ package lambdasinaction.chap2; -import java.util.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; public class FilteringApples{ public static void main(String ... args){ - List inventory = Arrays.asList(new Apple(80,"green"), new Apple(155, "green"), new Apple(120, "red")); + List inventory = Arrays.asList(new Apple(80,"green"), new Apple(155, "green"), new Apple(120, "red")); // [Apple{color='green', weight=80}, Apple{color='green', weight=155}] List greenApples = filterApplesByColor(inventory, "green"); diff --git a/src/main/java/lambdasinaction/chap3/README.md b/src/main/java/lambdasinaction/chap3/README.md new file mode 100644 index 00000000..fc15991e --- /dev/null +++ b/src/main/java/lambdasinaction/chap3/README.md @@ -0,0 +1,6 @@ +# + +自定义接口作为参数 + +Comsumer +Functions diff --git a/src/main/java/lambdasinaction/chap4/README.md b/src/main/java/lambdasinaction/chap4/README.md new file mode 100644 index 00000000..ce2b258c --- /dev/null +++ b/src/main/java/lambdasinaction/chap4/README.md @@ -0,0 +1,11 @@ +# + +List to Stream + +Stream的操作 +filter +sort +collect +map +forEach +