Skip to content

Commit c666e17

Browse files
authored
Added section on Optional<T> use (#127).
1 parent 3fa9ebf commit c666e17

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ GitLab API for Java (gitlab4j-api) provides a full featured and easy to consume
55

66
---
77

8-
## Java 8 Requirement
9-
As of GitLab4J-API 4.8.0 Java 8+ is now required to use GitLab4J-API.
10-
11-
---
12-
138
To utilize the GitLab API for Java in your project, simply add the following dependency to your project's build file:
149

1510
**Gradle: build.gradle**
@@ -41,6 +36,11 @@ Javadocs are available here: <a href="http://www.messners.com/gitlab4j-api/javad
4136

4237
---
4338

39+
## Java 8 Requirement
40+
As of GitLab4J-API 4.8.0, Java 8+ is now required to use GitLab4J-API.
41+
42+
---
43+
4444
## Using GitLab4J
4545

4646
GitLab4J-API is quite simple to use, all you need is the URL to your GitLab server and the Private Token from your GitLab Account Settings page. Once you have that info it is as simple as:
@@ -93,15 +93,15 @@ while (projectsPager.hasNext())) {
9393
}
9494
}
9595
```
96-
96+
---
97+
## Java 8 Optional&lt;T&gt; Support
98+
GitLab4J-API supports Java 8 Optional&lt;T&gt; for API calls that result in the return of a single item. Here are a couple of examples on how to use the Java 8 Optional&lt;T&gt; API calls:
9799
```java
98-
// Create a Pager instance that will be used to build a list containing all the commits for project ID 1234
99-
Pager<Commit> commitPager = gitlabApi.getCommitsApi().getCommits(1234, 20);
100-
List<Commit> allCommits = new ArrayList<>(commitPager.getTotalItems());
100+
Optional<Group> optionalGroup = gitlabApi.getGroupApi().getGroup("my-group-path");
101+
if (optionalGroup.isPresent())
102+
return optionalGroup.get();
101103

102-
// Iterate through the pages and append each page of commits to the list
103-
while (commitPager.hasNext())
104-
allCommits.addAll(commitPager.next());
104+
return gitlabApi.getGroupApi().addGroup("my-group-name", "my-group-path");
105105
```
106106
---
107107
## Issue Time Estimates

0 commit comments

Comments
 (0)