All Downloads are FREE. Search and download functionalities are using the official Maven repository.

power.util.KeyValuePairedArrays Maven / Gradle / Ivy

package power.util;

import java.util.Iterator;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class KeyValuePairedArrays implements Iterable> {

	@NonNull F[] first;
	@NonNull S[] second;

	public boolean hasSameLenght(){
		return first.length == second.length;
	}

	@Override
	public Iterator> iterator() {
		return new KeyValueIterator();
	}

	class KeyValueIterator implements Iterator> {
		
		volatile int firstCursor = 0;
		volatile int secondCursor = 0;

		@Override
		public boolean hasNext() {
			return firstCursor < first.length
				&& secondCursor < second.length;
		}

		@Override
		public KeyValue next() {
			return new KeyValue<>( first[firstCursor++], second[secondCursor++] );
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy