Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,20 @@ public static boolean isUnchangedStructure(
{
final PersistenceTypeDefinitionMember legacyMember = legacy.next() ;
final PersistenceTypeDefinitionMember currentMember = current.next();

// all legacy members must be directly mapped to their order-wise corresponding current member.
if(mapping.get(legacyMember) != currentMember)
final Similarity<PersistenceTypeDefinitionMember> match = mapping.get(legacyMember);
if(match == null || match.targetElement() != currentMember)
{
return false;
}

// and the types must be the same, of course. Member names are sound and smoke.
if(!legacyMember.typeName().equals(currentMember.typeName()))

// the persistent layout of the two members must match. equalsLayout handles every
// member kind (regular fields, primitive definitions, enum constants, complex generic
// fields) via polymorphic dispatch and intentionally ignores member names: the
// mapping/order check above already establishes identity, so a renamed-but-otherwise-
// unchanged member still qualifies for the unchanged-structure fast path.
if(!legacyMember.equalsLayout(currentMember))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,37 @@ public default boolean equalsDescription(final PersistenceTypeDescriptionMember
/**
* Structure means equal order of members by type name and simple name.<br>
* Not qualifier, since that is only required for intra-type field identification
*
*
* @param other the description to compare to
* @return if this and the other description's structure are equal
*
* @see #equalDescription(PersistenceTypeDescriptionMember, PersistenceTypeDescriptionMember)
*
* @see #equalStructure(PersistenceTypeDescriptionMember, PersistenceTypeDescriptionMember)
*/
public default boolean equalsStructure(final PersistenceTypeDescriptionMember other)
{
return equalTypeAndName(this, other);
}

/**
* Like {@link #equalsStructure(PersistenceTypeDescriptionMember)} but ignores the member's
* simple name. Compares only the persistent layout (type name; for primitive-definition members
* the bit-layout descriptor; for complex generic fields the nested members compared again by
* layout).
* <p>
* Used by the "unchanged structure" fast path in legacy-handler creation, where the identity
* correspondence between legacy and current members is already established by the refactoring
* mapping and only the on-disk layout needs to be confirmed &mdash; e.g. a renamed field whose
* type and offset are unchanged still produces the same persisted bytes.
*
* @param other the description to compare to.
* @return if this and the other description's persistent layout are equal.
*
* @see #equalLayout(PersistenceTypeDescriptionMember, PersistenceTypeDescriptionMember)
*/
public default boolean equalsLayout(final PersistenceTypeDescriptionMember other)
{
return other != null && Objects.equals(this.typeName(), other.typeName());
}

/**
* Tests whether two members have the same {@link #typeName()} and {@link #name()}. The comparison
Expand Down Expand Up @@ -203,6 +224,25 @@ public static boolean equalStructure(
// must delegate to the implementation since complex fields must deep-check their nested fields
return m1 == m2 || m1 != null && m1.equalsStructure(m2);
}

/**
* Static null-safe counterpart to {@link #equalsLayout(PersistenceTypeDescriptionMember)}.
* Delegation to the instance method is required so that complex (nested) member descriptions
* can deep-check their nested members by layout.
*
* @param m1 the first member.
* @param m2 the second member.
*
* @return {@code true} if both members have equal persistent layout.
*/
public static boolean equalLayout(
final PersistenceTypeDescriptionMember m1,
final PersistenceTypeDescriptionMember m2
)
{
// must delegate to the implementation since complex fields must deep-check their nested fields
return m1 == m2 || m1 != null && m1.equalsLayout(m2);
}

/**
* Static counterpart to {@link #equalsDescription(PersistenceTypeDescriptionMember)} that handles a
Expand Down Expand Up @@ -529,6 +569,23 @@ public static boolean equalStructures(
return equalMembers(members1, members2, PersistenceTypeDescriptionMember::equalStructure);
}

/**
* Pairwise compares two member sequences using
* {@link #equalLayout(PersistenceTypeDescriptionMember, PersistenceTypeDescriptionMember)}.
*
* @param members1 the first sequence.
* @param members2 the second sequence.
*
* @return {@code true} if the sequences are pairwise equal in persistent layout.
*/
public static boolean equalLayouts(
final XGettingSequence<? extends PersistenceTypeDescriptionMember> members1,
final XGettingSequence<? extends PersistenceTypeDescriptionMember> members2
)
{
return equalMembers(members1, members2, PersistenceTypeDescriptionMember::equalLayout);
}

/**
* Pairwise iterates two member sequences in lock-step and applies the passed {@link Equalator} to
* every pair. The iteration intentionally proceeds while <i>either</i> iterator has elements, padding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public default boolean equalsStructure(final PersistenceTypeDescriptionMember ot
&& equalName(this, (PersistenceTypeDescriptionMemberEnumConstant)other)
;
}

@Override
public default boolean equalsLayout(final PersistenceTypeDescriptionMember other)
{
// enum-constant entries have no layout footprint (length 0); identity lives in name().
// Callers that pair members by mapping/order already establish identity correspondence,
// so layout equality here only confirms both members are enum-constant entries.
return other instanceof PersistenceTypeDescriptionMemberEnumConstant;
}

@Override
public default boolean equalsDescription(final PersistenceTypeDescriptionMember member)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ public default boolean equalsStructure(final PersistenceTypeDescriptionMember ot
)
;
}

@Override
public default boolean equalsLayout(final PersistenceTypeDescriptionMember other)
{
return PersistenceTypeDescriptionMemberFieldGenericVariableLength.super.equalsLayout(other)
&& other instanceof PersistenceTypeDescriptionMemberFieldGenericComplex
&& PersistenceTypeDescriptionMember.equalLayouts(
this.members(),
((PersistenceTypeDescriptionMemberFieldGenericComplex)other).members()
)
;
}

/**
* Type-specific overload of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public default boolean equalsStructure(final PersistenceTypeDescriptionMember ot
&& PersistenceTypeDescriptionMemberFieldGeneric.super.equalsStructure(other)
;
}

@Override
public default boolean equalsLayout(final PersistenceTypeDescriptionMember other)
{
// the type check is the only specific thing here.
return other instanceof PersistenceTypeDescriptionMemberFieldGenericVariableLength
&& PersistenceTypeDescriptionMemberFieldGeneric.super.equalsLayout(other)
;
}

/**
* Type-specific overload of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ public default boolean equalsDescription(final PersistenceTypeDescriptionMember
&& equalDescription(this, (PersistenceTypeDescriptionMemberPrimitiveDefinition)member)
;
}

@Override
public default boolean equalsLayout(final PersistenceTypeDescriptionMember other)
{
// primitive-definition members carry a null typeName; identity lives in primitiveDefinition().
return other instanceof PersistenceTypeDescriptionMemberPrimitiveDefinition
&& Objects.equals(
this.primitiveDefinition(),
((PersistenceTypeDescriptionMemberPrimitiveDefinition)other).primitiveDefinition()
)
;
}

/**
* Tests whether two primitive-definition entries record the same {@link #primitiveDefinition()}
Expand Down
Loading