// Path: src/main/java/com/netflix/nfgraph/OrdinalIterator.java
// public interface OrdinalIterator {
//     
//     /**
//      * This value will be returned from <code>nextOrdinal()</code> after the iteration is completed.
//      */
//     public static final int NO_MORE_ORDINALS = Integer.MAX_VALUE;
//     
//     /**
//      * @return the next ordinal in this set.
//      */
//     public int nextOrdinal();
//     
//     /**
//      * Rewinds this <code>OrdinalIterator</code> to the beginning of the set.
//      */
//     public void reset();
//     
//     /**
//      * Obtain a copy of this <code>OrdinalIterator</code>.  The returned <code>OrdinalIterator</code> will be reset to the beginning of the set.
//      */
//     public OrdinalIterator copy();
//     
//     /**
//      * @return <code>true</code> if the ordinals returned from this set are guaranteed to be in ascending order.  Returns <code>false</code> otherwise.  
//      */
//     public boolean isOrdered();
//     
//     /**
//      * An iterator which always return <code>OrdinalIterator.NO_MORE_ORDINALS</code>
//      */
//     public static final OrdinalIterator EMPTY_ITERATOR = new OrdinalIterator() {
//         @Override public int nextOrdinal() { return NO_MORE_ORDINALS; }
// 
//         @Override public void reset() { }
// 
//         @Override public OrdinalIterator copy() { return this; }
//         
//         @Override public boolean isOrdered() { return true; }
//     };
// 
// }


import java.util.Arrays;
import com.netflix.nfgraph.OrdinalIterator;
/*
 *  Copyright 2013 Netflix, Inc.
 *
 *     Licensed under the Apache License, Version 2.0 (the "License");
 *     you may not use this file except in compliance with the License.
 *     You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *     Unless required by applicable law or agreed to in writing, software
 *     distributed under the License is distributed on an "AS IS" BASIS,
 *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *     See the License for the specific language governing permissions and
 *     limitations under the License.
 *
 */

package com.netflix.nfgraph.build;



/**
 * An implementation of {@link OrdinalIterator} returned for connections in an {@link NFBuildGraph}.
 */
public class NFBuildGraphOrdinalIterator implements OrdinalIterator {
    
    private final int ordinals[];
    
    private int currentPositionInList;
    private int previousOrdinal = Integer.MIN_VALUE;
    
    NFBuildGraphOrdinalIterator(int ordinals[], int size) {
    	this.ordinals = Arrays.copyOfRange(ordinals, 0, size);
    	Arrays.sort(this.ordinals);
    }
    
    private NFBuildGraphOrdinalIterator(int ordinals[]) {
    	this.ordinals = ordinals;
    }
    
    @Override
    public int nextOrdinal() {
        if(previousOrdinal == NO_MORE_ORDINALS)
            return NO_MORE_ORDINALS;
        
// Path: src/main/java/com/netflix/nfgraph/OrdinalIterator.java
// public interface OrdinalIterator {
//     
//     /**
//      * This value will be returned from <code>nextOrdinal()</code> after the iteration is completed.
//      */
//     public static final int NO_MORE_ORDINALS = Integer.MAX_VALUE;
//     
//     /**
//      * @return the next ordinal in this set.
//      */
//     public int nextOrdinal();
//     
//     /**
//      * Rewinds this <code>OrdinalIterator</code> to the beginning of the set.
//      */
//     public void reset();
//     
//     /**
//      * Obtain a copy of this <code>OrdinalIterator</code>.  The returned <code>OrdinalIterator</code> will be reset to the beginning of the set.
//      */
//     public OrdinalIterator copy();
//     
//     /**
//      * @return <code>true</code> if the ordinals returned from this set are guaranteed to be in ascending order.  Returns <code>false</code> otherwise.  
//      */
//     public boolean isOrdered();
//     
//     /**
//      * An iterator which always return <code>OrdinalIterator.NO_MORE_ORDINALS</code>
//      */
//     public static final OrdinalIterator EMPTY_ITERATOR = new OrdinalIterator() {
//         @Override public int nextOrdinal() { return NO_MORE_ORDINALS; }
// 
//         @Override public void reset() { }
// 
//         @Override public OrdinalIterator copy() { return this; }
//         
//         @Override public boolean isOrdered() { return true; }
//     };
// 
// }


// Path: src/main/java/com/netflix/nfgraph/build/NFBuildGraphOrdinalIterator.java
import java.util.Arrays;
import com.netflix.nfgraph.OrdinalIterator;

/*
 *  Copyright 2013 Netflix, Inc.
 *
 *     Licensed under the Apache License, Version 2.0 (the "License");
 *     you may not use this file except in compliance with the License.
 *     You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *     Unless required by applicable law or agreed to in writing, software
 *     distributed under the License is distributed on an "AS IS" BASIS,
 *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *     See the License for the specific language governing permissions and
 *     limitations under the License.
 *
 */

package com.netflix.nfgraph.build;



/**
 * An implementation of {@link OrdinalIterator} returned for connections in an {@link NFBuildGraph}.
 */
public class NFBuildGraphOrdinalIterator implements OrdinalIterator {
    
    private final int ordinals[];
    
    private int currentPositionInList;
    private int previousOrdinal = Integer.MIN_VALUE;
    
    NFBuildGraphOrdinalIterator(int ordinals[], int size) {
    	this.ordinals = Arrays.copyOfRange(ordinals, 0, size);
    	Arrays.sort(this.ordinals);
    }
    
    private NFBuildGraphOrdinalIterator(int ordinals[]) {
    	this.ordinals = ordinals;
    }
    
    @Override
    public int nextOrdinal() {
        if(previousOrdinal == NO_MORE_ORDINALS)
            return NO_MORE_ORDINALS;
        
        int nextOrdinal = nextOrdinalInList();