本文整理汇总了Java中org.sdnplatform.sync.IVersion.Occurred.BEFORE属性的典型用法代码示例。如果您正苦于以下问题:Java Occurred.BEFORE属性的具体用法?Java Occurred.BEFORE怎么用?Java Occurred.BEFORE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.sdnplatform.sync.IVersion.Occurred
的用法示例。
在下文中一共展示了Occurred.BEFORE属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compare
public int compare(Versioned<S> v1, Versioned<S> v2) {
Occurred occurred = v1.getVersion().compare(v2.getVersion());
if(occurred == Occurred.BEFORE)
return -1;
else if(occurred == Occurred.AFTER)
return 1;
else
return 0;
}
示例2: doput
public boolean doput(K key, Versioned<V> value) throws SyncException {
StoreUtils.assertValidKey(key);
IVersion version = value.getVersion();
while(true) {
List<Versioned<V>> items = map.get(key);
// If we have no value, optimistically try to add one
if(items == null) {
items = new ArrayList<Versioned<V>>();
items.add(new Versioned<V>(value.getValue(), version));
if (map.putIfAbsent(key, items) != null)
continue;
return true;
} else {
synchronized(items) {
// if this check fails, items has been removed from the map
// by delete, so we try again.
if(map.get(key) != items)
continue;
// Check for existing versions - remember which items to
// remove in case of success
List<Versioned<V>> itemsToRemove = new ArrayList<Versioned<V>>(items.size());
for(Versioned<V> versioned: items) {
Occurred occurred = value.getVersion().compare(versioned.getVersion());
if(occurred == Occurred.BEFORE) {
return false;
} else if(occurred == Occurred.AFTER) {
itemsToRemove.add(versioned);
}
}
items.removeAll(itemsToRemove);
items.add(value);
}
return true;
}
}
}