static boolean hasNoValues(Item<?, ?> item) { return item == null || item.getValues().isEmpty(); }
private int getValueCount(Object item) { if (item == null) { return 0; } if (!(item instanceof Item)) { throw new IllegalStateException("Expected Item but got " + item.getClass() + " instead"); } return ((Item) item).getValues().size(); }
@NotNull static <V extends PrismValue> Collection<V> getValues(Item<V, ?> item) { return item != null ? item.getValues() : Collections.emptySet(); }
@NotNull private static List<PrismValue> getValues(PrismContainerValue<?> pcv, ItemPath path) { Item<PrismValue, ItemDefinition> item = pcv.findItem(path); return item != null ? item.getValues() : Collections.emptyList(); }
@Nullable private <IV extends PrismValue> IV getSingleParentlessValue(Item<IV, ?> item) { if (item.size() == 0) { return null; } else if (item.size() == 1) { IV value = item.getValues().get(0); value.setParent(null); return value; } else { throw new IllegalStateException("Expected one item value, got " + item.getValues().size() + " while parsing " + item); } }
@Override public Object get(int index) { if (isSchemaless()) { throw new UnsupportedOperationException("Definition-less containers are not supported any more."); } else { if (containerValue != null) { for (Item<?,?> item : containerValue.getItems()) { if (index < item.getValues().size()) { return asElement(item.getValues().get(index)); } else { index -= item.getValues().size(); } } throw new IndexOutOfBoundsException(); } return null; //TODO: is this OK?? } }
@Override public Object remove(int index) { if (isSchemaless()) { throw new UnsupportedOperationException("Definition-less containers are not supported any more."); } else { for (Item<?,?> item: containerValue.getItems()) { if (index < item.getValues().size()) { ((ItemImpl) item).remove(index); } else { index -= item.getValues().size(); } } throw new IndexOutOfBoundsException(); } }
public static String prettyPrint(Item<?, ?> item) { String values = item.getValues().stream() .map(value -> PrettyPrinter.prettyPrint(value)) .collect(Collectors.joining(", ")); return PrettyPrinter.prettyPrint(item.getElementName()) + "={" + values + "}"; }
private Collection findItemValues(Long id, ItemPath path, Collection<PrismContainerValue<V>> cvalues) { if (cvalues == null) { return null; } boolean foundValuesOnPath = false; Collection<PrismValue> subValues = new ArrayList<>(); for (PrismContainerValue<V> cvalue: cvalues) { if (id == null || id.equals(cvalue.getId())) { Item<?,?> item = cvalue.findItem(path); if (item != null) { subValues.addAll(PrismValueCollectionsUtil.cloneCollection(item.getValues())); foundValuesOnPath = true; } } } return foundValuesOnPath ? subValues : null; }
@Override public Long getAssignmentId() { Item<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> any = assignmentIdi.getAnyItem(); return any != null && !any.getValues().isEmpty() ? any.getAnyValue().getId() : null; }
@Override public <T extends Containerable> T getExtensionContainerRealValue(QName containerName) { Item<?, ?> item = getExtensionItem(ItemName.fromQName(containerName)); if (item == null || item.getValues().isEmpty()) { return null; } else { return ((PrismContainer<T>) item).getRealValue(); } }
/** * Merge all the values of other item to this item. */ @Override public void merge(Item<V,D> otherItem) throws SchemaException { for (V otherValue: otherItem.getValues()) { if (!contains(otherValue)) { add((V) otherValue.clone()); } } }
private Item parseItem(RootXNodeImpl root, QName itemName, ItemDefinition itemDefinition) throws SchemaException{ Item<?,?> item; item = prismContext.parserFor(root) .name(itemName) .definition(itemDefinition) .context(prismContext.createParsingContextForAllowMissingRefTypes()) .parseItem(); if (item.getValues().size() < 1 ) { throw new IllegalStateException("No values to search specified for item " + itemName); } return item; }
public static <IV extends PrismValue,ID extends ItemDefinition> List<JAXBElement<RawType>> serializeValueElements(Item<IV,ID> item, String contextDescription) throws SchemaException { if (item == null) { return null; } List<JAXBElement<RawType>> elements = new ArrayList<>(item.size()); for (PrismValue value : item.getValues()) { RootXNode xnode = item.getPrismContext().xnodeSerializer().serialize(value); RawType rawType = new RawType(xnode.getSubnode(), item.getPrismContext()); JAXBElement<RawType> jaxbElement = new JAXBElement<>(SchemaConstants.C_VALUE, RawType.class, rawType); elements.add(jaxbElement); } return elements; }
public static <O extends Objectable> void setDeltaOldValue(PrismObject<O> oldObject, ItemDelta<?,?> itemDelta) { if (oldObject == null) { return; } Item<PrismValue, ItemDefinition> itemOld = oldObject.findItem(itemDelta.getPath()); if (itemOld != null) { itemDelta.setEstimatedOldValues((Collection) PrismValueCollectionsUtil.cloneCollection(itemOld.getValues())); } }
public static void assertParentConsistency(Item<?,?> item) { for (PrismValue pval: item.getValues()) { assert pval.getParent() == item : "Wrong parent of "+pval+" in "+PrettyPrinter.prettyPrint(item.getElementName()); if (pval instanceof PrismContainerValue) { assertParentConsistency((PrismContainerValue)pval); } } }
public static <IV extends PrismValue,ID extends ItemDefinition> PrismValueDeltaSetTriple<IV> toDeltaSetTriple( Item<IV, ID> item, ItemDelta<IV, ID> delta, PrismContext prismContext) { if (item == null && delta == null) { return null; } if (delta == null) { PrismValueDeltaSetTriple<IV> triple = prismContext.deltaFactory().createPrismValueDeltaSetTriple(); triple.addAllToZeroSet(PrismValueCollectionsUtil.cloneCollection(item.getValues())); return triple; } return delta.toDeltaSetTriple(item); }
public boolean isRedundant(PrismObject<? extends Objectable> object, Comparator<V> comparator) { Item<V,D> currentItem = (Item<V,D>) object.findItem(getPath()); if (currentItem == null) { if (valuesToReplace != null) { return valuesToReplace.isEmpty(); } return !hasAnyValue(valuesToAdd); } else { if (valuesToReplace != null) { return MiscUtil.unorderedCollectionCompare(valuesToReplace, currentItem.getValues(), comparator); } ItemDeltaImpl<V,D> narrowed = (ItemDeltaImpl<V, D>) narrow(object, comparator); boolean narrowedNotEmpty = narrowed == null || narrowed.hasAnyValue(narrowed.valuesToAdd) || narrowed.hasAnyValue(narrowed.valuesToDelete); return narrowedNotEmpty; } }
/** * Merges the provided item into this item. The values are joined together. * Returns true if new item or value was added. */ public <IV extends PrismValue,ID extends ItemDefinition> boolean merge(Item<IV,ID> item) throws SchemaException { checkMutability(); Item<IV, ID> existingItem = findItem(item.getElementName(), Item.class); if (existingItem == null) { return add(item); } else { boolean changed = false; for (IV newVal: item.getValues()) { if (existingItem.add((IV) newVal.clone())) { changed = true; } } return changed; } }
private FactorOutResultMulti<O> factorOutValuesForAddDelta(ItemPath path, boolean cloneDelta) { Item<?, ?> item = objectToAdd.findItem(path); if (item == null || item.isEmpty()) { return new FactorOutResultMulti<>(this); } ObjectDeltaImpl<O> remainder = cloneIfRequested(cloneDelta); remainder.getObjectToAdd().remove(item); FactorOutResultMulti<O> rv = new FactorOutResultMulti<>(remainder); for (PrismValue value : item.getValues()) { ObjectDeltaImpl<O> offspring = createOffspring(); offspring.addModification(ItemDeltaUtil.createAddDeltaFor(item, value)); rv.offsprings.add(offspring); } return rv; }