ReverseScriptArrayIterator.java revision 953:221a84ef44c0
11592Srgrimes/* 21592Srgrimes * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 31592Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41592Srgrimes * 51592Srgrimes * This code is free software; you can redistribute it and/or modify it 61592Srgrimes * under the terms of the GNU General Public License version 2 only, as 71592Srgrimes * published by the Free Software Foundation. Oracle designates this 81592Srgrimes * particular file as subject to the "Classpath" exception as provided 91592Srgrimes * by Oracle in the LICENSE file that accompanied this code. 101592Srgrimes * 111592Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT 121592Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 131592Srgrimes * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 141592Srgrimes * version 2 for more details (a copy is included in the LICENSE file that 151592Srgrimes * accompanied this code). 161592Srgrimes * 171592Srgrimes * You should have received a copy of the GNU General Public License version 181592Srgrimes * 2 along with this work; if not, write to the Free Software Foundation, 191592Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 201592Srgrimes * 211592Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 221592Srgrimes * or visit www.oracle.com if you need additional information or have any 231592Srgrimes * questions. 241592Srgrimes */ 251592Srgrimes 261592Srgrimespackage jdk.nashorn.internal.runtime.arrays; 271592Srgrimes 281592Srgrimesimport jdk.nashorn.internal.runtime.ScriptObject; 291592Srgrimes 301592Srgrimes/** 311592Srgrimes * Reverse iterator over a NativeArray 321592Srgrimes */ 331592Srgrimesfinal class ReverseScriptArrayIterator extends ScriptArrayIterator { 341592Srgrimes 3531491Scharnier /** 3621838Spst * Constructor 3731491Scharnier * @param array array to iterate over 3831491Scharnier * @param includeUndefined should undefined elements be included in iteration 3950476Speter */ 401592Srgrimes public ReverseScriptArrayIterator(final ScriptObject array, final boolean includeUndefined) { 411592Srgrimes super(array, includeUndefined); 421592Srgrimes this.index = array.getArray().length() - 1; 431592Srgrimes } 441592Srgrimes 451592Srgrimes @Override 461592Srgrimes public boolean isReverse() { 471592Srgrimes return true; 4821838Spst } 491592Srgrimes 5021838Spst @Override 511592Srgrimes protected boolean indexInArray() { 5221838Spst return index >= 0; 5321838Spst } 5421838Spst 5521838Spst @Override 561592Srgrimes protected long bumpIndex() { 571592Srgrimes return index--; 5821838Spst } 591592Srgrimes} 601592Srgrimes