Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added traffic tendecy #1479

Merged
merged 4 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Mapbox welcomes participation and contributions from everyone.

### main
- Added traffic tendency annotations. [#1479](https://github.com/mapbox/mapbox-java/pull/1479)

### v6.8.0-beta.1 - August 12, 2022
- Fixed an issue where the `RouteOptions#...List` parameters were not reset correctly (for example, `routeOptions.toBuilder().bearingsList(null).build()` did not reset bearings to null). [#1469](https://github.com/mapbox/mapbox-java/pull/1469)
Expand Down
2 changes: 1 addition & 1 deletion samples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ dependencies {

buildConfig {
packageName = 'com.mapbox.sample'
buildConfigField 'String', 'MAPBOX_ACCESS_TOKEN', System.getenv("MAPBOX_ACCESS_TOKEN")
buildConfigField 'String', 'MAPBOX_ACCESS_TOKEN', project.hasProperty('MAPBOX_ACCESS_TOKEN') ? project.property('MAPBOX_ACCESS_TOKEN') : System.getenv('MAPBOX_ACCESS_TOKEN')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mapbox.api.directions.v5;

import androidx.annotation.IntDef;
import androidx.annotation.StringDef;

import java.lang.annotation.Retention;
Expand Down Expand Up @@ -143,6 +144,13 @@ public final class DirectionsCriteria {
*/
public static final String ANNOTATION_CLOSURE = "closure";

/*
* The tendency value conveys the changing
* state of traffic congestion (increasing, decreasing, constant etc).
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final String ANNOTATION_TRAFFIC_TENDENCY = "traffic_tendency";

/**
* Exclude all tolls along the returned directions route.
*
Expand Down Expand Up @@ -270,6 +278,42 @@ public final class DirectionsCriteria {
*/
public static final String APPROACH_CURB = "curb";

/*
* Conveys the changing state of traffic congestion: unknown.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final int TRAFFIC_TENDENCY_UNKNOWN = 0;

/*
* Conveys the changing state of traffic congestion: constant.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final int TRAFFIC_TENDENCY_CONSTANT_CONGESTION = 1;

/*
* Conveys the changing state of traffic congestion: increasing.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final int TRAFFIC_TENDENCY_INCREASING_CONGESTION = 2;

/*
* Conveys the changing state of traffic congestion: decreasing.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final int TRAFFIC_TENDENCY_DECREASING_CONGESTION = 3;

/*
* Conveys the changing state of traffic congestion: rapidly increasing.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final int TRAFFIC_TENDENCY_RAPIDLY_INCREASING_CONGESTION = 4;

/*
* Conveys the changing state of traffic congestion: rapidly decreasing.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final int TRAFFIC_TENDENCY_RAPIDLY_DECREASING_CONGESTION = 5;

private DirectionsCriteria() {
//not called
}
Expand Down Expand Up @@ -329,7 +373,8 @@ private DirectionsCriteria() {
ANNOTATION_CONGESTION,
ANNOTATION_CONGESTION_NUMERIC,
ANNOTATION_MAXSPEED,
ANNOTATION_CLOSURE
ANNOTATION_CLOSURE,
ANNOTATION_TRAFFIC_TENDENCY
})
public @interface AnnotationCriteria {
}
Expand Down Expand Up @@ -417,4 +462,23 @@ private DirectionsCriteria() {
})
public @interface ApproachesCriteria {
}

/*
* Retention policy for the traffic tendency annotations.
* The tendency value conveys the changing state of traffic
* congestion (increasing, decreasing, constant etc). New values
* could be introduced in the future without an API version change.
*/
@SuppressWarnings("checkstyle:javadoctype")
@Retention(RetentionPolicy.CLASS)
@IntDef({
TRAFFIC_TENDENCY_UNKNOWN,
TRAFFIC_TENDENCY_CONSTANT_CONGESTION,
TRAFFIC_TENDENCY_INCREASING_CONGESTION,
TRAFFIC_TENDENCY_DECREASING_CONGESTION,
TRAFFIC_TENDENCY_RAPIDLY_INCREASING_CONGESTION,
TRAFFIC_TENDENCY_RAPIDLY_DECREASING_CONGESTION
})
public @interface TrafficTendencyCriteria {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the annotation used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only in comments

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mapbox.api.directions.v5.models;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.auto.value.AutoValue;
import com.google.gson.Gson;
Expand Down Expand Up @@ -92,6 +93,18 @@ public static Builder builder() {
@SerializedName("congestion_numeric")
public abstract List<Integer> congestionNumeric();

/*
* The traffic tendency between each pair of coordinates.
* @return a list of {@link Integer} where each value matches
* {@link DirectionsCriteria.TrafficTendencyCriteria}. The tendency value conveys the changing
* state of traffic congestion (increasing, decreasing, constant etc). New values
* could be introduced in the future without an API version change.
*/
@SuppressWarnings("checkstyle:javadocmethod")
@Nullable
@SerializedName("traffic_tendency")
public abstract List<Integer> trafficTendency();

/**
* Convert the current {@link LegAnnotation} to its builder holding the currently assigned
* values. This allows you to modify a single property and then rebuild the object resulting in
Expand Down Expand Up @@ -196,12 +209,23 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
*/
public abstract Builder congestionNumeric(@Nullable List<Integer> congestionNumeric);

/*
* The traffic tendency between each pair of coordinates.
* @param trafficTendency is a list of {@link Integer} where each value matches
* {@link DirectionsCriteria.TrafficTendencyCriteria}. The tendency value conveys the changing
* state of traffic congestion (increasing, decreasing, constant etc).
*/
@SuppressWarnings("checkstyle:javadocmethod")
@NonNull
public abstract Builder trafficTendency(@Nullable List<Integer> trafficTendency);

/**
* Build a new {@link LegAnnotation} object.
*
* @return a new {@link LegAnnotation} using the provided values in this builder
* @since 3.0.0
*/
public abstract LegAnnotation build();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void testSerialization() throws IOException {
assertNotNull(directionsRefreshResponse.route().legs().get(0).annotation());
assertTrue(directionsRefreshResponse.route().legs().get(0).annotation().congestion().size() > 0);
assertTrue(directionsRefreshResponse.route().legs().get(0).incidents().size() > 0);
assertTrue(directionsRefreshResponse.route().legs().get(0).annotation().trafficTendency().size() > 0);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void testSerialization() throws IOException {
assertNotNull(directionsRouteRefresh.legs().get(0).annotation().congestion());
assertNotNull(directionsRouteRefresh.legs().get(0).incidents());
assertTrue(directionsRouteRefresh.legs().get(0).incidents().size() > 0);
assertTrue(directionsRouteRefresh.legs().get(0).annotation().trafficTendency().size() > 0);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import com.mapbox.api.directions.v5.DirectionsCriteria;
import com.mapbox.api.directions.v5.models.Congestion;
import com.mapbox.api.directions.v5.models.Incident;
import com.mapbox.api.directions.v5.models.LegAnnotation;
Expand Down Expand Up @@ -70,6 +71,14 @@ public void fromJson() {
0.1,
10.2
);
List<Integer> trafficTendency = Arrays.asList(
DirectionsCriteria.TRAFFIC_TENDENCY_UNKNOWN,
DirectionsCriteria.TRAFFIC_TENDENCY_CONSTANT_CONGESTION,
DirectionsCriteria.TRAFFIC_TENDENCY_INCREASING_CONGESTION,
DirectionsCriteria.TRAFFIC_TENDENCY_DECREASING_CONGESTION,
DirectionsCriteria.TRAFFIC_TENDENCY_RAPIDLY_INCREASING_CONGESTION,
DirectionsCriteria.TRAFFIC_TENDENCY_RAPIDLY_DECREASING_CONGESTION
);

List<Incident> incidents = Arrays.asList(
Incident.builder()
Expand Down Expand Up @@ -110,6 +119,7 @@ public void fromJson() {
.duration(durations)
.maxspeed(maxSpeeds)
.speed(speeds)
.trafficTendency(trafficTendency)
.build()
)
.incidents(incidents)
Expand All @@ -123,4 +133,22 @@ public void fromJson() {
assertEquals(routeLegRefresh, fromJson);
}

@Test
public void trafficTendencyFromJson() {
String json = "{\"traffic_tendency\": [0,1,2,3,4,5]}";
LegAnnotation expectedAnnotations = LegAnnotation.builder()
.trafficTendency(Arrays.asList(
DirectionsCriteria.TRAFFIC_TENDENCY_UNKNOWN,
DirectionsCriteria.TRAFFIC_TENDENCY_CONSTANT_CONGESTION,
DirectionsCriteria.TRAFFIC_TENDENCY_INCREASING_CONGESTION,
DirectionsCriteria.TRAFFIC_TENDENCY_DECREASING_CONGESTION,
DirectionsCriteria.TRAFFIC_TENDENCY_RAPIDLY_INCREASING_CONGESTION,
DirectionsCriteria.TRAFFIC_TENDENCY_RAPIDLY_DECREASING_CONGESTION
))
.build();

LegAnnotation fromJson = LegAnnotation.fromJson(json);

assertEquals(expectedAnnotations, fromJson);
}
}
Loading