private static Value calculateDistance( PointValue p1, PointValue p2 ) { if ( p1.getCoordinateReferenceSystem().equals( p2.getCoordinateReferenceSystem() ) ) { return doubleValue( p1.getCoordinateReferenceSystem().getCalculator().distance( p1, p2 ) ); } else { return NO_VALUE; } }
@Override Value get( PointValue value ) { return Values.stringValue( value.getCoordinateReferenceSystem().toString() ); } },
@Override public double distance( PointValue p1, PointValue p2 ) { assert p1.getCoordinateReferenceSystem().getDimension() == dimension; assert p2.getCoordinateReferenceSystem().getDimension() == dimension; return pythagoras( p1.coordinate(), p2.coordinate() ); }
@Override Value get( PointValue value ) { return Values.intValue( value.getCoordinateReferenceSystem().getCode() ); } };
/** * @return the next pseudorandom three-dimensional cartesian {@link PointValue}. * @see RandomValues */ public PointValue nextCartesian3DPoint() { double x = randomCartesianCoordinate(); double y = randomCartesianCoordinate(); double z = randomCartesianCoordinate(); return Values.pointValue( CoordinateReferenceSystem.Cartesian_3D, x, y, z ); }
public static <E extends Exception> void writeTo( ValueWriter<E> writer, Point[] values ) throws E { writer.beginArray( values.length, ValueWriter.ArrayType.POINT ); for ( Point x : values ) { PointValue value = Values.point( x ); writer.writePoint( value.getCoordinateReferenceSystem(), value.coordinate() ); } writer.endArray(); } }
@Override public int compare( Number n1, Number n2 ) { return Values.COMPARATOR.compare( Values.numberValue(n1), Values.numberValue(n2) ); } };
private TextValue nextTextValue( int minLength, int maxLength, CodePointFactory codePointFactory ) { // todo should we generate UTF8StringValue or StringValue? Or maybe both? Randomly? int length = intBetween( minLength, maxLength ); UTF8StringValueBuilder builder = new UTF8StringValueBuilder( nextPowerOf2( length ) ); for ( int i = 0; i < length; i++ ) { builder.addCodePoint( codePointFactory.generate() ); } return builder.build(); }
/** * @see RandomValues */ public LocalTimeValue nextLocalTimeValue() { return localTime( nextLocalTimeRaw() ); }
@Override public AnyValue value( int position ) { return Values.booleanValue( booleanValue( position ) ); }
/** * @see RandomValues */ public DoubleArray nextDoubleArray() { double[] array = nextDoubleArrayRaw( minArray(), maxArray() ); return Values.doubleArray( array ); }
/** * @see RandomValues */ public IntArray nextIntArray() { int[] array = nextIntArrayRaw( minArray(), maxArray() ); return Values.intArray( array ); }
protected final <E extends Exception> void writeTo( ValueWriter<E> writer, ValueWriter.ArrayType type, Temporal[] values ) throws E { writer.beginArray( values.length, type ); for ( Temporal x : values ) { Value value = Values.temporalValue( x ); value.writeTo( writer ); } writer.endArray(); }
@Override public int compareTo( IntegralValue other ) { return NumberValues.compareDoubleAgainstLong( doubleValue(), other.longValue() ); }
@Override public int compareTo( FloatingPointValue other ) { return NumberValues.compareLongAgainstDouble( longValue(), other.doubleValue() ); }
/** * @see RandomValues */ public TimeArray nextTimeArray() { OffsetTime[] array = nextTimeArrayRaw( minArray(), maxArray() ); return Values.timeArray( array ); }
/** * @see RandomValues */ public LocalDateTimeArray nextLocalDateTimeArray() { return Values.localDateTimeArray( nextLocalDateTimeArrayRaw( minArray(), maxArray() ) ); }
/** * Create a {@code RandomValues} using the given {@link SplittableRandom} with given configuration * * @return a {@code RandomValues} instance */ public static RandomValues create( SplittableRandom random, Configuration configuration ) { return new RandomValues( new SplittableRandomGenerator( random ), configuration ); }
/** * Create a {@code RandomValues} using the given {@link SplittableRandom} with default configuration * * @return a {@code RandomValues} instance */ public static RandomValues create( SplittableRandom random ) { return new RandomValues( new SplittableRandomGenerator( random ) ); }