com.github.andyshao.lang.DoubleArrayWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Gear Show documentation
Show all versions of Gear Show documentation
Enhance and formating the coding of JDK
The newest version!
package com.github.andyshao.lang;
import com.github.andyshao.reflect.ArrayOperation;
import com.github.andyshao.util.stream.StreamOperation;
import java.io.Serial;
import java.util.Arrays;
import java.util.stream.Stream;
/**
*
* Title:
* Descript:
* Copyright: Copryright(c) Oct 1, 2015
* Encoding:UNIX UTF-8
*
* @author Andy.Shao
*
*/
public class DoubleArrayWrapper extends ArrayWrapperModel implements ArrayWrapper {
@Serial
private static final long serialVersionUID = 7582951027306249651L;
/**{@link ArrayType#DOUBLE_ARRAY}*/
private final double[] array;
/**
* build {@link DoubleArrayWrapper}
* @param array {@link ArrayType#DOUBLE_ARRAY}
*/
public DoubleArrayWrapper(double[] array) {
this.array = array;
this.position = 0;
this.mark = 0;
this.limit = this.array.length;
}
@Override
public double[] array() {
return this.array;
}
@Override
public ArrayWrapper backup() {
ArrayWrapper result = new DoubleArrayWrapper(ArrayOperation.backup(this.array()));
result.position(this.position());
result.limit(this.limit());
result.mark();
return result;
}
@Override
public int capacity() {
return this.array().length;
}
@Override
public ArrayWrapper duplicate() {
ArrayWrapper result = new DoubleArrayWrapper(this.array());
result.position(this.position());
result.limit(this.limit());
result.mark();
return result;
}
@Override
public Double get(int index) {
return this.array()[this.calculateRealIndex(index)];
}
@Override
public Double put(Object value , int index) {
int realIndex = this.calculateRealIndex(index);
Double result = this.get(realIndex);
this.array()[realIndex] = Convert.OB_2_DOUBLE.convert(value);
return result;
}
@Override
public Stream stream() {
return StreamOperation.valueOf(Arrays.stream(this.array));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy