本文整理汇总了Java中com.wm.data.IDataCursor.first方法的典型用法代码示例。如果您正苦于以下问题:Java IDataCursor.first方法的具体用法?Java IDataCursor.first怎么用?Java IDataCursor.first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.wm.data.IDataCursor
的用法示例。
在下文中一共展示了IDataCursor.first方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: remove
import com.wm.data.IDataCursor; //导入方法依赖的package包/类
public final void remove(RemoveEntryOption removeOption) {
Preconditions.checkNotNull(removeOption, "Remove option cannot be null");
IDataCursorResource cursorRes = newCursorResource();
try {
IDataCursor cursor = cursorRes.getCursor();
boolean exists = cursor.first(getKey());
if (!exists && RemoveEntryOption.STRICT.equals(removeOption)) {
throw new InexistentEntryException(
"Entry with key '" + getKey() + "' doesn't exist and can't be removed");
}
deleteCurrentEntry(cursor);
} finally {
cursorRes.close();
}
}
示例2: getKeys
import com.wm.data.IDataCursor; //导入方法依赖的package包/类
public Collection<String> getKeys() {
// Using LinkedHashSet to preserve insertion order
Set<String> keys = new LinkedHashSet<String>();
IDataCursorResource cursorRes = newCursorResource();
try {
IDataCursor cursor = cursorRes.getCursor();
boolean hasMore = cursor.first();
while (hasMore) {
keys.add(cursor.getKey());
hasMore = cursor.next();
}
return Collections.unmodifiableSet(keys);
}
finally {
cursorRes.close();
}
}
示例3: testPut
import com.wm.data.IDataCursor; //导入方法依赖的package包/类
@Test
public void testPut() {
List<String> list = Lists.newArrayList("Hello", "World");
Document doc = docFactory.create();
doc.stringsSplitEntry("words").put(list);
IData iData = doc.getIData();
IDataCursor cursor = iData.getCursor();
assertEquals(2, IDataUtil.size(cursor));
cursor.first();
assertEquals("words", cursor.getKey());
assertEquals("Hello", cursor.getValue());
cursor.next();
assertEquals("words", cursor.getKey());
assertEquals("World", cursor.getValue());
}
示例4: clear
import com.wm.data.IDataCursor; //导入方法依赖的package包/类
/**
* Removes all key value pairs from the given IData document except those with a specified key.
*
* @param document An IData document to be cleared.
* @param keysToBePreserved List of simple or fully-qualified keys identifying items that should not be removed.
*/
public static void clear(IData document, String... keysToBePreserved) {
if (document == null) return;
IData saved = IDataFactory.create();
if (keysToBePreserved != null) {
for (String key : keysToBePreserved) {
if (key != null) put(saved, key, get(document, key), false, false);
}
}
IDataCursor cursor = document.getCursor();
cursor.first();
while (cursor.delete());
cursor.destroy();
if (keysToBePreserved != null) IDataUtil.merge(saved, document);
}
示例5: remove
import com.wm.data.IDataCursor; //导入方法依赖的package包/类
/**
* Removes the given key and its associated value from the given cursor.
*
* @param cursor The cursor to remove the key from.
* @param key The key to be removed.
* @param required Throws an exception if true and a non-null value is not associated with the given key.
* @return The value that was associated with the key.
*/
public static Object remove(IDataCursor cursor, String key, boolean required) {
if (cursor == null || key == null) return null;
Object value = null;
if (cursor.first(key)) {
value = cursor.getValue();
cursor.delete();
}
if (value == null && required) {
throw new RuntimeException(new NoSuchFieldException(MessageFormat.format("Key \"{0}\" either does not exist or is associated with a null value", key)));
}
return value;
}
示例6: get
import com.wm.data.IDataCursor; //导入方法依赖的package包/类
/**
* Returns the value associated with the given key from the IDataCursor.
*
* @param cursor The IDataCursor to add the key value association to.
* @param required Throws an exception if true and a value is not associated with any of the given keys.
* @param keys One or more keys in order of precedence.
* @return The first value found associated with a given key.
*/
public static Object get(IDataCursor cursor, boolean required, String... keys) {
if (cursor == null || keys == null || keys.length == 0 || keys[0] == null) return null;
Object value = null;
for (String key : keys) {
if (key != null) {
if (cursor.first(key)) {
value = cursor.getValue();
}
if (value != null) break;
}
}
if (value == null && required) {
if (keys.length == 1) {
throw new RuntimeException(new NoSuchFieldException(MessageFormat.format("Specified key does not exist or is associated with null value: {0}", keys[0])));
} else {
throw new RuntimeException(new NoSuchFieldException(MessageFormat.format("Specified keys do not exist or are associated with null values: {0}", ArrayHelper.join(keys, Sanitization.REMOVE_NULLS))));
}
}
return value;
}
示例7: add
import com.wm.data.IDataCursor; //导入方法依赖的package包/类
@Test
public void add() throws Exception {
String bandName = "Joy Division";
ElementList<String, Object> band = new CaseInsensitiveElementList<Object>();
band.add(new Element<String, Object>("Name", bandName));
IDataCursor cursor = band.getCursor();
assertEquals("Keys should be case insensitive", bandName, IDataUtil.getString(cursor, "name"));
assertEquals("Keys should be case insensitive", bandName, IDataUtil.getString(cursor, "NAME"));
assertEquals("Keys should be case insensitive", bandName, IDataUtil.getString(cursor, "naME"));
cursor.first();
assertEquals("Keys should have their case preserved", "Name", cursor.getKey());
assertEquals(bandName, cursor.getValue());
}
示例8: doPut
import com.wm.data.IDataCursor; //导入方法依赖的package包/类
private void doPut(Iterable<?> values) {
IDataCursorResource cursorRes = newCursorResource();
try {
IDataCursor cursor = cursorRes.getCursor();
boolean continueLoop;
/* Remove previous entries */
do {
boolean hasValWithKey = cursor.first(getKey());
if (hasValWithKey) {
continueLoop = cursor.delete();
} else {
continueLoop = false;
}
} while (continueLoop);
cursor.last();
for (Object individualVal : values) {
Object normalisedIndividualVal = convertAndNormaliseValForPut(individualVal, mutatorType);
cursor.insertAfter(getKey(), normalisedIndividualVal);
}
} finally {
cursorRes.close();
}
}
示例9: remove
import com.wm.data.IDataCursor; //导入方法依赖的package包/类
@Override
public final void remove(RemoveEntryOption removeOption) {
Preconditions.checkNotNull(removeOption, "Remove option cannot be null");
boolean hasMore;
IDataCursorResource cursorRes = newCursorResource();
try {
IDataCursor cursor = cursorRes.getCursor();
boolean hasFirst = cursor.first(getKey());
if (!hasFirst && RemoveEntryOption.STRICT.equals(removeOption)) {
throw new InexistentEntryException(
"Entry with key '" + getKey() + "' doesn't exist and can't be removed");
}
hasMore = hasFirst;
while (hasMore) {
deleteCurrentEntry(cursor);
hasMore = cursor.first(getKey());
}
} finally {
cursorRes.close();
}
}
示例10: testRemove
import com.wm.data.IDataCursor; //导入方法依赖的package包/类
@Test
public void testRemove() {
IData iData = IDataFactory.create();
{
IDataCursor cursor = iData.getCursor();
cursor.insertAfter("first", "A");
cursor.insertAfter("words", "Word to replace");
cursor.insertAfter("middle", "M");
cursor.insertAfter("words", "Another word to replace");
cursor.insertAfter("last", "Z");
}
Document doc = docFactory.wrap(iData);
doc.stringsSplitEntry("words").remove();
IDataCursor cursor2 = doc.getIData().getCursor();
assertEquals(3, IDataUtil.size(cursor2));
cursor2.first();
assertEquals("first", cursor2.getKey());
assertEquals("A", cursor2.getValue());
cursor2.next();
assertEquals("middle", cursor2.getKey());
assertEquals("M", cursor2.getValue());
cursor2.next();
assertEquals("last", cursor2.getKey());
assertEquals("Z", cursor2.getValue());
}
示例11: drop
import com.wm.data.IDataCursor; //导入方法依赖的package包/类
/**
* Removes the value with the given key from the given IData document.
*
* @param document An IData document.
* @param key A simple or fully-qualified key identifying the value to be removed from the given IData
* document.
* @param literal If true, the key will be treated as a literal key, rather than potentially as a fully-qualified
* key.
* @return The given IData document.
*/
public static IData drop(IData document, String key, boolean literal) {
if (document != null && key != null) {
IDataCursor cursor = document.getCursor();
if (cursor.first(key)) {
cursor.delete();
} else if (IDataKey.isFullyQualified(key, literal)) {
drop(document, IDataKey.of(key, literal));
}
cursor.destroy();
}
return document;
}
示例12: testPutInOrder
import com.wm.data.IDataCursor; //导入方法依赖的package包/类
@Test
public void testPutInOrder() {
List<String> list = Lists.newArrayList("Keep", "Me", "In", "Order");
IData iData = IDataFactory.create();
{
IDataCursor cursor = iData.getCursor();
cursor.insertAfter("first", "A");
cursor.insertAfter("words", "Word to replace");
cursor.insertAfter("middle", "M");
cursor.insertAfter("words", "Another word to replace");
cursor.insertAfter("last", "Z");
}
Document doc = docFactory.wrap(iData);
doc.stringsSplitEntry("words").put(list);
IDataCursor cursor2 = doc.getIData().getCursor();
assertEquals(3+4, IDataUtil.size(cursor2));
cursor2.first();
assertEquals("first", cursor2.getKey());
assertEquals("A", cursor2.getValue());
cursor2.next();
assertEquals("middle", cursor2.getKey());
assertEquals("M", cursor2.getValue());
cursor2.next();
assertEquals("last", cursor2.getKey());
assertEquals("Z", cursor2.getValue());
cursor2.next();
assertEquals("words", cursor2.getKey());
assertEquals("Keep", cursor2.getValue());
cursor2.next();
assertEquals("words", cursor2.getKey());
assertEquals("Me", cursor2.getValue());
cursor2.next();
assertEquals("words", cursor2.getKey());
assertEquals("In", cursor2.getValue());
cursor2.next();
assertEquals("words", cursor2.getKey());
assertEquals("Order", cursor2.getValue());
}
示例13: testPutConvertedInOrder
import com.wm.data.IDataCursor; //导入方法依赖的package包/类
@Test
public void testPutConvertedInOrder() {
List<Integer> list = Lists.newArrayList(4, 3, 2, 1);
IData iData = IDataFactory.create();
{
IDataCursor cursor = iData.getCursor();
cursor.insertAfter("first", "A");
cursor.insertAfter("numbers", "8");
cursor.insertAfter("middle", "M");
cursor.insertAfter("numbers", "9");
cursor.insertAfter("last", "Z");
}
Document doc = docFactory.wrap(iData);
doc.stringsSplitEntry("numbers").putConverted(list);
IDataCursor cursor2 = doc.getIData().getCursor();
assertEquals(3+4, IDataUtil.size(cursor2));
cursor2.first();
assertEquals("first", cursor2.getKey());
assertEquals("A", cursor2.getValue());
cursor2.next();
assertEquals("middle", cursor2.getKey());
assertEquals("M", cursor2.getValue());
cursor2.next();
assertEquals("last", cursor2.getKey());
assertEquals("Z", cursor2.getValue());
cursor2.next();
assertEquals("numbers", cursor2.getKey());
assertEquals("4", cursor2.getValue());
cursor2.next();
assertEquals("numbers", cursor2.getKey());
assertEquals("3", cursor2.getValue());
cursor2.next();
assertEquals("numbers", cursor2.getKey());
assertEquals("2", cursor2.getValue());
cursor2.next();
assertEquals("numbers", cursor2.getKey());
assertEquals("1", cursor2.getValue());
}
示例14: sort
import com.wm.data.IDataCursor; //导入方法依赖的package包/类
/**
* Sorts the given IData document by its keys in natural ascending or descending order.
*
* @param document An IData document to be sorted by its keys.
* @param recurse A boolean which when true will also recursively sort nested IData document and IData[]
* document lists.
* @param descending Whether to sort in descending or ascending order.
* @return A new IData document which is duplicate of the given input IData document but with its keys
* sorted in natural ascending order.
*/
public static IData sort(IData document, boolean recurse, boolean descending) {
if (document == null) return null;
String[] keys = ArrayHelper.sort(getKeys(document), descending);
IData output = IDataFactory.create();
IDataCursor ic = document.getCursor();
IDataCursor oc = output.getCursor();
for (int i = 0; i < keys.length; i++) {
boolean result;
if (i > 0 && keys[i].equals(keys[i - 1])) {
result = ic.next(keys[i]);
} else {
result = ic.first(keys[i]);
}
if (result) {
Object value = ic.getValue();
if (recurse) {
if (value instanceof IData[] || value instanceof Table || value instanceof IDataCodable[] || value instanceof IDataPortable[] || value instanceof ValuesCodable[]) {
IData[] array = toIDataArray(value);
for (int j = 0; j < array.length; j++) {
array[j] = sort(array[j], recurse);
}
value = array;
} else if (value instanceof IData || value instanceof IDataCodable || value instanceof IDataPortable || value instanceof ValuesCodable) {
value = sort(toIData(value), recurse);
}
}
oc.insertAfter(keys[i], value);
}
}
ic.destroy();
oc.destroy();
return output;
}
示例15: put
import com.wm.data.IDataCursor; //导入方法依赖的package包/类
/**
* Associates the given key with the given value in an IDataCursor.
*
* @param cursor The IDataCursor to add the key value association to.
* @param key The key literal to be added.
* @param value The value to be associated with the given key. If null, no change is made to the cursor.
* @param includeNullValue If false and the given value is null, no change is made to the cursor. In all other
* cases the given value will be associated with the given key.
* @param includeEmptyValue If false and the given value is an empty array or empty string, no change is made to the
* cursor. In all other cases the given value will be associated with the given key.
* @param replace If a value is already associated with the given key, replace it, rather than add a new
* instance of the key.
*/
public static void put(IDataCursor cursor, String key, Object value, boolean includeNullValue, boolean includeEmptyValue, boolean replace) {
if (!includeNullValue && value == null) return;
if (!includeEmptyValue && ObjectHelper.isEmpty(value)) return;
if (replace && cursor.first(key)) {
cursor.setValue(value);
} else {
cursor.insertAfter(key, value);
}
}