Skip to content

Commit

Permalink
Refactored surface wind model classes: TrendForecastSurfaceWind and T…
Browse files Browse the repository at this point in the history
…AFSurfaceWind interfaces have been removed and replaced with a common SurfaceWind interface. METAR observations use ObservedSurfaceWind interface which now extends SurfaceWind.
  • Loading branch information
ilkkarinne committed Nov 7, 2018
1 parent b96d268 commit 138cc9d
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 169 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package fi.fmi.avi.model.metar;
package fi.fmi.avi.model;

import java.util.Optional;

import fi.fmi.avi.model.AviationCodeListUser;
import fi.fmi.avi.model.NumericMeasure;
public interface SurfaceWind extends AviationCodeListUser {

public interface TrendForecastSurfaceWind extends AviationCodeListUser {
boolean isVariableDirection();

NumericMeasure getMeanWindDirection();
Optional<NumericMeasure> getMeanWindDirection();

NumericMeasure getMeanWindSpeed();

Expand All @@ -16,4 +15,5 @@ public interface TrendForecastSurfaceWind extends AviationCodeListUser {
Optional<NumericMeasure> getWindGust();

Optional<RelationalOperator> getWindGustOperator();

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fi.fmi.avi.model.taf.immutable;
package fi.fmi.avi.model.immutable;

import java.io.Serializable;
import java.util.Objects;
Expand All @@ -11,42 +11,41 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import fi.fmi.avi.model.NumericMeasure;
import fi.fmi.avi.model.immutable.NumericMeasureImpl;
import fi.fmi.avi.model.taf.TAFSurfaceWind;
import fi.fmi.avi.model.SurfaceWind;

/**
* Created by rinne on 18/04/2018.
*/
@FreeBuilder
@JsonDeserialize(builder = TAFSurfaceWindImpl.Builder.class)
@JsonDeserialize(builder = SurfaceWindImpl.Builder.class)
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@JsonPropertyOrder({"meanWindDirection", "variableDirection", "meanWindSpeed", "meanWindSpeedOperator",
"windGust", "windGustOperator"})
public abstract class TAFSurfaceWindImpl implements TAFSurfaceWind, Serializable {
public abstract class SurfaceWindImpl implements SurfaceWind, Serializable {

public static TAFSurfaceWindImpl immutableCopyOf(final TAFSurfaceWind surfaceWind) {
public static SurfaceWindImpl immutableCopyOf(final SurfaceWind surfaceWind) {
Objects.requireNonNull(surfaceWind);
if (surfaceWind instanceof TAFSurfaceWindImpl) {
return (TAFSurfaceWindImpl) surfaceWind;
if (surfaceWind instanceof SurfaceWindImpl) {
return (SurfaceWindImpl) surfaceWind;
} else {
return Builder.from(surfaceWind).build();
}
}

public static Optional<TAFSurfaceWindImpl> immutableCopyOf(final Optional<TAFSurfaceWind> surfaceWind) {
public static Optional<SurfaceWindImpl> immutableCopyOf(final Optional<SurfaceWind> surfaceWind) {
Objects.requireNonNull(surfaceWind);
return surfaceWind.map(TAFSurfaceWindImpl::immutableCopyOf);
return surfaceWind.map(SurfaceWindImpl::immutableCopyOf);
}

public abstract Builder toBuilder();

public static class Builder extends TAFSurfaceWindImpl_Builder {
public static class Builder extends SurfaceWindImpl_Builder {

public static Builder from(final TAFSurfaceWind value) {
if (value instanceof TAFSurfaceWindImpl) {
return ((TAFSurfaceWindImpl) value).toBuilder();
public static Builder from(final SurfaceWind value) {
if (value instanceof SurfaceWindImpl) {
return ((SurfaceWindImpl) value).toBuilder();
} else {
return new TAFSurfaceWindImpl.Builder()//
return new SurfaceWindImpl.Builder()//
.setMeanWindSpeed(NumericMeasureImpl.immutableCopyOf(value.getMeanWindSpeed()))
.setMeanWindSpeedOperator(value.getMeanWindSpeedOperator())
.setMeanWindDirection(NumericMeasureImpl.immutableCopyOf(value.getMeanWindDirection()))
Expand All @@ -61,7 +60,7 @@ public Builder() {
}

@Override
public TAFSurfaceWindImpl build() {
public SurfaceWindImpl build() {
if (!isVariableDirection() && !getMeanWindDirection().isPresent()) {
throw new IllegalStateException("MeanWindDirection must be present if variableDirection is false");
}
Expand Down
16 changes: 2 additions & 14 deletions src/main/java/fi/fmi/avi/model/metar/ObservedSurfaceWind.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@

import java.util.Optional;

import fi.fmi.avi.model.AviationCodeListUser;
import fi.fmi.avi.model.NumericMeasure;
import fi.fmi.avi.model.SurfaceWind;

public interface ObservedSurfaceWind extends AviationCodeListUser {

boolean isVariableDirection();

Optional<NumericMeasure> getMeanWindDirection();

NumericMeasure getMeanWindSpeed();

Optional<RelationalOperator> getMeanWindSpeedOperator();

Optional<NumericMeasure> getWindGust();

Optional<RelationalOperator> getWindGustOperator();
public interface ObservedSurfaceWind extends SurfaceWind {

Optional<NumericMeasure> getExtremeClockwiseWindDirection();

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/fi/fmi/avi/model/metar/TrendForecast.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import fi.fmi.avi.model.NumericMeasure;
import fi.fmi.avi.model.PartialOrCompleteTimeInstant;
import fi.fmi.avi.model.PartialOrCompleteTimePeriod;
import fi.fmi.avi.model.SurfaceWind;
import fi.fmi.avi.model.Weather;

public interface TrendForecast extends AviationCodeListUser {
Expand All @@ -24,7 +25,7 @@ public interface TrendForecast extends AviationCodeListUser {

Optional<RelationalOperator> getPrevailingVisibilityOperator();

Optional<TrendForecastSurfaceWind> getSurfaceWind();
Optional<SurfaceWind> getSurfaceWind();

Optional<List<Weather>> getForecastWeather();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fi.fmi.avi.model.metar.immutable;


import java.io.Serializable;
import java.util.Collections;
import java.util.List;
Expand All @@ -16,12 +15,15 @@

import fi.fmi.avi.model.CloudForecast;
import fi.fmi.avi.model.NumericMeasure;
import fi.fmi.avi.model.SurfaceWind;
import fi.fmi.avi.model.Weather;
import fi.fmi.avi.model.immutable.CloudForecastImpl;
import fi.fmi.avi.model.immutable.NumericMeasureImpl;
import fi.fmi.avi.model.immutable.SurfaceWindImpl;
import fi.fmi.avi.model.immutable.WeatherImpl;
import fi.fmi.avi.model.metar.TrendForecast;
import fi.fmi.avi.model.metar.TrendForecastSurfaceWind;

;

/**
* Created by rinne on 13/04/2018.
Expand Down Expand Up @@ -69,7 +71,7 @@ public static Builder from(final TrendForecast value) {
.setPrevailingVisibilityOperator(value.getPrevailingVisibilityOperator())
.setNoSignificantWeather(value.isNoSignificantWeather())
.setPrevailingVisibility(NumericMeasureImpl.immutableCopyOf(value.getPrevailingVisibility()))
.setSurfaceWind(TrendForecastSurfaceWindImpl.immutableCopyOf(value.getSurfaceWind()))
.setSurfaceWind(SurfaceWindImpl.immutableCopyOf(value.getSurfaceWind()))
.setCloud(CloudForecastImpl.immutableCopyOf(value.getCloud()));

value.getForecastWeather()
Expand All @@ -86,8 +88,8 @@ public Builder setPrevailingVisibility(final NumericMeasure prevailingVisibility
}

@Override
@JsonDeserialize(as = TrendForecastSurfaceWindImpl.class)
public Builder setSurfaceWind(final TrendForecastSurfaceWind surfaceWind) {
@JsonDeserialize(as = SurfaceWindImpl.class)
public Builder setSurfaceWind(final SurfaceWind surfaceWind) {
return super.setSurfaceWind(surfaceWind);
}

Expand Down

This file was deleted.

13 changes: 7 additions & 6 deletions src/main/java/fi/fmi/avi/model/taf/TAFForecast.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import fi.fmi.avi.model.AviationCodeListUser;
import fi.fmi.avi.model.CloudForecast;
import fi.fmi.avi.model.NumericMeasure;
import fi.fmi.avi.model.SurfaceWind;
import fi.fmi.avi.model.Weather;

/**
Expand All @@ -23,7 +24,7 @@ public interface TAFForecast extends AviationCodeListUser {

Optional<AviationCodeListUser.RelationalOperator> getPrevailingVisibilityOperator();

Optional<TAFSurfaceWind> getSurfaceWind();
Optional<SurfaceWind> getSurfaceWind();

Optional<List<Weather>> getForecastWeather();

Expand Down Expand Up @@ -257,14 +258,14 @@ default B setPrevailingVisibilityOperator(final Optional<? extends AviationCodeL
* @throws NullPointerException
* if {@code surfaceWind} is null
*/
B setSurfaceWind(TAFSurfaceWind surfaceWind);
B setSurfaceWind(SurfaceWind surfaceWind);

/**
* Sets the value to be returned by {@link TAFForecast#getSurfaceWind()}.
*
* @return this {@code Builder} object
*/
default B setNullableSurfaceWind(@Nullable final TAFSurfaceWind surfaceWind) {
default B setNullableSurfaceWind(@Nullable final SurfaceWind surfaceWind) {
if (surfaceWind != null) {
return setSurfaceWind(surfaceWind);
} else {
Expand All @@ -283,7 +284,7 @@ default B setNullableSurfaceWind(@Nullable final TAFSurfaceWind surfaceWind) {
* @throws NullPointerException
* if {@code mapper} is null
*/
default B mapSurfaceWind(final UnaryOperator<TAFSurfaceWind> mapper) {
default B mapSurfaceWind(final UnaryOperator<SurfaceWind> mapper) {
return setSurfaceWind(getSurfaceWind().map(mapper));
}

Expand All @@ -298,14 +299,14 @@ default B mapSurfaceWind(final UnaryOperator<TAFSurfaceWind> mapper) {
/**
* Returns the value that will be returned by {@link TAFForecast#getSurfaceWind()}.
*/
Optional<TAFSurfaceWind> getSurfaceWind();
Optional<SurfaceWind> getSurfaceWind();

/**
* Sets the value to be returned by {@link TAFForecast#getSurfaceWind()}.
*
* @return this {@code Builder} object
*/
default B setSurfaceWind(final Optional<? extends TAFSurfaceWind> surfaceWind) {
default B setSurfaceWind(final Optional<? extends SurfaceWind> surfaceWind) {
if (surfaceWind.isPresent()) {
return setSurfaceWind(surfaceWind.get());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import fi.fmi.avi.model.AviationCodeListUser;
import fi.fmi.avi.model.immutable.CloudForecastImpl;
import fi.fmi.avi.model.immutable.NumericMeasureImpl;
import fi.fmi.avi.model.immutable.SurfaceWindImpl;
import fi.fmi.avi.model.immutable.WeatherImpl;
import fi.fmi.avi.model.taf.immutable.TAFSurfaceWindImpl;

/**
* Helper methods for implementations of {@link TAFForecast.Builder}.
Expand All @@ -39,7 +39,7 @@ public static void copyFrom(final TAFForecast.Builder<?, ?> builder, final TAFFo
builder.setNoSignificantWeather(value.isNoSignificantWeather());
builder.setPrevailingVisibility(NumericMeasureImpl.immutableCopyOf(value.getPrevailingVisibility()));
builder.setPrevailingVisibilityOperator(value.getPrevailingVisibilityOperator());
builder.setSurfaceWind(TAFSurfaceWindImpl.immutableCopyOf(value.getSurfaceWind()));
builder.setSurfaceWind(SurfaceWindImpl.immutableCopyOf(value.getSurfaceWind()));
builder.setForecastWeather(value.getForecastWeather()//
.map(list -> toImmutableList(list, WeatherImpl::immutableCopyOf)));
}
Expand Down Expand Up @@ -97,7 +97,7 @@ private static void mergePrevailingVisibilityOperator(final TAFForecast.Builder<

private static void mergeSurfaceWind(final TAFForecast.Builder<?, ?> builder, final TAFForecast from) {
from.getSurfaceWind()//
.map(TAFSurfaceWindImpl::immutableCopyOf)//
.map(SurfaceWindImpl::immutableCopyOf)//
.ifPresent(builder::setSurfaceWind);
}

Expand Down
27 changes: 0 additions & 27 deletions src/main/java/fi/fmi/avi/model/taf/TAFSurfaceWind.java

This file was deleted.

Loading

0 comments on commit 138cc9d

Please sign in to comment.