List of usage examples for org.apache.commons.lang3.builder CompareToBuilder toComparison
public int toComparison()
builder
has judged the "left-hand" side as less than, greater than, or equal to the "right-hand" side. 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]); }//ww w . java 2 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:io.netlibs.bgp.protocol.capabilities.OutboundRouteFilteringCapability.java
@Override protected int compareToSubclass(Capability other) { OutboundRouteFilteringCapability orc = (OutboundRouteFilteringCapability) other; CompareToBuilder builder = new CompareToBuilder(); builder.append(getAddressFamily(), orc.getAddressFamily()) .append(getSubsequentAddressFamily(), orc.getSubsequentAddressFamily()) .append(getFilters().size(), orc.getFilters().size()); if (builder.toComparison() != 0) return builder.toComparison(); Iterator<ORFType> hSet = getFilters().keySet().iterator(); Iterator<ORFType> oSet = orc.getFilters().keySet().iterator(); while (hSet.hasNext()) { ORFType hType = hSet.next();/* www .ja v a 2s .c o m*/ ORFType oType = oSet.next(); builder.append(hType, oType).append(getFilters().get(hType), orc.getFilters().get(oType)); } return builder.toComparison(); }
From source file:io.netlibs.bgp.rib.Route.java
/** * compare only the network / routeing relevant * //from w ww. ja v a 2s . com * @param o * @return */ public int networkCompareTo(Route o) { CompareToBuilder builder = (new CompareToBuilder()).append(getAddressFamilyKey(), o.getAddressFamilyKey()) .append(getNlri(), o.getNlri()).append(getPathAttributes().size(), o.getPathAttributes().size()) .append(getNextHop(), o.getNextHop()); if (builder.toComparison() == 0) { Iterator<PathAttribute> lit = getPathAttributes().iterator(); Iterator<PathAttribute> rit = o.getPathAttributes().iterator(); while (lit.hasNext()) builder.append(lit.next(), rit.next()); } return builder.toComparison(); }
From source file:io.netlibs.bgp.protocol.attributes.MultiProtocolUnreachableNLRI.java
@Override protected int subclassCompareTo(final PathAttribute obj) { final MultiProtocolUnreachableNLRI o = (MultiProtocolUnreachableNLRI) obj; final CompareToBuilder builer = (new CompareToBuilder()) .append(this.getAddressFamily(), o.getAddressFamily()) .append(this.getSubsequentAddressFamily(), o.getSubsequentAddressFamily()) .append(this.getNlris().size(), o.getNlris().size()); if (builer.toComparison() == 0) { final Iterator<NetworkLayerReachabilityInformation> lit = this.getNlris().iterator(); final Iterator<NetworkLayerReachabilityInformation> rit = o.getNlris().iterator(); while (lit.hasNext()) { builer.append(lit.next(), rit.next()); }/*from w w w . j ava 2s . c om*/ } return builer.toComparison(); }
From source file:io.netlibs.bgp.rib.Route.java
@Override public int compareTo(Route o) { CompareToBuilder builder = (new CompareToBuilder()).append(getAddressFamilyKey(), o.getAddressFamilyKey()) .append(getNlri(), o.getNlri()).append(getPathAttributes().size(), o.getPathAttributes().size()) .append(getNextHop(), o.getNextHop()).append(getRibID(), o.getRibID()); 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 w ww . j av a 2 s . co m*/ return builder.toComparison(); }
From source file:io.netlibs.bgp.protocol.attributes.MultiProtocolReachableNLRI.java
@Override protected int subclassCompareTo(final PathAttribute obj) { final MultiProtocolReachableNLRI o = (MultiProtocolReachableNLRI) obj; final CompareToBuilder builer = (new CompareToBuilder()) .append(this.getAddressFamily(), o.getAddressFamily()) .append(this.getSubsequentAddressFamily(), o.getSubsequentAddressFamily()) .append(this.getNextHop(), o.getNextHop()).append(this.getNlris().size(), o.getNlris().size()); if (builer.toComparison() == 0) { final Iterator<NetworkLayerReachabilityInformation> lit = this.getNlris().iterator(); final Iterator<NetworkLayerReachabilityInformation> rit = o.getNlris().iterator(); while (lit.hasNext()) { builer.append(lit.next(), rit.next()); }// w w w . ja v a 2s. co m } return builer.toComparison(); }
From source file:fr.landel.utils.commons.tuple.Generic.java
/** * <p>// ww w.j a v a 2 s . c om * 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.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)); }// w w w. j a v a 2 s . c om return builder.toComparison(); }
From source file:org.bgp4j.net.attributes.CommunityPathAttribute.java
@Override protected int subclassCompareTo(PathAttribute obj) { CommunityPathAttribute o = (CommunityPathAttribute) obj; CompareToBuilder builder = (new CompareToBuilder()).append(getCommunity(), o.getCommunity()) .append(getMembers().size(), o.getMembers().size()); if (builder.toComparison() == 0) { Iterator<CommunityMember> lit = getMembers().iterator(); Iterator<CommunityMember> rit = o.getMembers().iterator(); while (lit.hasNext()) builder.append(lit.next(), rit.next()); }//from w w w .j a va 2 s . c o m return builder.toComparison(); }
From source file:org.bgp4j.net.attributes.MultiProtocolReachableNLRI.java
@Override protected int subclassCompareTo(PathAttribute obj) { MultiProtocolReachableNLRI o = (MultiProtocolReachableNLRI) obj; CompareToBuilder builer = (new CompareToBuilder()).append(getAddressFamily(), o.getAddressFamily()) .append(getSubsequentAddressFamily(), o.getSubsequentAddressFamily()) .append(getNextHop(), o.getNextHop()).append(getNlris().size(), o.getNlris().size()); if (builer.toComparison() == 0) { Iterator<NetworkLayerReachabilityInformation> lit = getNlris().iterator(); Iterator<NetworkLayerReachabilityInformation> rit = o.getNlris().iterator(); while (lit.hasNext()) builer.append(lit.next(), rit.next()); }//from ww w .j av a 2 s . co m return builer.toComparison(); }