public static PointType valueOf(String value) { return new PointType(value); }
@Override public SortedMap<String, PrimitiveType> getConstituents() { SortedMap<String, PrimitiveType> result = new TreeMap<>(); result.put(KEY_LATITUDE, getLatitude()); result.put(KEY_LONGITUDE, getLongitude()); result.put(KEY_ALTITUDE, getAltitude()); return result; }
public PointType(String value) { if (!value.isEmpty()) { List<String> elements = Arrays.stream(value.split(",")).map(in -> in.trim()).collect(Collectors.toList()); if (elements.size() >= 2) { canonicalize(new DecimalType(elements.get(0)), new DecimalType(elements.get(1))); if (elements.size() == 3) { setAltitude(new DecimalType(elements.get(2))); } else if (elements.size() > 3) { throw new IllegalArgumentException(value + " is not a valid PointType syntax. The syntax must not consist of more than 3 elements."); } } else { throw new IllegalArgumentException(value + " is not a valid PointType syntax"); } } else { throw new IllegalArgumentException("Constructor argument must not be blank"); } }
@Override public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException { Mapview mapview = (Mapview) w; String snippet = getSnippet("mapview"); snippet = preprocessSnippet(snippet, mapview); State state = itemUIRegistry.getState(mapview); if (state instanceof PointType) { PointType pointState = (PointType) state; double latitude = pointState.getLatitude().doubleValue(); double longitude = pointState.getLongitude().doubleValue(); snippet = StringUtils.replace(snippet, "%lat%", Double.toString(latitude)); snippet = StringUtils.replace(snippet, "%lon%", Double.toString(longitude)); snippet = StringUtils.replace(snippet, "%lonminus%", Double.toString(longitude - 0.01)); snippet = StringUtils.replace(snippet, "%lonplus%", Double.toString(longitude + 0.01)); snippet = StringUtils.replace(snippet, "%latminus%", Double.toString(latitude - 0.01)); snippet = StringUtils.replace(snippet, "%latplus%", Double.toString(latitude + 0.01)); } int height = mapview.getHeight(); if (height == 0) { height = 4; // set default height to something viewable } height = height * 36; snippet = StringUtils.replace(snippet, "%height%", Integer.toString(height)); sb.append(snippet); return null; } }
public PointType(DecimalType latitude, DecimalType longitude, DecimalType altitude) { this(latitude, longitude); setAltitude(altitude); }
@Override public String toString() { return toFullString(); }
public PointType(DecimalType latitude, DecimalType longitude) { canonicalize(latitude, longitude); }
/** * Formats the value of this type according to a pattern (see {@link Formatter}). One single value of this type can * be referenced by the pattern using an index. The item order is defined by the natural (alphabetical) order of * their keys. * * @param pattern the pattern to use containing indexes to reference the single elements of this type * @return the formatted string */ @Override public String format(@Nullable String pattern) { String formatPattern = pattern; if (formatPattern == null || "%s".equals(formatPattern)) { formatPattern = LOCATION_PATTERN; } return String.format(formatPattern, getConstituents().values().toArray()); }
/** * Compute the distance with another Point type, * http://stackoverflow.com/questions/837872/calculate-distance-in-meters-when-you-know-longitude-and-latitude-in- * java * * @param away : the point to calculate the distance with * @return distance between the two points in meters */ public DecimalType distanceFrom(@Nullable LocationItem awayItem) { if (awayItem != null && awayItem.state instanceof PointType && this.state instanceof PointType) { PointType thisPoint = (PointType) this.state; PointType awayPoint = (PointType) awayItem.state; return thisPoint.distanceFrom(awayPoint); } return new DecimalType(-1); }
private void setLocation(final @Nullable String location) { PointType oldLocation = this.location; PointType newLocation; if (location == null || location.isEmpty()) { newLocation = null; } else { try { newLocation = PointType.valueOf(location); } catch (IllegalArgumentException e) { newLocation = oldLocation; // preserve old location or null if none was set before logger.warn("Could not set new location: {}, keeping old one, error message: {}", location, e.getMessage()); } } if (!Objects.equals(newLocation, oldLocation)) { this.location = newLocation; logger.info("Location set to '{}'.", newLocation); } }
public PointType(DecimalType latitude, DecimalType longitude, DecimalType altitude) { this(latitude, longitude); setAltitude(altitude); }
@Override public String toString() { return toFullString(); }
public PointType(DecimalType latitude, DecimalType longitude) { canonicalize(latitude, longitude); }
/** * Formats the value of this type according to a pattern (see {@link Formatter}). One single value of this type can * be referenced by the pattern using an index. The item order is defined by the natural (alphabetical) order of * their keys. * * @param pattern the pattern to use containing indexes to reference the single elements of this type * @return the formatted string */ @Override public String format(@Nullable String pattern) { String formatPattern = pattern; if (formatPattern == null || "%s".equals(formatPattern)) { formatPattern = LOCATION_PATTERN; } return String.format(formatPattern, getConstituents().values().toArray()); }
/** * Compute the distance with another Point type, * http://stackoverflow.com/questions/837872/calculate-distance-in-meters-when-you-know-longitude-and-latitude-in- * java * * @param away : the point to calculate the distance with * @return distance between the two points in meters */ public DecimalType distanceFrom(@Nullable LocationItem awayItem) { if (awayItem != null && awayItem.state instanceof PointType && this.state instanceof PointType) { PointType thisPoint = (PointType) this.state; PointType awayPoint = (PointType) awayItem.state; return thisPoint.distanceFrom(awayPoint); } return new DecimalType(-1); }
private void setLocation(final @Nullable String location) { PointType oldLocation = this.location; PointType newLocation; if (location == null || location.isEmpty()) { newLocation = null; } else { try { newLocation = PointType.valueOf(location); } catch (IllegalArgumentException e) { newLocation = oldLocation; // preserve old location or null if none was set before logger.warn("Could not set new location: {}, keeping old one, error message: {}", location, e.getMessage()); } } if (!Objects.equals(newLocation, oldLocation)) { this.location = newLocation; logger.info("Location set to '{}'.", newLocation); } }
@Override public boolean equals(@Nullable Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof PointType)) { return false; } PointType other = (PointType) obj; if (!getLatitude().equals(other.getLatitude()) || !getLongitude().equals(other.getLongitude()) || !getAltitude().equals(other.getAltitude())) { return false; } return true; }
public PointType(String value) { if (!value.isEmpty()) { List<String> elements = Arrays.stream(value.split(",")).map(in -> in.trim()).collect(Collectors.toList()); if (elements.size() >= 2) { canonicalize(new DecimalType(elements.get(0)), new DecimalType(elements.get(1))); if (elements.size() == 3) { setAltitude(new DecimalType(elements.get(2))); } else if (elements.size() > 3) { throw new IllegalArgumentException(value + " is not a valid PointType syntax. The syntax must not consist of more than 3 elements."); } } else { throw new IllegalArgumentException(value + " is not a valid PointType syntax"); } } else { throw new IllegalArgumentException("Constructor argument must not be blank"); } }
public static PointType valueOf(String value) { return new PointType(value); }
@Override public int hashCode() { int tmp = 10000 * getLatitude().hashCode(); tmp += 100 * getLongitude().hashCode(); tmp += getAltitude().hashCode(); return tmp; }