Example usage for org.apache.commons.lang3.builder CompareToBuilder append

List of usage examples for org.apache.commons.lang3.builder CompareToBuilder append

Introduction

In this page you can find the example usage for org.apache.commons.lang3.builder CompareToBuilder append.

Prototype

public CompareToBuilder append(final boolean[] lhs, final boolean[] rhs) 

Source Link

Document

Appends to the builder the deep comparison of two boolean arrays.

  1. Check if arrays are the same using ==
  2. Check if for null, null is less than non-null
  3. Check array length, a shorter length array is less than a longer length array
  4. Check array contents element by element using #append(boolean,boolean)

Usage

From source file:net.sf.jabb.util.col.IntegerArray.java

/**
 * Compare.<br>/*from   w ww  .  j  a v  a  2s .  co m*/
 * 
 * 
 * @param obj   The object to be compared with
 * @return   -1 if little than obj, 0 if equals, 1 if greater than.
 */
public int compareTo(IntegerArray to) {
    if (to == null || this.values.length > to.values.length) {
        return 1;
    } else if (this.values.length < to.values.length) {
        return -1;
    }

    CompareToBuilder b = new CompareToBuilder();
    for (int i = 0; i < this.values.length; i++) {
        b.append(this.values[i], to.values[i]);
    }
    return b.toComparison();
}

From source file:io.netlibs.bgp.protocol.attributes.PathAttribute.java

@Override
public int compareTo(final PathAttribute o) {
    final CompareToBuilder builder = new CompareToBuilder();

    builder.append(this.internalType(), o.internalType()).append(this.getCategory(), o.getCategory())
            .append(this.isOptional(), o.isOptional()).append(this.isPartial(), o.isPartial())
            .append(this.isTransitive(), o.isTransitive());

    if (this.internalType() == o.internalType()) {
        builder.appendSuper(this.subclassCompareTo(o));
    }// ww  w. j a v a2s  . c  o m

    return builder.toComparison();
}

From source file:net.sf.jabb.util.col.NumberArray.java

/**
 * Compare.<br>/*from www .j  ava 2  s.c  om*/
 * 
 * 
 * @param obj   The object to be compared with
 * @return   -1 if little than obj, 0 if equals, 1 if greater than.
 */
public int compareTo(NumberArray<? extends Number> to) {
    if (to == null || this.values.length > to.values.length) {
        return 1;
    } else if (this.values.length < to.values.length) {
        return -1;
    }

    CompareToBuilder b = new CompareToBuilder();
    for (int i = 0; i < this.values.length; i++) {
        b.append(this.values[i], to.values[i]);
    }
    return b.toComparison();
}

From source file:io.netlibs.bgp.protocol.NetworkLayerReachabilityInformation.java

@Override
public int compareTo(final NetworkLayerReachabilityInformation other) {
    final CompareToBuilder builder = new CompareToBuilder();

    builder.append(this.getPrefixLength(), other.getPrefixLength());

    if (builder.toComparison() == 0) {
        final int byteLen = calculateOctetsForPrefixLength(this.prefixLength);
        final int otherByteLen = calculateOctetsForPrefixLength(other.prefixLength);
        final int commonByteLen = (byteLen > otherByteLen) ? otherByteLen : byteLen;
        final int commonPrefixLen = (this.prefixLength > other.prefixLength) ? other.prefixLength
                : this.prefixLength;

        for (int i = 0; i < (commonByteLen - 1); i++) {
            builder.append(this.getPrefix()[i], other.getPrefix()[i]);
        }//from www  . j a  va2  s.co  m

        if (builder.toComparison() == 0) {
            final int bitsToCheck = commonPrefixLen % 8;

            if (bitsToCheck == 0) {
                if (commonByteLen > 0) {
                    builder.append(this.getPrefix()[commonByteLen - 1], other.getPrefix()[commonByteLen - 1]);
                }
            } else {
                for (int i = 0; i < bitsToCheck; i++) {
                    final int mask = 1 << (7 - i);

                    builder.append(this.getPrefix()[commonByteLen - 1] & mask,
                            other.getPrefix()[commonByteLen - 1] & mask);
                    if (builder.toComparison() != 0) {
                        break;
                    }
                }
            }

            if (builder.toComparison() == 0) {
                builder.append(this.getPrefixLength(), other.getPrefixLength());
            }
        }

    }

    return builder.toComparison();
}

From source file:edu.temple.cis3238.wiki.vo.TopicVO.java

