Retranslate Java.

上级 519692cd
......@@ -36,6 +36,22 @@ public final class ColorHelper {
return new Color(red, green, blue, alpha);
}
/**
* Creates a Color from the specified Color, but with the new specified alpha value.
* Although this method allows a 32-bit value to be passed for the alpha value, the
* value is limited to 8 bits.
*
* @param alpha
* The alpha value for the new Color. Valid values are 0 through 255.
* @param baseColor
* The Color from which to create the new Color.
* @return The Color that this method creates.
*/
@Nonnull
public static Color fromArgb(int alpha, @Nonnull Color baseColor) {
return new Color(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), alpha);
}
@Nonnull
public static final Color LIME = new Color(0x00FF00);
}
......@@ -15,6 +15,10 @@ import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static java.lang.Math.abs;
import static java.lang.Math.floor;
import static java.lang.Math.log10;
/**
* Helper methods related to Formats.
*
......@@ -277,7 +281,7 @@ public final class FormatHelper {
@Override
public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
double exponentDigits = number == 0.0 ? 0.0 : Math.floor(Math.log10(number));
double exponentDigits = number == 0.0 ? 0.0 : floor(log10(abs(number)));
if (exponentDigits > -5 && exponentDigits < 17) {
return format.format(number, toAppendTo, pos);
......
package agi.foundation.compatibility;
import javax.annotation.Nonnull;
/**
* Represents a method that has one parameter and returns a value of the type specified by
* the {@code TResult} parameter.
*
* @param <T>
* The type of the parameter.
* @param <TResult>
* The type of the return value of the method.
*/
public abstract class Func2<T, TResult> extends Delegate implements java.util.function.Function<T, TResult> {
/**
* Creates a new instance of this delegate.
*/
public Func2() {
super();
}
/**
* Initializes a delegate that will invoke an instance method on a class instance.
*
* @param targetObject
* The class instance on which the delegate will invoke the method.
* @param methodName
* The name of the instance method.
* @param methodParameterClasses
* The type of the parameters of the instance method.
*/
public Func2(@Nonnull Object targetObject, @Nonnull String methodName, @Nonnull Class<?>... methodParameterClasses) {
super(targetObject, methodName, methodParameterClasses);
}
/**
* Initializes a delegate that will invoke a static method on a class.
*
* @param targetClass
* The class that defines the method.
* @param methodName
* The name of the static method.
* @param methodParameterClasses
* The type of the parameters of the static method.
*/
public Func2(@Nonnull Class<?> targetClass, @Nonnull String methodName, @Nonnull Class<?>... methodParameterClasses) {
super(targetClass, methodName, methodParameterClasses);
}
/**
* Represents a method that has has one parameter and returns a value of the type
* specified by the {@code TResult} parameter.
*
* @param arg
* The parameter of the method.
* @return The return value of the method.
*/
public abstract TResult invoke(T arg);
@Override
public final TResult apply(T t) {
return invoke(t);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof Func2<?, ?>)) {
return false;
}
return super.equals(obj);
}
/**
* Create a delegate for the given interface. This can be used to create a delegate
* from a lambda expression.
*
* @param f
* The function which will be invoked.
* @return A new delegate that will invoke the given function.
*/
@Nonnull
public static <T, TResult> Func2<T, TResult> of(@Nonnull Function<T, TResult> f) {
return new FunctionImpl<>(f);
}
/**
* Create a delegate for the given interface. This can be used to create a delegate
* from a method reference to an instance method.
*
* @param f
* The function which will be invoked.
* @param targetObject
* The class instance on which the delegate will invoke the method.
* @param methodName
* The name of the instance method.
* @param methodParameterClasses
* The type of the parameters of the instance method.
* @return A new delegate that will invoke the given function.
*/
@Nonnull
public static <T, TResult> Func2<T, TResult> of(@Nonnull Function<T, TResult> f, @Nonnull Object targetObject, @Nonnull String methodName, @Nonnull Class<?>... methodParameterClasses) {
return new FunctionImpl<>(f, targetObject, methodName, methodParameterClasses);
}
/**
* Create a delegate for the given interface. This can be used to create a delegate
* from a method reference to a static method.
*
* @param f
* The function which will be invoked.
* @param targetClass
* The class that defines the method.
* @param methodName
* The name of the static method.
* @param methodParameterClasses
* The type of the parameters of the static method.
* @return A new delegate that will invoke the given function.
*/
@Nonnull
public static <T, TResult> Func2<T, TResult> of(@Nonnull Function<T, TResult> f, @Nonnull Class<?> targetClass, @Nonnull String methodName, @Nonnull Class<?>... methodParameterClasses) {
return new FunctionImpl<>(f, targetClass, methodName, methodParameterClasses);
}
/**
* A functional interface for the containing delegate type.
*/
@FunctionalInterface
public interface Function<T, TResult> {
/**
* Represents a method that has has one parameter and returns a value of the type
* specified by the {@code TResult} parameter.
*
* @param arg
* The parameter of the method.
* @return The return value of the method.
*/
TResult invoke(T arg);
}
private static final class FunctionImpl<T, TResult> extends Func2<T, TResult> {
@Nonnull
private final Function<T, TResult> f;
public FunctionImpl(@Nonnull Function<T, TResult> f) {
this.f = f;
}
public FunctionImpl(@Nonnull Function<T, TResult> f, @Nonnull Object targetObject, @Nonnull String methodName, @Nonnull Class<?>... methodParameterClasses) {
super(targetObject, methodName, methodParameterClasses);
this.f = f;
}
public FunctionImpl(@Nonnull Function<T, TResult> f, @Nonnull Class<?> targetClass, @Nonnull String methodName, @Nonnull Class<?>... methodParameterClasses) {
super(targetClass, methodName, methodParameterClasses);
this.f = f;
}
@Override
public TResult invoke(T arg) {
return f.invoke(arg);
}
}
}
\ No newline at end of file
package agi.foundation.compatibility;
import agi.foundation.compatibility.annotations.Internal;
import java.util.Arrays;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.function.Function;
import javax.annotation.Nonnull;
/**
* Helper class for Iterable methods.
*
* @deprecated Internal use only.
*/
@Internal
@Deprecated
public final class IterableHelper {
private IterableHelper() {}
public static <T> Iterable<T> concat(@Nonnull Iterable<? extends Iterable<? extends T>> iterables) {
return new ConcatIterable<>(iterables);
}
/**
* Projects each element of a sequence into a new form.
*
* @param <TSource>
* The type of the elements of source.
* @param <TResult>
* The type of the value returned by selector.
* @param source
* A sequence of values to invoke a transform function on.
* @param selector
* A transform function to apply to each element.
* @return A sequence whose elements are the result of invoking the transform function
* on each element of source.
*/
@Nonnull
public static <TSource, TResult> Iterable<TResult> select(@Nonnull Iterable<? extends TSource> source, @Nonnull Function<? super TSource, ? extends TResult> selector) {
ArgumentNullException.assertNonNull(source, "source");
ArgumentNullException.assertNonNull(selector, "selector");
return new SelectIterable<>(source, selector);
}
/**
* Projects each element of a sequence to a new sequence and flattens the resulting
* sequences into one sequence.
*
* @param <TSource>
* The type of the elements of source.
* @param <TResult>
* The type of the elements of the sequence returned by selector.
* @param source
* A sequence of values to invoke a transform function on.
* @param selector
* A transform function to apply to each element.
* @return A sequence whose elements are the result of invoking the transform function
* on each element of source and flattening the sequences.
*/
@SuppressWarnings("null")
@Nonnull
public static <TSource, TResult> Iterable<TResult> selectMany(@Nonnull Iterable<? extends TSource> source,
@Nonnull Function<? super TSource, ? extends Iterable<? extends TResult>> selector) {
ArgumentNullException.assertNonNull(source, "source");
ArgumentNullException.assertNonNull(selector, "selector");
return concat(select(source, selector));
}
private static interface ResultYielder<T> {
void yield(T t);
void end();
}
private static abstract class BaseIterator<T> implements Iterator<T>, ResultYielder<T> {
private T next;
private State state = State.NEED_NEXT;
private enum State {
HAVE_NEXT,
NEED_NEXT,
END,
}
@Override
public boolean hasNext() {
switch (state) {
case END:
return false;
case HAVE_NEXT:
return true;
default:
yieldNext(this);
return state != State.END;
}
}
protected abstract void yieldNext(@Nonnull ResultYielder<T> yielder);
@Override
public T next() {
if (!hasNext())
throw new NoSuchElementException();
state = State.NEED_NEXT;
return next;
}
@Override
public void yield(T t) {
state = State.HAVE_NEXT;
next = t;
}
@Override
public void end() {
state = State.END;
next = null;
}
}
private static final class GetIteratorFromIterable<T> implements Function<Iterable<? extends T>, Iterator<? extends T>> {
@Override
public Iterator<? extends T> apply(Iterable<? extends T> arg) {
return arg.iterator();
}
}
private static final class ConcatIterable<T> implements Iterable<T> {
@Nonnull
private final Iterable<? extends Iterable<? extends T>> iterables;
public ConcatIterable(@Nonnull Iterable<? extends Iterable<? extends T>> iterables) {
this.iterables = iterables;
}
public ConcatIterable(@Nonnull Iterable<? extends T> first, @Nonnull Iterable<? extends T> second) {
this.iterables = Arrays.asList(first, second);
}
@Override
public Iterator<T> iterator() {
return new ConcatIterator<>(select(iterables, new GetIteratorFromIterable<T>()).iterator());
}
private static final class ConcatIterator<T> extends BaseIterator<T> {
@Nonnull
private final Iterator<Iterator<? extends T>> iterators;
private Iterator<? extends T> current;
public ConcatIterator(@Nonnull Iterator<Iterator<? extends T>> iterators) {
this.iterators = iterators;
}
@Override
protected void yieldNext(ResultYielder<T> yielder) {
if (current == null || !current.hasNext()) {
if (iterators.hasNext()) {
current = iterators.next();
yieldNext(yielder);
return;
}
yielder.end();
return;
}
yielder.yield(current.next());
}
}
}
private static final class SelectIterable<TSource, TResult> implements Iterable<TResult> {
@Nonnull
private final Iterable<? extends TSource> source;
@Nonnull
private final Function<? super TSource, ? extends TResult> selector;
public SelectIterable(@Nonnull Iterable<? extends TSource> source, @Nonnull Function<? super TSource, ? extends TResult> selector) {
this.source = source;
this.selector = selector;
}
@Override
public Iterator<TResult> iterator() {
return new SelectIterator<>(source.iterator(), selector);
}
private static final class SelectIterator<TSource, TResult> extends BaseIterator<TResult> {
@Nonnull
private final Iterator<? extends TSource> iterator;
@Nonnull
private final Function<? super TSource, ? extends TResult> selector;
public SelectIterator(@Nonnull Iterator<? extends TSource> iterator, @Nonnull Function<? super TSource, ? extends TResult> selector) {
this.iterator = iterator;
this.selector = selector;
}
@Override
protected void yieldNext(ResultYielder<TResult> yielder) {
if (iterator.hasNext()) {
yielder.yield(selector.apply(iterator.next()));
return;
}
yielder.end();
}
}
}
}
......@@ -24,6 +24,7 @@ import cesiumlanguagewriter.PathCesiumWriter;
import cesiumlanguagewriter.PointCesiumWriter;
import cesiumlanguagewriter.PolygonCesiumWriter;
import cesiumlanguagewriter.PolylineCesiumWriter;
import cesiumlanguagewriter.PolylineVolumeCesiumWriter;
import cesiumlanguagewriter.PositionCesiumWriter;
import cesiumlanguagewriter.RectangleCesiumWriter;
import cesiumlanguagewriter.RectangularSensorCesiumWriter;
......@@ -141,6 +142,10 @@ public class PacketCesiumWriter extends CesiumElementWriter {
*/
public static final String PolylinePropertyName = "polyline";
/**
* The name of the {@code polylineVolume} property.
*/
public static final String PolylineVolumePropertyName = "polylineVolume";
/**
* The name of the {@code rectangle} property.
*/
public static final String RectanglePropertyName = "rectangle";
......@@ -262,6 +267,11 @@ public class PacketCesiumWriter extends CesiumElementWriter {
return new PolylineCesiumWriter(PolylinePropertyName);
}
}, false);
private Lazy<PolylineVolumeCesiumWriter> m_polylineVolume = new Lazy<cesiumlanguagewriter.PolylineVolumeCesiumWriter>(new Func1<cesiumlanguagewriter.PolylineVolumeCesiumWriter>() {
public cesiumlanguagewriter.PolylineVolumeCesiumWriter invoke() {
return new PolylineVolumeCesiumWriter(PolylineVolumePropertyName);
}
}, false);
private Lazy<RectangleCesiumWriter> m_rectangle = new Lazy<cesiumlanguagewriter.RectangleCesiumWriter>(new Func1<cesiumlanguagewriter.RectangleCesiumWriter>() {
public cesiumlanguagewriter.RectangleCesiumWriter invoke() {
return new RectangleCesiumWriter(RectanglePropertyName);
......@@ -1306,6 +1316,22 @@ public class PacketCesiumWriter extends CesiumElementWriter {
return this.<PolylineCesiumWriter> openAndReturn(getPolylineWriter());
}
/**
* Gets the writer for the {@code polylineVolume} property. The returned instance must be opened by calling the {@link CesiumElementWriter#open} method before it can be used for writing. The {@code polylineVolume} property defines a polyline with a volume, defined as a 2D shape extruded along a polyline.
*/
@Nonnull
public final PolylineVolumeCesiumWriter getPolylineVolumeWriter() {
return m_polylineVolume.getValue();
}
/**
* Opens and returns the writer for the {@code polylineVolume} property. The {@code polylineVolume} property defines a polyline with a volume, defined as a 2D shape extruded along a polyline.
*/
@Nonnull
public final PolylineVolumeCesiumWriter openPolylineVolumeProperty() {
return this.<PolylineVolumeCesiumWriter> openAndReturn(getPolylineVolumeWriter());
}
/**
* Gets the writer for the {@code rectangle} property. The returned instance must be opened by calling the {@link CesiumElementWriter#open} method before it can be used for writing. The {@code rectangle} property defines a cartographic rectangle, which conforms to the curvature of the globe and can be placed along the surface or at altitude.
*/
......
package cesiumlanguagewriter;
import agi.foundation.compatibility.*;
import agi.foundation.compatibility.Func1;
import agi.foundation.compatibility.Lazy;
import cesiumlanguagewriter.advanced.*;
import javax.annotation.Nonnull;
/**
* Writes a {@code Shape} to a {@link CesiumOutputStream}. A {@code Shape} is a list of two-dimensional positions defining a shape.
*/
@SuppressWarnings( {
"unused",
"deprecation",
"serial"
})
public class ShapeCesiumWriter extends CesiumPropertyWriter<ShapeCesiumWriter> implements ICesiumDeletablePropertyWriter, ICesiumCartesian2ListValuePropertyWriter {
/**
* The name of the {@code cartesian2} property.
*/
public static final String Cartesian2PropertyName = "cartesian2";
/**
* The name of the {@code delete} property.
*/
public static final String DeletePropertyName = "delete";
private Lazy<CesiumCartesian2ListValuePropertyAdaptor<ShapeCesiumWriter>> m_asCartesian2;
/**
* Initializes a new instance.
* @param propertyName The name of the property.
*/
public ShapeCesiumWriter(@Nonnull String propertyName) {
super(propertyName);
m_asCartesian2 = createAsCartesian2();
}
/**
* Initializes a new instance as a copy of an existing instance.
* @param existingInstance The existing instance to copy.
*/
protected ShapeCesiumWriter(@Nonnull ShapeCesiumWriter existingInstance) {
super(existingInstance);
m_asCartesian2 = createAsCartesian2();
}
/**
* Copies this instance and returns the copy.
* @return The copy.
*/
@Override
public ShapeCesiumWriter clone() {
return new ShapeCesiumWriter(this);
}
/**
* Writes the value expressed as a {@code cartesian2}, which is the list of positions specified as two-dimensional Cartesian values {@code [X, Y, X, Y, ...]}.
* @param values The values.
*/
public final void writeCartesian2(Iterable<Rectangular> values) {
final String PropertyName = Cartesian2PropertyName;
openIntervalIfNecessary();
getOutput().writePropertyName(PropertyName);
CesiumWritingHelper.writeCartesian2List(getOutput(), values);
}
/**
* Writes the value expressed as a {@code delete}, which is whether the client should delete existing samples or interval data for this property. Data will be deleted for the containing interval, or if there is no containing interval, then all data. If true, all other properties in this property will be ignored.
* @param value The value.
*/
public final void writeDelete(boolean value) {
final String PropertyName = DeletePropertyName;
openIntervalIfNecessary();
getOutput().writePropertyName(PropertyName);
getOutput().writeValue(value);
}
/**
* Returns a wrapper for this instance that implements {@link ICesiumCartesian2ListValuePropertyWriter}. Because the returned instance is a wrapper for this instance, you may call {@link ICesiumElementWriter#close} on either this instance or the wrapper, but you must not call it on both.
* @return The wrapper.
*/
public final CesiumCartesian2ListValuePropertyAdaptor<ShapeCesiumWriter> asCartesian2() {
return m_asCartesian2.getValue();
}
private final Lazy<CesiumCartesian2ListValuePropertyAdaptor<ShapeCesiumWriter>> createAsCartesian2() {
return new Lazy<cesiumlanguagewriter.advanced.CesiumCartesian2ListValuePropertyAdaptor<ShapeCesiumWriter>>(
new Func1<cesiumlanguagewriter.advanced.CesiumCartesian2ListValuePropertyAdaptor<ShapeCesiumWriter>>(this, "createCartesian2List") {
public cesiumlanguagewriter.advanced.CesiumCartesian2ListValuePropertyAdaptor<ShapeCesiumWriter> invoke() {
return createCartesian2List();
}
}, false);
}
private final CesiumCartesian2ListValuePropertyAdaptor<ShapeCesiumWriter> createCartesian2List() {
return CesiumValuePropertyAdaptors.<ShapeCesiumWriter> createCartesian2List(this);
}
}
\ No newline at end of file
package cesiumlanguagewriter.advanced;
import agi.foundation.compatibility.*;
import cesiumlanguagewriter.*;
import javax.annotation.Nonnull;
/**
* Adapts a class that implements {@link ICesiumCartesian2ListValuePropertyWriter} to implement
{@link ICesiumPropertyWriter} for a list of {@link Rectangular} values.
* @param <TFrom> The class that implements {@link ICesiumCartesian2ListValuePropertyWriter} to adapt.
*/
@SuppressWarnings( {