Example usage for org.springframework.data.mapping PersistentProperty equals

List of usage examples for org.springframework.data.mapping PersistentProperty equals

Introduction

In this page you can find the example usage for org.springframework.data.mapping PersistentProperty equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:com.turbospaces.model.BO.java

/**
 * @return collection of persistent properties sorted in alphabetical order
 *//*from  w  w  w  . jav  a2  s.  c o m*/
public PersistentProperty[] getOrderedProperties() {
    if (orderedProperties == null) {
        final List<PersistentProperty> nonOrderedProperties = Lists.newLinkedList();

        // Potentially non-ordered properties, add to temporary set and then sort
        getOriginalPersistentEntity().doWithProperties(new PropertyHandler() {
            @Override
            public void doWithPersistentProperty(final PersistentProperty persistentProperty) {
                if (!persistentProperty.equals(getOriginalPersistentEntity().getIdProperty())
                        && !persistentProperty.equals(getOptimisticLockVersionProperty())
                        && !persistentProperty.equals(getRoutingProperty()))
                    nonOrderedProperties.add(persistentProperty);
            }
        });

        // sort properties in alphabetical order
        Collections.sort(nonOrderedProperties, new Comparator<PersistentProperty>() {
            @Override
            public int compare(final PersistentProperty o1, final PersistentProperty o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });

        // construct ordered properties lists where idProperty is first and version is second
        List<PersistentProperty> ordered = Lists.newLinkedList();
        if (getOptimisticLockVersionProperty() != null)
            ordered.add(getOptimisticLockVersionProperty());
        if (getRoutingProperty() != null)
            ordered.add(getRoutingProperty());

        // set id field first - we need this optimization to be fast in matchById reading
        ordered.add(getIdIndex(), getIdProperty());
        ordered.addAll(nonOrderedProperties);

        orderedProperties = ordered.toArray(new PersistentProperty[ordered.size()]);
    }
    return orderedProperties;
}