本文整理了Java中com.vmware.xenon.common.Utils.updateCollections()
方法的一些代码示例,展示了Utils.updateCollections()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.updateCollections()
方法的具体详情如下:
包路径:com.vmware.xenon.common.Utils
类名称:Utils
方法名:updateCollections
[英]Adds/removes elements from specified collections; if both are specified elements are removed before new elements added
[中]从指定集合中添加/删除元素;如果两个元素都是指定的,则在添加新元素之前删除它们
代码示例来源:origin: vmware/xenon
/**
* Update the state of collections that are part of the service state
* @param currentState The current state
* @param op Operation with the patch request
* @return
* @throws IllegalAccessException
* @throws NoSuchFieldException
*/
public static <T extends ServiceDocument> boolean mergeWithState(T currentState, Operation op)
throws NoSuchFieldException, IllegalAccessException {
ServiceStateCollectionUpdateRequest collectionUpdateRequest =
op.getBody(ServiceStateCollectionUpdateRequest.class);
if (ServiceStateCollectionUpdateRequest.KIND.equals(collectionUpdateRequest.kind)) {
Utils.updateCollections(currentState, collectionUpdateRequest);
return true;
}
ServiceStateMapUpdateRequest mapUpdateRequest =
op.getBody(ServiceStateMapUpdateRequest.class);
if (ServiceStateMapUpdateRequest.KIND.equals(mapUpdateRequest.kind)) {
Utils.updateMaps(currentState, mapUpdateRequest);
return true;
}
return false;
}
代码示例来源:origin: vmware/xenon
if (ServiceStateCollectionUpdateRequest.KIND.equals(requestBody.kind)) {
result.add(MergeResult.SPECIAL_MERGE);
if (Utils.updateCollections(currentState, requestBody)) {
result.add(MergeResult.STATE_CHANGED);
代码示例来源:origin: vmware/xenon
@Test
public void testCollectionsUpdate() throws Throwable {
MergeTest state = new MergeTest();
state.listOfStrings = new ArrayList<String>();
state.listOfStrings.add(SOME_STRING_VALUE);
state.listOfStrings.add(SOME_OTHER_STRING_VALUE);
state.setOfStrings = new HashSet<String>();
Map<String, Collection<Object>> collectionsToRemove = new HashMap<>();
collectionsToRemove.put("listOfStrings", new ArrayList<>(state.listOfStrings));
Map<String, Collection<Object>> collectionsToAdd = new HashMap<>();
collectionsToRemove.put("listOfStrings", new ArrayList<>(state.listOfStrings));
collectionsToAdd.put("setOfStrings", new ArrayList<>(Arrays.asList(SOME_STRING_VALUE)));
ServiceStateCollectionUpdateRequest request = ServiceStateCollectionUpdateRequest
.create(collectionsToAdd, collectionsToRemove);
boolean changed = Utils.updateCollections(state, request);
assertTrue(changed);
assertEquals(state.listOfStrings.size(), 0);
assertEquals(state.setOfStrings.size(), 1);
// repeating the update should not change the state anymore
changed = Utils.updateCollections(state, request);
assertFalse(changed);
}
代码示例来源:origin: com.vmware.xenon/xenon-common
@Test
public void testCollectionsUpdate() throws Throwable {
MergeTest state = new MergeTest();
state.listOfStrings = new ArrayList<String>();
state.listOfStrings.add(SOME_STRING_VALUE);
state.listOfStrings.add(SOME_OTHER_STRING_VALUE);
state.setOfStrings = new HashSet<String>();
Map<String, Collection<Object>> collectionsToRemove = new HashMap<>();
collectionsToRemove.put("listOfStrings", new ArrayList<>(state.listOfStrings));
Map<String, Collection<Object>> collectionsToAdd = new HashMap<>();
collectionsToRemove.put("listOfStrings", new ArrayList<>(state.listOfStrings));
collectionsToAdd.put("setOfStrings", new ArrayList<>(Arrays.asList(SOME_STRING_VALUE)));
ServiceStateCollectionUpdateRequest request = ServiceStateCollectionUpdateRequest
.create(collectionsToAdd, collectionsToRemove);
boolean changed = Utils.updateCollections(state, request);
assertTrue(changed);
assertEquals(state.listOfStrings.size(), 0);
assertEquals(state.setOfStrings.size(), 1);
// repeating the update should not change the state anymore
changed = Utils.updateCollections(state, request);
assertFalse(changed);
}
内容来源于网络,如有侵权,请联系作者删除!