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

com.vendasta.accountgroup.v1.internal.Geo Maven / Gradle / Ivy

The newest version!
package com.vendasta.accountgroup.v1.internal;

import java.util.List;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import java.util.Collections;
import java.util.Arrays;
import java.time.Duration;
import org.apache.commons.lang3.StringUtils;
import com.vendasta.accountgroup.v1.generated.ApiProto;

/**
 * Represents a geo point location.
 **/
public final class Geo {




	private final double latitude;
	private final double longitude;
	

	private Geo (
		final double latitude,
		final double longitude)
		
	{
		this.latitude = latitude;
		this.longitude = longitude;
		
	}
	
	/**
	 * 
      * @return The final value of latitude on the object
	 **/
	public double getLatitude() {
		return this.latitude;
	}
	
	/**
	 * 
      * @return The final value of longitude on the object
	 **/
	public double getLongitude() {
		return this.longitude;
	}
	

	public static class Builder {
		private double latitude;
		private double longitude;
		
		public Builder() {
			this.latitude = 0;
			this.longitude = 0;
			
		}
		
		/**
		  * Adds a value to the builder for latitude
		  * @param latitude Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setLatitude(double latitude) {
			this.latitude = latitude;
			return this;
		}
		
		/**
		  * Adds a value to the builder for longitude
		  * @param longitude Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setLongitude(double longitude) {
			this.longitude = longitude;
			return this;
		}
		
		/**
		  * Takes the configuration in the mutable Builder and uses it to instantiate a final instance
		  * of the Geo class
		  * @return The instantiated final Geo
		 **/
		public Geo build() {
			return new Geo(
				this.latitude,
				this.longitude);
		}
	}

	/**
	 * Returns a Builder for Geo, which is a mutable representation of the object.  Once the
	 * client has built up an object they can then create an immutable Geo object using the
	 * build function.
	 * @return A fresh Builder instance with no values set
	 **/
	public static Builder newBuilder() {
		return new Builder();
	}

	/**
	 * Provides a human-readable representation of this object.  Useful for debugging.
	 * @return A string representation of the Geo instance
	 **/
	 public String toString() {
		 String result = "Geo\n";
		 result += "-> latitude: (double)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.latitude).split("\n"))) + "\n"; 
		 result += "-> longitude: (double)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.longitude).split("\n"))) + "\n"; 
		 
		 return result;
	 }
	/**
	* Allows for simple conversion between the low-level generated protobuf object to
	* Geo, which is much more usable.
	* @return An instance of Geo representing the input proto object
	**/
	public static Geo fromProto(ApiProto.Geo proto) {
		Geo out = null;
		if (proto != null) {
			Geo.Builder outBuilder = Geo.newBuilder()
			.setLatitude(proto.getLatitude())
			.setLongitude(proto.getLongitude());
			out = outBuilder.build();
		}
		return out;
	}

	/**
	* Convenience method for handling lists of proto objects.  It calls .fromProto on each one
	* and returns a list of the converted results.
	* @return A list of Geo instances representing the input proto objects
	**/
	public static List fromProtos(List protos) {
		List out = new ArrayList();
		for(ApiProto.Geo proto : protos) {
			out.add(Geo.fromProto(proto));
		}
		return out;
	}

	/**
	 * Allows for simple conversion of an object to the low-level generated protobuf object.
	 * @return An instance of ApiProto.Geo which is a proto object ready for wire transmission
	 **/
	 public ApiProto.Geo toProto() {
		 Geo obj = this;
		 ApiProto.Geo.Builder outBuilder = ApiProto.Geo.newBuilder();
		 outBuilder.setLatitude(obj.getLatitude());
		 outBuilder.setLongitude(obj.getLongitude());
		 return outBuilder.build();
	 }

	 /**
	  * Convenience method for handling lists of objects.  It calls .toProto on each one and
	  * returns a list of the converted results.
	  * @return A list of ApiProto.Geo instances representing the input objects.
	  */
	public static List toProtos(List objects) {
		List out = new ArrayList();
		if(objects != null) {
			for (Geo obj : objects) {
				out.add(obj!=null?obj.toProto():null);
			}
		}
		return out;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy