// 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/OrdinalSet.java
// public abstract class OrdinalSet {
// 
//     /**
//      * Returns <code>true</code> when the specified value is contained in this set.  Depending on the implementation,
//      * this operation will have one of two performance characteristics:<p>
//      * 
//      * <code>O(1)</code> for {@link HashSetOrdinalSet} and {@link BitSetOrdinalSet}<br>
//      * <code>O(n)</code> for {@link CompactOrdinalSet} and {@link NFBuildGraphOrdinalSet}
//      */
//     public abstract boolean contains(int value);
// 	
//     /**
//      * Returns <code>true</code> when all specified values are contained in this set.  Depending on the implementation,
//      * this operation will have one of two performance characteristics:<p>
//      * 
//      * <code>O(m)</code> for {@link HashSetOrdinalSet} and {@link BitSetOrdinalSet}, where <code>m</code> is the number of specified elements.<br>
//      * <code>O(n)</code> for {@link CompactOrdinalSet}, where <code>n</code> is the number of elements in the set.<br>
//      * <code>O(n * m)</code> for {@link NFBuildGraphOrdinalSet}.
//      */
// 	public boolean containsAll(int... values) {
// 		for(int value : values) {
// 			if(!contains(value))
// 				return false;
// 		}
// 		return true;
// 	}
// 	
// 	/**
// 	 * Returns an array containing all elements in the set.
// 	 */
// 	public int[] asArray() {
// 	    int arr[] = new int[size()];
// 	    OrdinalIterator iter = iterator();
// 	    
// 	    int ordinal = iter.nextOrdinal();
// 	    int i = 0;
// 
// 	    while(ordinal != NO_MORE_ORDINALS) {
// 	        arr[i++] = ordinal;
// 	        ordinal = iter.nextOrdinal();
// 	    }
// 	    
// 	    return arr;
// 	}
// 	
// 	/**
// 	 * @return an {@link OrdinalIterator} over this set.
// 	 */
// 	public abstract OrdinalIterator iterator();
// 	
// 	/**
// 	 * @return the number of ordinals in this set.
// 	 */
// 	public abstract int size();
// 
// 	private static final int EMPTY_ORDINAL_ARRAY[] = new int[0];
// 
// 	/**
// 	 * An empty <code>OrdinalSet</code>.
// 	 */
// 	public static final OrdinalSet EMPTY_SET = new OrdinalSet() {
// 		@Override public boolean contains(int value) { return false; }
// 		
// 		@Override public int[] asArray() { return EMPTY_ORDINAL_ARRAY; }
// 
// 		@Override public OrdinalIterator iterator() { return EMPTY_ITERATOR; }
// 
// 		@Override public int size() { return 0; }
// 	};
// }


import java.util.Arrays;
import com.netflix.nfgraph.OrdinalIterator;
import com.netflix.nfgraph.OrdinalSet;
/*
 *  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;



/**
 * And implementation of {@link OrdinalSet} returned for connections in an {@link NFBuildGraph}. 
 */
public class NFBuildGraphOrdinalSet extends OrdinalSet {

	private final int ordinals[];
	private final int size;
	
	public NFBuildGraphOrdinalSet(int ordinals[], int size) {
		this.ordinals = ordinals;
		this.size = size;
	}
	
    /**
     * {@inheritDoc}
     */
	@Override
	public boolean contains(int value) {
		for(int i=0;i<size;i++) {
			if(ordinals[i] == value) {
				return true;
			}
		}
		return false;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public int[] asArray() {
		return Arrays.copyOf(ordinals, size);
	}

    /**
     * {@inheritDoc}
     */
	@Override
// 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/OrdinalSet.java
// public abstract class OrdinalSet {
// 
//     /**
//      * Returns <code>true</code> when the specified value is contained in this set.  Depending on the implementation,
//      * this operation will have one of two performance characteristics:<p>
//      * 
//      * <code>O(1)</code> for {@link HashSetOrdinalSet} and {@link BitSetOrdinalSet}<br>
//      * <code>O(n)</code> for {@link CompactOrdinalSet} and {@link NFBuildGraphOrdinalSet}
//      */
//     public abstract boolean contains(int value);
// 	
//     /**
//      * Returns <code>true</code> when all specified values are contained in this set.  Depending on the implementation,
//      * this operation will have one of two performance characteristics:<p>
//      * 
//      * <code>O(m)</code> for {@link HashSetOrdinalSet} and {@link BitSetOrdinalSet}, where <code>m</code> is the number of specified elements.<br>
//      * <code>O(n)</code> for {@link CompactOrdinalSet}, where <code>n</code> is the number of elements in the set.<br>
//      * <code>O(n * m)</code> for {@link NFBuildGraphOrdinalSet}.
//      */
// 	public boolean containsAll(int... values) {
// 		for(int value : values) {
// 			if(!contains(value))
// 				return false;
// 		}
// 		return true;
// 	}
// 	
// 	/**
// 	 * Returns an array containing all elements in the set.
// 	 */
// 	public int[] asArray() {
// 	    int arr[] = new int[size()];
// 	    OrdinalIterator iter = iterator();
// 	    
// 	    int ordinal = iter.nextOrdinal();
// 	    int i = 0;
// 
// 	    while(ordinal != NO_MORE_ORDINALS) {
// 	        arr[i++] = ordinal;
// 	        ordinal = iter.nextOrdinal();
// 	    }
// 	    
// 	    return arr;
// 	}
// 	
// 	/**
// 	 * @return an {@link OrdinalIterator} over this set.
// 	 */
// 	public abstract OrdinalIterator iterator();
// 	
// 	/**
// 	 * @return the number of ordinals in this set.
// 	 */
// 	public abstract int size();
// 
// 	private static final int EMPTY_ORDINAL_ARRAY[] = new int[0];
// 
// 	/**
// 	 * An empty <code>OrdinalSet</code>.
// 	 */
// 	public static final OrdinalSet EMPTY_SET = new OrdinalSet() {
// 		@Override public boolean contains(int value) { return false; }
// 		
// 		@Override public int[] asArray() { return EMPTY_ORDINAL_ARRAY; }
// 
// 		@Override public OrdinalIterator iterator() { return EMPTY_ITERATOR; }
// 
// 		@Override public int size() { return 0; }
// 	};
// }


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

/*
 *  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;



/**
 * And implementation of {@link OrdinalSet} returned for connections in an {@link NFBuildGraph}. 
 */
public class NFBuildGraphOrdinalSet extends OrdinalSet {

	private final int ordinals[];
	private final int size;
	
	public NFBuildGraphOrdinalSet(int ordinals[], int size) {
		this.ordinals = ordinals;
		this.size = size;
	}
	
    /**
     * {@inheritDoc}
     */
	@Override
	public boolean contains(int value) {
		for(int i=0;i<size;i++) {
			if(ordinals[i] == value) {
				return true;
			}
		}
		return false;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public int[] asArray() {
		return Arrays.copyOf(ordinals, size);
	}

    /**
     * {@inheritDoc}
     */
	@Override
	public OrdinalIterator iterator() {