@Test public void singleVersion() { final MigrationRelationship<TestVersionImpl> relationship1_3 = new MigrationRelationship<>( new TestVersionImpl( 1 ), new TestVersionImpl( 3 ) ); final MigrationRelationship<TestVersionImpl> relationship2_3 = new MigrationRelationship<>( new TestVersionImpl( 2 ), new TestVersionImpl( 3 ) ); final MigrationRelationship<TestVersionImpl> current = new MigrationRelationship<>( new TestVersionImpl( 3 ), new TestVersionImpl( 3 ) ); final VersionedMigrationSet<TestVersionImpl> set = new VersionedMigrationSet<>( relationship1_3, relationship2_3, current ); try { set.getMigrationRelationship( 0 ); fail( "I should throw an exception" ); } catch ( IllegalArgumentException iae ) { } MigrationRelationship<TestVersionImpl> migrationRelationship = set.getMigrationRelationship( 1 ); assertEquals( relationship1_3, migrationRelationship ); migrationRelationship = set.getMigrationRelationship( 2 ); assertEquals( relationship2_3, migrationRelationship ); migrationRelationship = set.getMigrationRelationship( 3 ); assertEquals( current, migrationRelationship ); try { set.getMigrationRelationship( 4 ); fail( "I should throw an exception" ); } catch ( IllegalArgumentException iae ) { } }
public MigrationRelationship<T> getMigrationRelationship( final int currentVersion ) { final MigrationRelationship<T> relationship = cacheVersion.get( currentVersion ); if ( relationship != null ) { return relationship; } int lastSpan = Integer.MAX_VALUE; MigrationRelationship<T> toUse = null; for ( MigrationRelationship<T> current : orderedVersions ) { final int newSpan = current.getSpan( currentVersion ); if ( newSpan < lastSpan ) { lastSpan = newSpan; toUse = current; } } if ( lastSpan == Integer.MAX_VALUE ) { throw new IllegalArgumentException( "Could not find a migration version for version " + currentVersion + " min found was " + orderedVersions .get( orderedVersions.size() - 1 ) ); } cacheVersion.put( currentVersion, toUse ); return toUse; }
VersionedMigrationSet { public MigrationRelationship<T> getMigrationRelationship( final int currentVersion ) { final MigrationRelationship<T> relationship = cacheVersion.get( currentVersion ); if ( relationship != null ) { return relationship; } int lastSpan = Integer.MAX_VALUE; MigrationRelationship<T> toUse = null; for ( MigrationRelationship<T> current : orderedVersions ) { final int newSpan = current.getSpan( currentVersion ); if ( newSpan < lastSpan ) { lastSpan = newSpan; toUse = current; } } if ( lastSpan == Integer.MAX_VALUE ) { throw new IllegalArgumentException( "Could not find a migration version for version " + currentVersion + " min found was " + orderedVersions .get( orderedVersions.size() - 1 ) ); } cacheVersion.put( currentVersion, toUse ); return toUse; } }
VersionedMigrationSet { public MigrationRelationship<T> getMigrationRelationship( final int currentVersion ) { final MigrationRelationship<T> relationship = cacheVersion.get( currentVersion ); if ( relationship != null ) { return relationship; } int lastSpan = Integer.MAX_VALUE; MigrationRelationship<T> toUse = null; for ( MigrationRelationship<T> current : orderedVersions ) { final int newSpan = current.getSpan( currentVersion ); if ( newSpan < lastSpan ) { lastSpan = newSpan; toUse = current; } } if ( lastSpan == Integer.MAX_VALUE ) { throw new IllegalArgumentException( "Could not find a migration version for version " + currentVersion + " min found was " + orderedVersions .get( orderedVersions.size() - 1 ) ); } cacheVersion.put( currentVersion, toUse ); return toUse; } VersionedMigrationSet( final MigrationRelationship<T>... migrations ); }
VersionedMigrationSet { public MigrationRelationship<T> getMigrationRelationship( final int currentVersion ) { final MigrationRelationship<T> relationship = cacheVersion.get( currentVersion ); if ( relationship != null ) { return relationship; } int lastSpan = Integer.MAX_VALUE; MigrationRelationship<T> toUse = null; for ( MigrationRelationship<T> current : orderedVersions ) { final int newSpan = current.getSpan( currentVersion ); if ( newSpan < lastSpan ) { lastSpan = newSpan; toUse = current; } } if ( lastSpan == Integer.MAX_VALUE ) { throw new IllegalArgumentException( "Could not find a migration version for version " + currentVersion + " min found was " + orderedVersions .get( orderedVersions.size() - 1 ) ); } cacheVersion.put( currentVersion, toUse ); return toUse; } VersionedMigrationSet( final MigrationRelationship<T>... migrations ); MigrationRelationship<T> getMigrationRelationship( final int currentVersion ); int getMaxVersion(final int currentVersion); }
VersionedMigrationSet { public MigrationRelationship<T> getMigrationRelationship( final int currentVersion ) { final MigrationRelationship<T> relationship = cacheVersion.get( currentVersion ); if ( relationship != null ) { return relationship; } int lastSpan = Integer.MAX_VALUE; MigrationRelationship<T> toUse = null; for ( MigrationRelationship<T> current : orderedVersions ) { final int newSpan = current.getSpan( currentVersion ); if ( newSpan < lastSpan ) { lastSpan = newSpan; toUse = current; } } if ( lastSpan == Integer.MAX_VALUE ) { throw new IllegalArgumentException( "Could not find a migration version for version " + currentVersion + " min found was " + orderedVersions .get( orderedVersions.size() - 1 ) ); } cacheVersion.put( currentVersion, toUse ); return toUse; } VersionedMigrationSet( final MigrationRelationship<T>... migrations ); MigrationRelationship<T> getMigrationRelationship( final int currentVersion ); int getMaxVersion(final int currentVersion);  }