src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/ReverseJavaArrayIterator.java
author hannesw
Wed, 21 Mar 2018 16:55:34 +0100
changeset 49275 c639a6b33c5c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8199869: Missing copyright headers in nashorn source code Reviewed-by: sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19469
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
     1
/*
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
     4
 *
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    10
 *
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    15
 * accompanied this code).
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    16
 *
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    20
 *
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    23
 * questions.
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    24
 */
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    25
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    26
package jdk.nashorn.internal.runtime.arrays;
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    27
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    28
import java.lang.reflect.Array;
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    29
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    30
/**
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    31
 * Reverse iterator over a array
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    32
 */
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    33
final class ReverseJavaArrayIterator extends JavaArrayIterator {
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    34
    /**
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    35
     * Constructor
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    36
     * @param array array to iterate over
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    37
     * @param includeUndefined should undefined elements be included in iteration
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    38
     */
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    39
    public ReverseJavaArrayIterator(final Object array, final boolean includeUndefined) {
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    40
        super(array, includeUndefined);
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    41
        this.index = Array.getLength(array) - 1;
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    42
    }
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    43
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    44
    @Override
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    45
    public boolean isReverse() {
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    46
        return true;
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    47
    }
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    48
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    49
    @Override
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    50
    protected boolean indexInArray() {
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    51
        return index >= 0;
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    52
    }
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    53
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    54
    @Override
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    55
    protected long bumpIndex() {
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    56
        return index--;
a5d34b586cea 8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists
sundar
parents:
diff changeset
    57
    }
20928
3ff39d5c8c08 8026137: Fix Issues with Binary Evaluation Order
lagergren
parents: 19469
diff changeset
    58
}