sustain/src/main/java/net/happyonroad/component/core/support/VersionRange.java
public VersionRange restrict( VersionRange restriction ) throws OverConstrainedVersionException {
        List<Restriction> r1 = this.restrictions;
        List<Restriction> r2 = restriction.restrictions;
        List<Restriction> restrictions;
        if ( r1.isEmpty() || r2.isEmpty() )
        {
            restrictions = Collections.emptyList();
        }
        else
        {
            restrictions = intersection( r1, r2 );
        }

        ComponentVersion version = null;
        if ( restrictions.size() > 0 )
        {
            boolean found = false;
            for ( Iterator i = restrictions.iterator(); i.hasNext() && !found; )
            {
                Restriction r = (Restriction) i.next();

                if ( recommendedVersion != null && r.containsVersion( recommendedVersion ) )
                {
                    // if we find the original, use that
                    version = recommendedVersion;
                    found = true;
                }
                else if ( version == null && restriction.getRecommendedVersion() != null &&
                    r.containsVersion( restriction.getRecommendedVersion() ) )
                {
                    // use this if we can, but prefer the original if possible
                    version = restriction.getRecommendedVersion();
                }
            }
        }
        // Either the original or the specified version ranges have no restructions
        else if ( recommendedVersion != null )
        {
            // Use the original recommended version since it exists
            version = recommendedVersion;
        }
        else if (restriction.recommendedVersion != null)
        {
            // Use the recommended version from the specified VersionRange since there is no
            // original recommended version
            version = restriction.recommendedVersion;
        }
        else
        {
            //TODO: the component is null
            throw new OverConstrainedVersionException( "Restricting incompatible version ranges", null );
        }

        return new VersionRange( version, restrictions );
    }
public VersionRange restrict( VersionRange restriction ) throws OverConstrainedVersionException {
        List<Restriction> r1 = this.restrictions;
        List<Restriction> r2 = restriction.restrictions;
        List<Restriction> restrictions;
        if ( r1.isEmpty() || r2.isEmpty() )
        {
            restrictions = Collections.emptyList();
        }
        else
        {
            restrictions = intersection( r1, r2 );
        }

        ComponentVersion version = null;
        if ( restrictions.size() > 0 )
        {
            boolean found = false;
            for ( Iterator i = restrictions.iterator(); i.hasNext() && !found; )
            {
                Restriction r = (Restriction) i.next();

                if ( recommendedVersion != null && r.containsVersion( recommendedVersion ) )
                {
                    // if we find the original, use that
                    version = recommendedVersion;
                    found = true;
                }
                else if ( version == null && restriction.getRecommendedVersion() != null &&
                    r.containsVersion( restriction.getRecommendedVersion() ) )
                {
                    // use this if we can, but prefer the original if possible
                    version = restriction.getRecommendedVersion();
                }
            }
        }
        // Either the original or the specified version ranges have no restructions
        else if ( recommendedVersion != null )
        {
            // Use the original recommended version since it exists
            version = recommendedVersion;
        }
        else if (restriction.recommendedVersion != null)
        {
            // Use the recommended version from the specified VersionRange since there is no
            // original recommended version
            version = restriction.recommendedVersion;
        }
        else
        {
            //TODO: the component is null
            throw new OverConstrainedVersionException( "Restricting incompatible version ranges", null );
        }

        return new VersionRange( version, restrictions );
    }
public VersionRange restrict ( VersionRange restriction ) throws OverConstrainedVersionException { List < Restriction > r1 = this . restrictions ; List < Restriction > r2 = restriction . restrictions ; List < Restriction > restrictions ; if ( r1 . isEmpty ( ) || r2 . isEmpty ( ) ) { restrictions = Collections . emptyList ( ) ; } else { restrictions = intersection ( r1 , r2 ) ; } ComponentVersion version = null ; if ( restrictions . size ( ) > 0 ) { boolean found = false ; for ( Iterator i = restrictions . iterator ( ) ; i . hasNext ( ) && ! found ; ) { Restriction r = ( Restriction ) i . next ( ) ; if ( recommendedVersion != null && r . containsVersion ( recommendedVersion ) ) { // if we find the original, use that version = recommendedVersion ; found = true ; } else if ( version == null && restriction . getRecommendedVersion ( ) != null && r . containsVersion ( restriction . getRecommendedVersion ( ) ) ) { // use this if we can, but prefer the original if possible version = restriction . getRecommendedVersion ( ) ; } } } // Either the original or the specified version ranges have no restructions else if ( recommendedVersion != null ) { // Use the original recommended version since it exists version = recommendedVersion ; } else if ( restriction . recommendedVersion != null ) { // Use the recommended version from the specified VersionRange since there is no // original recommended version version = restriction . recommendedVersion ; } else { //TODO: the component is null throw new OverConstrainedVersionException ( "Restricting incompatible version ranges" , null ) ; } return new VersionRange ( version , restrictions ) ; }
Creates and returns a new <code>VersionRange</code> that is a restriction of this
version range and the specified version range.
<p>
Note: Precedence is given to the recommended version from this version range over the
recommended version from the specified version range.
</p>
@param restriction the <code>VersionRange</code> that will be used to restrict this version
range.
@return the <code>VersionRange</code> that is a restriction of this version range and the
specified version range.
<p>
The restrictions of the returned version range will be an intersection of the restrictions
of this version range and the specified version range if both version ranges have
restrictions. Otherwise, the restrictions on the returned range will be empty.
</p>
<p>
The recommended version of the returned version range will be the recommended version of
this version range, provided that ranges falls within the intersected restrictions. If
the restrictions are empty, this version range's recommended version is used if it is not
<code>null</code>. If it is <code>null</code>, the specified version range's recommended
version is used (provided it is non-<code>null</code>). If no recommended version can be
obtained, the returned version range's recommended version is set to <code>null</code>.
</p>
@throws NullPointerException if the specified <code>VersionRange</code> is
<code>null</code>.
Creates and returns a new <code > VersionRange< / code > that is a restriction of this version range and the specified version range . <p > Note : Precedence is given to the recommended version from this version range over the recommended version from the specified version range . < / p >