@Override
public int compareTo(TopicVO _that) {
    if (_that == null) {
        return 1;
    }/*from   w w w.  ja v  a2s.  c om*/
    CompareToBuilder ctb = new CompareToBuilder();
    ctb.append(this.getTopicID() > 0, _that.getTopicID() > 0);
    ctb.append(this.getTopicID(), _that.getTopicID());
    ctb.append(this.getTopicName().toLowerCase().trim(), _that.getTopicName().toLowerCase().trim());
    return ctb.build();
}

From source file:com.medlog.webservice.vo.MedicationVO.java

@Override
public int compareTo(MedicationVO that) {
    CompareToBuilder ctb = new CompareToBuilder();
    ctb.append(this.getMedicationID(), that.getMedicationID());
    try {/*w ww.  ja va  2s  .  co  m*/
        ctb.append(this.getPharmID().getPharmID(), that.getPharmID().getPharmID());
    } catch (Exception e) {

    }
    return ctb.build();
}

From source file:io.netlibs.bgp.protocol.attributes.CommunityPathAttribute.java

@Override
protected int subclassCompareTo(final PathAttribute obj) {
    final CommunityPathAttribute o = (CommunityPathAttribute) obj;
    final CompareToBuilder builder = (new CompareToBuilder()).append(this.getMembers().size(),
            o.getMembers().size());// w  w w.  j  a  va 2s .  c o  m

    if (builder.toComparison() == 0) {
        final Iterator<CommunityMember> lit = this.getMembers().iterator();
        final Iterator<CommunityMember> rit = o.getMembers().iterator();

        while (lit.hasNext()) {
            builder.append(lit.next(), rit.next());
        }
    }

    return builder.toComparison();
}

From source file:fr.landel.utils.commons.tuple.Generic.java

/**
 * <p>//from   www  .ja v a 2s  .c  o m
 * Compares the generic based on the elements in order from left to right.
 * The types must be {@code Comparable}.
 * </p>
 * 
 * @param other
 *            the other generic, not null
 * @return negative if this is less, zero if equal, positive if greater,
 *         {@link Integer#MAX_VALUE} if other is {@code null} or has less
 *         elements and {@link Integer#MIN_VALUE} if other has more elements
 */
@Override
public int compareTo(final Generic<T> other) {
    if (other == null) {
        return Integer.MAX_VALUE;
    } else if (other == this) {
        return 0;
    }

    int length = this.getAll().size();
    int otherLength = other.getAll().size();

    if (length > otherLength) {
        return Integer.MAX_VALUE;
    } else if (length < otherLength) {
        return Integer.MIN_VALUE;
    }

    final CompareToBuilder compareBuilder = new CompareToBuilder();

    final Iterator<T> iterator = this.getAll().iterator();
    final Iterator<T> otherIterator = other.getAll().iterator();
    while (iterator.hasNext() && otherIterator.hasNext()) {
        compareBuilder.append(iterator.next(), otherIterator.next());
    }

    return compareBuilder.toComparison();
}

From source file:io.netlibs.bgp.rib.TopologicalTreeSortingKey.java

@Override
public int compareTo(TopologicalTreeSortingKey o) {
    CompareToBuilder builder = (new CompareToBuilder()).append(getAddressFamilyKey(), o.getAddressFamilyKey())
            .append(getPathAttributes().size(), o.getPathAttributes().size());

    if (builder.toComparison() == 0) {
        Iterator<PathAttribute> lit = getPathAttributes().iterator();
        Iterator<PathAttribute> rit = o.getPathAttributes().iterator();

        while (lit.hasNext())
            builder.append(lit.next(), rit.next());
    }/*from  www .jav  a  2  s  .  c  o m*/

    return builder.toComparison();
}

From source file:io.netlibs.bgp.protocol.attributes.ASPathAttribute.java

@Override
protected int subclassCompareTo(PathAttribute obj) {
    ASPathAttribute o = (ASPathAttribute) obj;

    CompareToBuilder builder = (new CompareToBuilder()).append(getAsType(), o.getAsType())
            .append(getPathSegments().size(), o.getPathSegments().size());

    if (builder.toComparison() == 0) {
        Iterator<PathSegment> lit = getPathSegments().iterator();
        Iterator<PathSegment> rit = o.getPathSegments().iterator();

        while (lit.hasNext())
            builder.append(lit.next(), rit.next());
    }// w w  w .j a v  a  2s .c om

    return builder.toComparison();
}