Skip to content

Commit

Permalink
Change setImmutable() method to freeze()
Browse files Browse the repository at this point in the history
It is to emphasize one-way nature of this change and to consolidate
it with the name of the interface (Freezable).

This might be not the last terminological twist here, however.

(cherry picked from commit 7b10132)
  • Loading branch information
mederly committed Jan 23, 2020
1 parent abd65a2 commit 04d7c4e
Show file tree
Hide file tree
Showing 29 changed files with 58 additions and 68 deletions.
Expand Up @@ -57,9 +57,9 @@ public String toString() {
}

@Override
public void setImmutable() {
public void freeze() {
if (expression instanceof Freezable) {
((Freezable) expression).setImmutable();
((Freezable) expression).freeze();
}
}
}
Expand Up @@ -12,5 +12,5 @@
*/
public interface Freezable {

void setImmutable();
void freeze();
}
Expand Up @@ -33,7 +33,7 @@
* @author Radovan Semancik
*/
public interface Item<V extends PrismValue, D extends ItemDefinition> extends Itemable, DebugDumpable, Visitable, PathVisitable,
ParentVisitable, Serializable, Revivable {
ParentVisitable, Serializable, Revivable, Freezable {

/**
* Returns applicable definition.
Expand Down Expand Up @@ -543,8 +543,6 @@ static boolean hasNoValues(Item<?, ?> item) {

boolean isImmutable();

void setImmutable();

void checkImmutability();

@NotNull
Expand Down
Expand Up @@ -338,9 +338,6 @@ static <T extends Containerable> List<PrismContainerValue<T>> toPcvList(List<T>
return rv;
}

@Override
void setImmutable();

@Override
Class<?> getRealClass();

Expand Down
Expand Up @@ -183,7 +183,7 @@ void checkConsistenceInternal(Itemable rootItem, boolean requireDefinitions, boo
ConsistencyCheckScope scope);

@Override
void setImmutable();
void freeze();

PrismObject<O> cloneIfImmutable();

Expand Down
Expand Up @@ -132,7 +132,7 @@ public interface PrismValue extends Visitable, PathVisitable, Serializable, Debu

boolean isImmutable();

void setImmutable();
void freeze();

@Nullable
Class<?> getRealClass();
Expand Down
Expand Up @@ -27,7 +27,7 @@
* @author Radovan Semancik
*
*/
public interface ItemDelta<V extends PrismValue,D extends ItemDefinition> extends Itemable, DebugDumpable, Visitable, PathVisitable, Foreachable<V>, Serializable {
public interface ItemDelta<V extends PrismValue,D extends ItemDefinition> extends Itemable, DebugDumpable, Visitable, PathVisitable, Foreachable<V>, Serializable, Freezable {

ItemName getElementName();

Expand Down Expand Up @@ -353,7 +353,4 @@ public interface ItemDelta<V extends PrismValue,D extends ItemDefinition> extend
void setOriginTypeRecursive(OriginType originType);

boolean isImmutable();

void setImmutable();

}
Expand Up @@ -36,7 +36,7 @@
* @author Radovan Semancik
* @see PropertyDelta
*/
public interface ObjectDelta<O extends Objectable> extends DebugDumpable, Visitable, PathVisitable, Serializable {
public interface ObjectDelta<O extends Objectable> extends DebugDumpable, Visitable, PathVisitable, Serializable, Freezable {

void accept(Visitor visitor, boolean includeOldValues);

Expand Down Expand Up @@ -369,6 +369,4 @@ public FactorOutResultSingle(ObjectDelta<T> remainder, ObjectDelta<T> offspring)
void clear();

boolean isImmutable();

void setImmutable();
}
Expand Up @@ -290,9 +290,9 @@ public String debugDump(int indent) {
}

@Override
public void setImmutable() {
public void freeze() {
if (filterClauseXNode != null) {
filterClauseXNode.setImmutable();
filterClauseXNode.freeze();
}
immutable = true;
}
Expand Down
Expand Up @@ -932,9 +932,9 @@ public boolean isImmutable() {
return immutable;
}

public void setImmutable() {
public void freeze() {
for (V value : getValues()) {
value.setImmutable();
value.freeze();
}
this.immutable = true;
}
Expand Down Expand Up @@ -965,7 +965,7 @@ public Collection<PrismValue> getAllValues(ItemPath path) {

public Item<V,D> createImmutableClone() {
Item<V,D> clone = clone();
clone.setImmutable();
clone.freeze();
return clone;
}

Expand Down
Expand Up @@ -711,7 +711,7 @@ public <IV extends PrismValue,ID extends ItemDefinition,I extends Item<IV,ID>> I
Class<I> type, ID itemDefinition, boolean immutable) throws SchemaException {
I newItem = createDetachedNewItemInternal(name, type, itemDefinition);
if (immutable) {
newItem.setImmutable();
newItem.freeze();
}
return newItem;
}
Expand Down Expand Up @@ -1531,7 +1531,7 @@ public static <T extends Containerable> List<PrismContainerValue<T>> toPcvList(L
}

@Override
public void setImmutable() {
public void freeze() {
// Before freezing this PCV we should initialize it (if needed).
// We assume that this object is NOT shared at this moment.
if (getComplexTypeDefinition() != null && getComplexTypeDefinition().getCompileTimeClass() != null) {
Expand All @@ -1542,9 +1542,9 @@ public void setImmutable() {

// And now let's freeze it; from the bottom up.
for (Item item : items.values()) {
item.setImmutable();
item.freeze();
}
super.setImmutable();
super.freeze();
}

@Override
Expand Down
Expand Up @@ -450,11 +450,11 @@ public void checkConsistenceInternal(Itemable rootItem, boolean requireDefinitio
}

@Override
public void setImmutable() {
public void freeze() {
if (!this.immutable && values.isEmpty()) {
createNewValue();
}
super.setImmutable();
super.freeze();
}

public PrismObject<O> cloneIfImmutable() {
Expand Down
Expand Up @@ -612,22 +612,22 @@ public T getRealValue() {
}

@Override
public void setImmutable() {
public void freeze() {
if (value instanceof Freezable) {
((Freezable) value).setImmutable();
((Freezable) value).freeze();
} else if (value instanceof JaxbVisitable) {
((JaxbVisitable) value).accept(v -> {
if (v instanceof Freezable) {
((Freezable) v).setImmutable();
((Freezable) v).freeze();
}
});
}
if (rawElement != null) {
rawElement.setImmutable();
rawElement.freeze();
}
if (expression != null) {
expression.setImmutable();
expression.freeze();
}
super.setImmutable();
super.freeze();
}
}
Expand Up @@ -222,7 +222,7 @@ public void normalize() {
@Override
public PrismValue createImmutableClone() {
PrismValue clone = clone();
clone.setImmutable();
clone.freeze();
return clone;
}

Expand Down Expand Up @@ -337,7 +337,7 @@ public boolean isImmutable() {
return immutable;
}

public void setImmutable() {
public void freeze() {
this.immutable = true;
}

Expand Down
Expand Up @@ -1826,7 +1826,7 @@ public boolean isImmutable() {
}

@Override
public void setImmutable() {
public void freeze() {
// TODO make this object really immutable (by freezing the collections and the values in them)
this.immutable = true;
}
Expand Down
Expand Up @@ -382,12 +382,12 @@ public boolean isImmutable() {
}

@Override
public void setImmutable() {
public void freeze() {
if (objectToAdd != null) {
objectToAdd.setImmutable();
objectToAdd.freeze();
}
for (ItemDelta<?, ?> modification : modifications) {
modification.setImmutable();
modification.freeze();
}
this.immutable = true;
}
Expand Down
Expand Up @@ -586,8 +586,8 @@ public boolean isImmutable() {
return realContainer.isImmutable();
}

public void setImmutable() {
realContainer.setImmutable();
public void freeze() {
realContainer.freeze();
}

public void checkImmutability() {
Expand Down
Expand Up @@ -492,8 +492,8 @@ public boolean isImmutable() {
return realProperty.isImmutable();
}

public void setImmutable() {
realProperty.setImmutable();
public void freeze() {
realProperty.freeze();
}

public void checkImmutability() {
Expand Down
Expand Up @@ -419,8 +419,8 @@ public boolean isImmutable() {
return realReference.isImmutable();
}

public void setImmutable() {
realReference.setImmutable();
public void freeze() {
realReference.freeze();
}

public void checkImmutability() {
Expand Down
Expand Up @@ -202,10 +202,10 @@ public List<? extends XNode> asList() {
}

@Override
public void setImmutable() {
public void freeze() {
for (XNodeImpl subnode : subnodes) {
subnode.setImmutable();
subnode.freeze();
}
super.setImmutable();
super.freeze();
}
}
Expand Up @@ -330,13 +330,13 @@ public MapXNodeImpl clone() {
}

@Override
public void setImmutable() {
public void freeze() {
for (Map.Entry<QName, XNodeImpl> subnode : subnodes.entrySet()) {
if (subnode.getValue() != null) {
subnode.getValue().setImmutable();
subnode.getValue().freeze();
}
}
super.setImmutable();
super.freeze();
}

// TODO reconsider performance of this method
Expand Down
Expand Up @@ -380,13 +380,13 @@ PrimitiveXNodeImpl<T> cloneInternal() {
}

@Override
public void setImmutable() {
public void freeze() {
if (value instanceof Freezable) {
((Freezable) value).setImmutable();
((Freezable) value).freeze();
}
if (valueParser != null) {
valueParser = valueParser.freeze();
}
super.setImmutable();
super.freeze();
}
}
Expand Up @@ -142,10 +142,10 @@ public RootXNodeImpl toRootXNode() {
}

@Override
public void setImmutable() {
public void freeze() {
if (subnode != null) {
subnode.setImmutable();
subnode.freeze();
}
super.setImmutable();
super.freeze();
}
}
Expand Up @@ -238,7 +238,7 @@ protected void checkMutable() {
}

@Override
public void setImmutable() {
public void freeze() {
immutable = true;
}
}
Expand Up @@ -53,7 +53,7 @@ public void test010SimpleProperty() throws Exception {
PrismPropertyDefinition<String> displayNamePPD = prismContext.getSchemaRegistry().findPropertyDefinitionByElementName(SchemaConstantsGenerated.C_DISPLAY_NAME);
PrismProperty<String> displayNamePP = displayNamePPD.instantiate();
displayNamePP.setRealValue("Big red ball");
displayNamePP.setImmutable();
displayNamePP.freeze();

// THEN
try {
Expand Down Expand Up @@ -85,7 +85,7 @@ public void test020DateProperty() throws Exception {
Date now = new Date();
Date yesterday = new Date(now.getTime()-86400000L);
datePP.setRealValue(XmlTypeConverter.createXMLGregorianCalendar(now));
datePP.setImmutable();
datePP.freeze();

// THEN
try {
Expand Down Expand Up @@ -120,7 +120,7 @@ public void test030Reference() throws Exception {
PrismReferenceDefinition refPRD = prismContext.definitionFactory().createReferenceDefinition(new QName(SchemaConstants.NS_C, "ref"), ObjectReferenceType.COMPLEX_TYPE);
PrismReference refPR = refPRD.instantiate();
refPR.add(ObjectTypeUtil.createObjectRef("oid1", ObjectTypes.USER).asReferenceValue());
refPR.setImmutable();
refPR.freeze();

// THEN
try {
Expand Down Expand Up @@ -163,7 +163,7 @@ public void test100Resource() throws Exception {
businessConfiguration.setAdministrativeState(ResourceAdministrativeStateType.ENABLED);
resource.asObjectable().setBusiness(businessConfiguration);

resource.setImmutable();
resource.freeze();

System.out.println("Resource: " + resource.debugDump());

Expand Down
Expand Up @@ -80,7 +80,7 @@ public void testAccessObjectTemplateMultithreaded() throws Exception {

// WHEN
PrismObject<ObjectTemplateType> template = prismContext.parseObject(OBJECT_TEMPLATE_FILE);
template.setImmutable(); // this is necessary in order to eliminate thread-unsafe DOM value parsers
template.freeze(); // this is necessary in order to eliminate thread-unsafe DOM value parsers
MappingType mapping = template.asObjectable().getMapping().stream()
.filter(m -> "Access role assignment".equals(m.getName()))
.findAny().orElse(null);
Expand Down

0 comments on commit 04d7c4e

Please sign in to comment.