All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mapbox.geojson.shifter.CoordinateShifterManager Maven / Gradle / Ivy

package com.mapbox.geojson.shifter;

import com.mapbox.geojson.Point;

import java.util.Arrays;
import java.util.List;

/**
 * CoordinateShifterManager keeps track of currently set CoordinateShifter.
 *
 * @since 4.2.0
 */
public final class CoordinateShifterManager {

  private static final CoordinateShifter DEFAULT = new CoordinateShifter() {
    @Override
    public List shiftLonLat(double lon, double lat) {
      return Arrays.asList(lon, lat);
    }

    @Override
    public List shiftLonLatAlt(double lon, double lat, double alt) {
      return Double.isNaN(alt)
              ? Arrays.asList(lon, lat) :
              Arrays.asList(lon, lat, alt);
    }

    @Override
    public List unshiftPoint(Point point) {
      return point.coordinates();
    }

    @Override
    public List unshiftPoint(List coordinates) {
      return coordinates;
    }
  };

  private static volatile CoordinateShifter coordinateShifter = DEFAULT;

  /**
   * Currently set CoordinateShifterManager.
   *
   * @return Currently set CoordinateShifterManager
   * @since 4.2.0
   */
  public static CoordinateShifter getCoordinateShifter() {
    return coordinateShifter;
  }

  /**
   * Sets CoordinateShifterManager.
   *
   * @param coordinateShifter CoordinateShifterManager to be set
   * @since 4.2.0
   */
  public static void setCoordinateShifter(CoordinateShifter coordinateShifter) {
    CoordinateShifterManager.coordinateShifter =
      coordinateShifter == null ? DEFAULT : coordinateShifter;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy