ArrayFilter.java revision 1571:fd97b9047199
11541Srgrimes/* 21541Srgrimes * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 31541Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41541Srgrimes * 51541Srgrimes * This code is free software; you can redistribute it and/or modify it 61541Srgrimes * under the terms of the GNU General Public License version 2 only, as 71541Srgrimes * published by the Free Software Foundation. Oracle designates this 81541Srgrimes * particular file as subject to the "Classpath" exception as provided 91541Srgrimes * by Oracle in the LICENSE file that accompanied this code. 101541Srgrimes * 111541Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT 121541Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 131541Srgrimes * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 141541Srgrimes * version 2 for more details (a copy is included in the LICENSE file that 151541Srgrimes * accompanied this code). 161541Srgrimes * 171541Srgrimes * You should have received a copy of the GNU General Public License version 181541Srgrimes * 2 along with this work; if not, write to the Free Software Foundation, 191541Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 201541Srgrimes * 211541Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 221541Srgrimes * or visit www.oracle.com if you need additional information or have any 231541Srgrimes * questions. 241541Srgrimes */ 251541Srgrimes 261541Srgrimespackage jdk.nashorn.internal.runtime.arrays; 271541Srgrimes 281541Srgrimesimport jdk.nashorn.internal.codegen.types.Type; 291541Srgrimesimport jdk.nashorn.internal.runtime.ScriptRuntime; 301541Srgrimesimport jdk.nashorn.internal.runtime.Undefined; 311541Srgrimesimport jdk.nashorn.internal.runtime.linker.Bootstrap; 321541Srgrimes 3385052Sru/** 3450477Speter * Base class for array filters. Implements all core routines so that the 351541Srgrimes * filter only has to implement those needed. 361541Srgrimes */ 372168Spaulabstract class ArrayFilter extends ArrayData { 382168Spaul /** Underlying array. */ 392168Spaul protected ArrayData underlying; 401541Srgrimes 411541Srgrimes ArrayFilter(final ArrayData underlying) { 428876Srgrimes super(underlying.length()); 431541Srgrimes this.underlying = underlying; 441541Srgrimes } 451541Srgrimes 461541Srgrimes /** 471541Srgrimes * Get the underlying {@link ArrayData} that this filter wraps 481541Srgrimes * @return array data 491541Srgrimes */ 501541Srgrimes protected ArrayData getUnderlying() { 511541Srgrimes return underlying; 521541Srgrimes } 531541Srgrimes 541541Srgrimes @Override 551541Srgrimes public void setLength(final long length) { 561541Srgrimes super.setLength(length); 571541Srgrimes underlying.setLength(length); 581541Srgrimes } 591541Srgrimes 601541Srgrimes @Override 61122922Sandre public Object[] asObjectArray() { 62122922Sandre return underlying.asObjectArray(); 63122922Sandre } 64122922Sandre 65122922Sandre @Override 66122922Sandre public Object asArrayOfType(final Class<?> componentType) { 671541Srgrimes return underlying.asArrayOfType(componentType); 681541Srgrimes } 691541Srgrimes 701541Srgrimes @Override 711541Srgrimes public void shiftLeft(final int by) { 7213765Smpp underlying.shiftLeft(by); 7313765Smpp setLength(underlying.length()); 741541Srgrimes } 751541Srgrimes 761541Srgrimes @Override 771541Srgrimes public ArrayData shiftRight(final int by) { 785791Swollman underlying = underlying.shiftRight(by); 791541Srgrimes setLength(underlying.length()); 801541Srgrimes return this; 811541Srgrimes } 821541Srgrimes 831541Srgrimes @Override 841541Srgrimes public ArrayData ensure(final long safeIndex) { 851541Srgrimes underlying = underlying.ensure(safeIndex); 861541Srgrimes setLength(underlying.length()); 871541Srgrimes return this; 881541Srgrimes } 891541Srgrimes 905833Sbde @Override 915833Sbde public ArrayData shrink(final long newLength) { 925833Sbde underlying = underlying.shrink(newLength); 935833Sbde setLength(underlying.length()); 945833Sbde return this; 951541Srgrimes } 961541Srgrimes 971541Srgrimes @Override 981541Srgrimes public ArrayData set(final int index, final Object value, final boolean strict) { 991541Srgrimes underlying = underlying.set(index, value, strict); 1001541Srgrimes setLength(underlying.length()); 1011541Srgrimes return this; 1021541Srgrimes } 1031541Srgrimes 1041541Srgrimes @Override 1051541Srgrimes public ArrayData set(final int index, final int value, final boolean strict) { 1061541Srgrimes underlying = underlying.set(index, value, strict); 1071541Srgrimes setLength(underlying.length()); 1081541Srgrimes return this; 1091541Srgrimes } 11048381Smsmith 1117197Swollman @Override 1121541Srgrimes public ArrayData set(final int index, final double value, final boolean strict) { 113122922Sandre underlying = underlying.set(index, value, strict); 1141541Srgrimes setLength(underlying.length()); 1151541Srgrimes return this; 116122922Sandre } 1171541Srgrimes 11893084Sbde @Override 11993084Sbde public ArrayData setEmpty(final int index) { 1205791Swollman underlying.setEmpty(index); 1215791Swollman return this; 122120727Ssam } 123120727Ssam 124120727Ssam @Override 125120727Ssam public ArrayData setEmpty(final long lo, final long hi) { 1261541Srgrimes underlying.setEmpty(lo, hi); 1271541Srgrimes return this; 1281541Srgrimes } 1291541Srgrimes 1301541Srgrimes @Override 1311541Srgrimes public Type getOptimisticType() { 1321541Srgrimes return underlying.getOptimisticType(); 1331541Srgrimes } 1341541Srgrimes 1351541Srgrimes @Override 1361541Srgrimes public int getInt(final int index) { 1371541Srgrimes return underlying.getInt(index); 1381541Srgrimes } 1391541Srgrimes 1401541Srgrimes @Override 1411541Srgrimes public int getIntOptimistic(final int index, final int programPoint) { 1424104Swollman return underlying.getIntOptimistic(index, programPoint); 1434104Swollman } 1441541Srgrimes 1451541Srgrimes @Override 1461541Srgrimes public double getDouble(final int index) { 1471541Srgrimes return underlying.getDouble(index); 1481541Srgrimes } 1491541Srgrimes 1501541Srgrimes @Override 15186764Sjlemon public double getDoubleOptimistic(final int index, final int programPoint) { 1521541Srgrimes return underlying.getDoubleOptimistic(index, programPoint); 1531541Srgrimes } 15417835Sjulian 1551541Srgrimes @Override 1561541Srgrimes public Object getObject(final int index) { 1571541Srgrimes return underlying.getObject(index); 1581541Srgrimes } 1591541Srgrimes 160122921Sandre @Override 161122921Sandre public boolean has(final int index) { 162122921Sandre return underlying.has(index); 163122921Sandre } 164122921Sandre 1655099Swollman @Override 1665099Swollman public ArrayData delete(final int index) { 16718839Swollman underlying = underlying.delete(index); 1686245Swollman setLength(underlying.length()); 16915652Swollman return this; 17015652Swollman } 17115652Swollman 17215652Swollman @Override 1731541Srgrimes public ArrayData delete(final long from, final long to) { 1741541Srgrimes underlying = underlying.delete(from, to); 1751541Srgrimes setLength(underlying.length()); 1761541Srgrimes return this; 1771541Srgrimes } 1781541Srgrimes 1791541Srgrimes @Override 1801541Srgrimes public ArrayData convert(final Class<?> type) { 1811541Srgrimes underlying = underlying.convert(type); 1821541Srgrimes setLength(underlying.length()); 1831541Srgrimes return this; 1841541Srgrimes } 1851541Srgrimes 1861541Srgrimes @Override 1871541Srgrimes public Object pop() { 1881541Srgrimes final Object value = underlying.pop(); 1891541Srgrimes setLength(underlying.length()); 1901541Srgrimes return value; 1911541Srgrimes } 1921541Srgrimes 1931541Srgrimes @Override 1941541Srgrimes public long nextIndex(final long index) { 1951541Srgrimes return underlying.nextIndex(index); 1961541Srgrimes } 1971541Srgrimes 1981541Srgrimes static Object convertUndefinedValue(final Class<?> targetType) { 1991541Srgrimes return invoke(Bootstrap.getLinkerServices().getTypeConverter(Undefined.class, targetType), 2001541Srgrimes ScriptRuntime.UNDEFINED); 2011541Srgrimes } 2025791Swollman} 2031541Srgrimes