Here you can find the source of getIterator(final int[] p, final Object[] data)
data[p[0]],..,data[p[data.length-1]]
public static Iterator getIterator(final int[] p, final Object[] data)
//package com.java2s; /*/*from w w w . ja va 2 s. co m*/ * Copyright 2004, 2005, 2006 Odysseus Software GmbH * * 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. */ import java.util.Iterator; import java.util.List; public class Main { /** * Answer iterator, which iterates over specified data array according * to the specified permutation, that is * <code>data[p[0]],..,data[p[data.length-1]]</code> */ public static Iterator getIterator(final int[] p, final Object[] data) { return new Iterator() { int pos = 0; public boolean hasNext() { return pos < data.length; } public Object next() { return data[p[pos++]]; } public void remove() { throw new UnsupportedOperationException("Cannot remove from immutable iterator!"); } }; } /** * Answer iterator, which iterates over specified data list according * to the specified permutation, that is * <code>data.get(p[0]),..,data.get(p[data.length-1])</code> */ public static Iterator getIterator(final int[] p, final List data) { return new Iterator() { int pos = 0; public boolean hasNext() { return pos < data.size(); } public Object next() { return data.get(p[pos++]); } public void remove() { throw new UnsupportedOperationException("Cannot remove from immutable iterator!"); } }; } }