001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Rustem Rafikov
019: * @version $Revision$
020: */package org.apache.harmony.awt.nativebridge;
021:
022: public class DoublePointer extends VoidPointer {
023:
024: private static final int DOUBLE_SIZE_FACTOR = 8;
025:
026: DoublePointer(int size, boolean direct) {
027: super (size * DOUBLE_SIZE_FACTOR, direct);
028: }
029:
030: DoublePointer(long add) {
031: super (add);
032: }
033:
034: DoublePointer(VoidPointer p) {
035: super (p);
036: }
037:
038: DoublePointer(ByteBase base) {
039: super (base);
040: }
041:
042: /**
043: * Returns the element at the specified position.
044: * @param index
045: */
046: public double get(int index) {
047: return byteBase.getDouble(index * DOUBLE_SIZE_FACTOR);
048: }
049:
050: /**
051: * Sets the element at the specified position.
052: * @param index
053: * @param value
054: */
055: public void set(int index, double value) {
056: byteBase.setDouble(index * DOUBLE_SIZE_FACTOR, value);
057: }
058:
059: /**
060: * This method transfers int values into the given destination array.
061: *
062: * @param dst - The array into which values are to be written
063: * @param offset - The offset within the array of the first element to be written;
064: * must be non-negative and no larger than dst.length
065: * @param length - The maximum number of elements to be written to the given array;
066: * must be non-negative and no larger than dst.length - offset
067: */
068: public void get(double[] dst, int offset, int length) {
069: byteBase.getDouble(dst, offset, length);
070: }
071:
072: /**
073: * This method transfers double values from the given destination array.
074: *
075: * @param src - The array from which values are to be read
076: * @param offset - The offset within the array of the first element to be read;
077: * must be non-negative and no larger than dst.length
078: * @param length - The maximum number of elements to be read from the given array;
079: * must be non-negative and no larger than dst.length - offset
080: */
081: public void set(double[] src, int offset, int length) {
082: byteBase.setDouble(src, offset, length);
083: }
084:
085: /**
086: * returns class that represents the pointer to specified index.
087: */
088: public DoublePointer getElementPointer(int index) {
089: return new DoublePointer(byteBase.getBytesBaseElementPointer(
090: index * DOUBLE_SIZE_FACTOR, DOUBLE_SIZE_FACTOR));
091: }
092:
093: public void fill(double value, int size) {
094: int this Size = size();
095: for (int i = 0; i < size && i < this Size; i++) {
096: byteBase.setDouble(i * DOUBLE_SIZE_FACTOR, value);
097: }
098: }
099:
100: @Override
101: public int size() {
102: return byteBase.size() / DOUBLE_SIZE_FACTOR;
103: }
104: }
|