public class K2hashQueue extends Object implements Closeable
The difference of KeyQueue and Queue: KeyQueue stores references to keys in k2hash database whereas Queue holds any kinds of elements.
Usage Examples. Suppose you want to make a new sorted data collection in a K2hashQueue. You could write this as:
package com.example;
import java.io.IOException;
import java.util.*;
import java.util.stream.*;
import ax.antpick.*;
public class App {
public static void main(String[] args) {
// 1. make a random string array for test
String[] suffleArray = {"e", "b", "d", "a", "c"};
// 2. sort it!
Arrays.sort(suffleArray);
// 3. offer to a Queue
Stream<String> stream = Stream.of(suffleArray);
try (K2hash db = K2hash.of("App.k2h")) {
long handle = db.getHandle();
K2hashQueue queue = K2hashQueue.of(handle);
stream.forEach(s -> { queue.offer(s); });
} catch (IOException ex) {
System.out.println(ex.getMessage());
return;
}
// 4. poll from the Queue
try (K2hash db = K2hash.of("App.k2h")) {
long handle = db.getHandle();
K2hashQueue queue = K2hashQueue.of(handle);
String s = null;
do {
s = queue.poll();
System.out.println(s);
} while (s != null);
} catch (IOException ex) {
System.out.println(ex.getMessage());
return;
}
}
}
| Modifier and Type | Field and Description |
|---|---|
static K2hashAttrPack[] |
DEFAULT_ATTRPACK
Default K2hashAttrPack array is
null. |
static int |
DEFAULT_ATTRPACK_SIZE
Default size of a K2hashAttrPack array is
0. |
static long |
DEFAULT_EXPIRATION_DURATION
Default data expiration duration is
0. |
static boolean |
DEFAULT_FIFO
Default FIFO is
true. |
static String |
DEFAULT_PASS
Default passphrase string is
null. |
static int |
DEFAULT_POSITION
Default position of a peek operation is
0. |
static String |
DEFAULT_PREFIX
Default prefix string is
null. |
static long |
K2H_INVALID_HANDLE
Default k2hash data handle.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(Object obj)
Inserts an element into the tail of this queue.
|
void |
clear()
Removes all of the elements from this collection (optional operation).
|
void |
close()
Free KeyQueueHandle
|
long |
count()
Returns the number of queue.
|
String |
element()
Finds and gets a object from the head of this queue.
|
String |
element(int position)
Finds and gets a object from the head of this queue.
|
long |
getQueueHandle()
Returns a K2hashQueue handle.
|
boolean |
isEmpty()
Returns true if, and only if, queue size is 0.
|
static K2hashQueue |
of(long handle)
Constructs a K2hashQueue instance.
|
static K2hashQueue |
of(long handle,
boolean fifo,
String prefix)
Constructs a K2hashQueue instance.
|
static K2hashQueue |
of(long handle,
boolean fifo,
String prefix,
String pass,
long expirationDuration)
Constructs a K2hashQueue instance.
|
boolean |
offer(Object obj)
Inserts an element into the tail of this queue.
|
String |
peek()
Finds and gets a object at the head of this queue.
|
String |
peek(int position)
Finds and gets a object from the head of this queue.
|
String |
poll()
Finds and gets a object from the head of this queue.
|
void |
print()
Print the objects in this queue.
|
String |
remove()
Finds and removes the object at the top of this queue and returns the object.
|
List<String> |
removeList(long count)
Removes objects from this queue.
|
String |
toString() |
public static final long K2H_INVALID_HANDLE
public static final boolean DEFAULT_FIFO
true.public static final String DEFAULT_PREFIX
null.public static final int DEFAULT_POSITION
0.public static final String DEFAULT_PASS
null.public static final long DEFAULT_EXPIRATION_DURATION
0.public static final K2hashAttrPack[] DEFAULT_ATTRPACK
null.public static final int DEFAULT_ATTRPACK_SIZE
0.public static K2hashQueue of(long handle) throws IOException
handle - a K2hash data handleIOException - if a K2hash data handle is invalidpublic static K2hashQueue of(long handle, boolean fifo, String prefix) throws IOException
handle - a K2hash data handlefifo - true if elements are in a FIFO (first-in-first-out) mannerprefix - a prefix string of this queueIOException - if a K2hash data handle is invalidpublic static K2hashQueue of(long handle, boolean fifo, String prefix, String pass, long expirationDuration) throws IOException
handle - a K2hash data handlefifo - true if elements are in a FIFO (first-in-first-out) mannerprefix - a prefix string of this queuepass - a passphrase string to access dataexpirationDuration - a duration to expire data in secondsIOException - if a K2hash handle is invalidIllegalArgumentException - if an illegal augment existspublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic long getQueueHandle()
public boolean isEmpty()
true if empty false otherwisepublic long count()
public String peek()
public String peek(int position)
position - a position to peek in this queueIllegalArgumentException - if the position is less than zeropublic boolean offer(Object obj)
obj - an object to be inserted to this queuetrue if success false otherwiseIllegalArgumentException - - if arguments are illegal.public String poll()
public boolean add(Object obj)
obj - an object to be inserted into this queuetrue if success false otherwiseNoSuchElementException - - if this queue is emptyIllegalArgumentException - if an illegal augment existspublic String remove()
NoSuchElementException - - if this queue is emptypublic List<String> removeList(long count)
count - the number of objects to be removedNoSuchElementException - - if this queue is emptyIllegalArgumentException - if an illegal augment existspublic String element()
NoSuchElementException - - if this queue is emptypublic String element(int position)
position - position where the data exists in queueNoSuchElementException - - if this queue is emptyIllegalArgumentException - if an illegal augment existspublic void clear()
public void print()
NoSuchElementException - - if this queue is emptyCopyright © 2021. All rights reserved.