Unverified Commit c666e172 authored by Greg Messner's avatar Greg Messner Committed by GitHub
Browse files

Added section on Optional<T> use (#127).

parent 3fa9ebf5
......@@ -5,11 +5,6 @@ GitLab API for Java (gitlab4j-api) provides a full featured and easy to consume
---
## Java 8 Requirement
As of GitLab4J-API 4.8.0 Java 8+ is now required to use GitLab4J-API.
---
To utilize the GitLab API for Java in your project, simply add the following dependency to your project's build file:
**Gradle: build.gradle**
......@@ -41,6 +36,11 @@ Javadocs are available here: <a href="http://www.messners.com/gitlab4j-api/javad
---
## Java 8 Requirement
As of GitLab4J-API 4.8.0, Java 8+ is now required to use GitLab4J-API.
---
## Using GitLab4J
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())) {
}
}
```
---
## Java 8 Optional&lt;T&gt; Support
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:
```java
// Create a Pager instance that will be used to build a list containing all the commits for project ID 1234
Pager<Commit> commitPager = gitlabApi.getCommitsApi().getCommits(1234, 20);
List<Commit> allCommits = new ArrayList<>(commitPager.getTotalItems());
Optional<Group> optionalGroup = gitlabApi.getGroupApi().getGroup("my-group-path");
if (optionalGroup.isPresent())
return optionalGroup.get();
// Iterate through the pages and append each page of commits to the list
while (commitPager.hasNext())
allCommits.addAll(commitPager.next());
return gitlabApi.getGroupApi().addGroup("my-group-name", "my-group-path");
```
---
## Issue Time Estimates
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment