com.atlassian.jira.rest.client.api.OptionalIterable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jira-rest-java-client-api Show documentation
Show all versions of jira-rest-java-client-api Show documentation
The public API for JIRA REST Java Client
The newest version!
package com.atlassian.jira.rest.client.api;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Iterator;
/**
* Represent iterable which is optional (for example due to lack of field in old REST API version).
* This iterable is intended to be not null, so you can always get items by using iterator. If you need
* to check if value was actually provided then use {@link OptionalIterable#isSupported}.
*
* @since v1.0
*/
public class OptionalIterable implements Iterable {
@SuppressWarnings("unchecked")
private static final OptionalIterable absentInstance = new OptionalIterable(null);
@Nullable
private final Iterable iterable;
@SuppressWarnings("unchecked")
public static OptionalIterable absent() {
return absentInstance;
}
public OptionalIterable(@Nullable Iterable iterable) {
this.iterable = iterable;
}
/**
* @return iterator for original iterable if {@link OptionalIterable#isSupported} is true,
* or empty iterator in other case.
*/
@Override
public Iterator iterator() {
return isSupported()
? iterable.iterator()
: Collections.emptyList().iterator();
}
/**
* @return true if server supports this field
*/
public boolean isSupported() {
return iterable != null;
}
@Override
public String toString() {
return isSupported() ? iterable.toString() : Collections.emptyList().toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy