Skip to content

Commit

Permalink
Added Optional to getCenter to made code more Java8
Browse files Browse the repository at this point in the history
  • Loading branch information
buma committed May 11, 2015
1 parent 511ef3a commit 1d49a19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
Expand Up @@ -14,6 +14,7 @@ the License, or (at your option) any later version.
package org.opentripplanner.api.resource; package org.opentripplanner.api.resource;


import java.util.HashSet; import java.util.HashSet;
import java.util.Optional;


import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
Expand Down Expand Up @@ -94,11 +95,12 @@ public GraphMetadata(Graph graph) {
setLowerLeftLatitude(Math.min(rightEnv.getMinY(), leftEnv.getMinY())); setLowerLeftLatitude(Math.min(rightEnv.getMinY(), leftEnv.getMinY()));
} }


Coordinate center = graph.getCenter(); Optional<Coordinate> centerOptional = graph.getCenter();
if (center != null) { centerOptional.ifPresent(center -> {
setCenterLongitude(center.x); setCenterLongitude(center.x);
setCenterLatitude(center.y); setCenterLatitude(center.y);
} else { });
if (!centerOptional.isPresent()) {
// Does not work around 180th parallel. // Does not work around 180th parallel.
setCenterLatitude((upperRightLatitude + lowerLeftLatitude) / 2); setCenterLatitude((upperRightLatitude + lowerLeftLatitude) / 2);
setCenterLongitude((upperRightLongitude + lowerLeftLongitude) / 2); setCenterLongitude((upperRightLongitude + lowerLeftLongitude) / 2);
Expand Down
17 changes: 3 additions & 14 deletions src/main/java/org/opentripplanner/routing/graph/Graph.java
Expand Up @@ -25,18 +25,7 @@ the License, or (at your option) any later version.
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass; import java.io.ObjectStreamClass;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.prefs.Preferences; import java.util.prefs.Preferences;


Expand Down Expand Up @@ -1009,7 +998,7 @@ public void calculateTransitCenter() {
} }
} }


public Coordinate getCenter() { public Optional<Coordinate> getCenter() {
return center; return Optional.ofNullable(center);
} }
} }

0 comments on commit 1d49a19

Please sign in to comment.