Skip to content

Commit

Permalink
Extend by convenience methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Apr 29, 2017
1 parent e6cc1ba commit 4ab4ebd
Showing 1 changed file with 53 additions and 2 deletions.
Expand Up @@ -8,8 +8,10 @@

/**
* Convenience for providing several checks with a lazy-init handle for fetching
* queued flying packets. Future concept should be somehow linking follow-up
* packets (flying->dig) to each other...
* queued flying packets. Typical use means only fetching this, if really
* necessary, so isFlyingQueueFetched() returns false, if a default or current
* position/look has passed checks. Future concept should be somehow linking
* follow-up packets (flying->dig) to each other...
*
* @author asofold
*
Expand All @@ -31,8 +33,57 @@ public DataPacketFlying[] getHandle() {
return queue;
}

/**
* Test if the queue has been fetched.
*
* @return
*/
public boolean isFlyingQueueFetched() {
return queue != null;
}

/**
* Get the first index where the element is not null, if not fetched or no
* non-null element is found, -1 is returned.
*
* @return -1 if the queue has not been fetched yet or if all elements are
* null, otherwise the lowest index of a non null element is
* returned.
*/
public int getFirstIndexWithContentIfFetched() {
if (queue == null) {
return -1;
}
else {
for (int i = 0; i < queue.length; i++) {
if (queue[i] != null) {
return i;
}
}
return -1;
}
}

/**
* Get the element at the given index, only if fetched.
*
* @param index
* @return If already feteched, the element at the index is returned,
* otherwiese null is returned.
* @throws ArrayIndexOutOfBoundsException
* If the index is out of range.
*/
public DataPacketFlying getIfFetched(final int index) {
return queue == null ? null : queue[index];
}

/**
* Get the queue size only if fetched - otherwise -1 is returned.
*
* @return Size of the queue if fetched, -1 otherwise.
*/
public int sizeIfFetched() {
return queue == null ? -1 : queue.length;
}

}

0 comments on commit 4ab4ebd

Please sign in to comment.