Commit 868542ed authored by Adam Blank's avatar Adam Blank
Browse files

Initial commit

parents
No related merge requests found
Showing with 1107 additions and 0 deletions
+1107 -0
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
data/*
static:
script: "/testers/cs2/project07/static"
C:
script: "/testers/cs2/project07/C/test"
B:
script: "/testers/cs2/project07/B/test"
A:
script: "/testers/cs2/project07/A/test"
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CheckStyle-IDEA">
<option name="configuration">
<map>
<entry key="checkstyle-version" value="8.13" />
<entry key="copy-libs" value="false" />
<entry key="location-0" value="BUNDLED:(bundled):Sun Checks" />
<entry key="location-1" value="BUNDLED:(bundled):Google Checks" />
<entry key="scan-before-checkin" value="false" />
<entry key="scanscope" value="JavaOnly" />
<entry key="suppress-errors" value="false" />
</map>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PreferredVcsStorage">
<preferredVcsName>ApexVCS</preferredVcsName>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/project07-beavermaps.iml" filepath="$PROJECT_DIR$/project07-beavermaps.iml" />
</modules>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
/* scaffolding */
/* ----------- */
.tt-menu,
.gist {
text-align: left;
}
/* base styles */
/* ----------- */
a {
color: #03739c;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.table-of-contents li {
display: inline-block;
*display: inline;
zoom: 1;
}
.table-of-contents li a {
font-size: 16px;
color: #999;
}
p + p {
margin: 30px 0 0 0;
}
/* site theme */
/* ---------- */
.title {
margin: 20px 0 0 0;
font-size: 64px;
}
.example {
padding: 30px 0;
}
.example-name {
margin: 20px 0;
font-size: 32px;
}
.demo {
position: relative;
*z-index: 1;
margin: 50px 0;
}
.typeahead,
.tt-query,
.tt-hint {
width: 422px;
/*height: 30px; */
padding: 8px 12px;
font-size: 24px;
line-height: 30px;
border: 2px solid #ccc;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
outline: none;
}
.typeahead {
background-color: #fff;
}
.typeahead:focus {
border: 2px solid #0097cf;
}
.tt-query {
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
}
.tt-hint {
color: #999
}
.tt-menu {
width: 422px;
padding: 8px 0;
background-color: #fff;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.2);
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
-webkit-box-shadow: 0 5px 10px rgba(0,0,0,.2);
-moz-box-shadow: 0 5px 10px rgba(0,0,0,.2);
box-shadow: 0 5px 10px rgba(0,0,0,.2);
}
.tt-suggestion {
padding: 3px 20px;
font-size: 18px;
line-height: 24px;
}
.tt-suggestion:hover {
cursor: pointer;
color: #fff;
background-color: #0097cf;
}
.tt-suggestion.tt-cursor {
color: #fff;
background-color: #0097cf;
}
.tt-suggestion p {
margin: 0;
}
.gist {
font-size: 14px;
}
/* example specific styles */
/* ----------------------- */
#custom-templates .empty-message {
padding: 5px 10px;
text-align: center;
}
#multiple-datasets .league-name {
margin: 0 20px 5px 20px;
padding: 3px 0;
border-bottom: 1px solid #ccc;
}
#scrollable-dropdown-menu .tt-menu {
max-height: 150px;
overflow-y: auto;
}
#rtl-support .tt-menu {
text-align: right;
z-index: 10;
}
.twitter-typeahead { width: 100%; }
.twitter-typeahead, .tt-hint, .tt-input, .tt-menu { width: 100%; }
.mapid {
height: 500px;
z-index: 0;
}
.tt-hint {
visibility:hidden;
}
\ No newline at end of file
$(function() {
var movies = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/autocomplete?query=%QUERY',
wildcard: '%QUERY'
}
});
$('#place-name').typeahead(null, {
name: 'movies',
limit: 10,
display: 'value',
hint: false,
highlight: false,
source: movies
});
$('#place-name').bind('typeahead:autocompleted', function(ev, suggestion) {
ids[suggestion['value']] = suggestion['id']
});
$('#place-name').bind('typeahead:selected', function(ev, suggestion) {
ids[suggestion['value']] = suggestion['id']
});
$('#end-name').typeahead(null, {
name: 'end',
limit: 10,
display: 'value',
hint: false,
highlight: false,
source: movies
});
$('#end-name').bind('typeahead:autocompleted', function(ev, suggestion) {
ids_for_end[suggestion['value']] = suggestion['id']
});
$('#end-name').bind('typeahead:selected', function(ev, suggestion) {
ids_for_end[suggestion['value']] = suggestion['id']
});
});
\ No newline at end of file
var ids = {}, ids_for_end = {};
$(function() {
mymap = L.map('mapid').setView([34.1377, -118.1253], 17);
var greenIcon = new L.Icon({
iconUrl: 'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-green.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});
L.tileLayer('https://api.mapbox.com/styles/v1/vigneshv59/cjs8ac0jc1lsb1fo05dxnke1r/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoidmlnbmVzaHY1OSIsImEiOiJjanM4OW40emwwZDloNGJtam9zNjczM2l1In0.EcwQfh4bxp5HCB6sqy0uhw', {
attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 19,
id: 'mapbox.streets',
accessToken: 'your.mapbox.access.token'
}).addTo(mymap);
var last_active = $("#place-name");
var markers, path, circle;
function update(name, id) {
if (last_active[0].id === "place-name") {
ids[name] = id;
}
else {
ids_for_end[name] = id;
}
last_active.val(name);
}
function clear() {
if (path) {
mymap.removeLayer(path);
path = null;
}
if (circle) {
mymap.removeLayer(circle);
circle = null;
}
if (markers) {
markers.clearLayers()
markers = null;
}
}
$("#search").on('click', function() {
$("#search").addClass('active');
$("#directions").removeClass('active');
$("#end-name").attr('hidden', true);
$("#all").removeAttr('hidden');
$("#nearby").removeAttr('hidden');
$("#findpath").attr('hidden', true);
last_active = $("#place-name");
});
$("#directions").on('click', function() {
$("#directions").addClass('active');
$("#search").removeClass('active');
$("#end-name").removeAttr('hidden');
$("#all").attr('hidden', true);
$("#nearby").attr('hidden', true);
$("#findpath").removeAttr('hidden');
});
$("#place-name").on('focus', function() {
last_active = $("#place-name");
});
$("#end-name").on('focus', function() {
last_active = $("#end-name");
});
$("#findpath").click(function() {
clear();
$.get("/pathfinder", {'start-id': ids[$("#place-name").val()], 'start': $("#place-name").val(), 'end-id': ids_for_end[$("#end-name").val()],'end': $("#end-name").val()}, function(data) {
data = data.substring(1, data.length - 1).split(",");
var start = data[0];
var end = data[data.length - 1];
data = data.slice(1, data.length - 1);
var ms = [];
$.each(data, function(i, val) {
var varr = val.split("::");
var lat = varr[0];
var lon = varr[1];
var m = new L.LatLng(parseFloat(lat), parseFloat(lon));
ms.push(m);
})
path = new L.Polyline(ms, {
color: 'blue',
weight: 3,
opacity: 0.5,
smoothFactor: 1
});
path.addTo(mymap);
});
});
$("#nearby").click(function() {
clear();
var pname = $("#place-name").val();
pname = pname.replace(/ \(.*\)$/, "")
$.get("/nearby", {'id': ids[$("#place-name").val()], 'name': pname, 'distance': 200}, function(data) {
data = data.substring(1, data.length - 1).split(",")
var ms = []
var varr = data[0].split("::");
var lat = varr[0];
var lon = varr[1];
var m = L.marker([parseFloat(lat), parseFloat(lon)], {icon: greenIcon})
if (varr[2] != "null") {
m.bindPopup(varr[2]).on('click', function() {
update(varr[2], varr[3]);
});
}
ms.push(m)
mymap.setView([parseFloat(lat), parseFloat(lon)], 18);
data = data.slice(1);
$.each(data, function(i, val) {
var varr = val.split("::")
var lat = varr[0]
var lon = varr[1]
var m = L.marker([parseFloat(lat), parseFloat(lon)])
if (varr[2] != "null") {
m.bindPopup(varr[2]).on('click', function() {
update(varr[2], varr[3]);
});
}
ms.push(m)
})
circle = new L.circle([lat, lon], 60);
circle.addTo(mymap);
markers = L.layerGroup(ms).addTo(mymap);
})
})
$("#all").click(function() {
clear();
var pname = $("#place-name").val();
pname = pname.replace(/ \(.*\)$/, "")
$.get("/byname", {'query': pname}, function(data) {
data = data.substring(1, data.length - 1).split(",")
var ms = []
mymap.setZoom(10);
$.each(data, function(i, val) {
var varr = val.split("::")
var lat = varr[0]
var lon = varr[1]
var m = L.marker([parseFloat(lat), parseFloat(lon)])
if (varr[2] != "null") {
m.bindPopup(varr[2]).on('click', function() {
update(varr[2], varr[3]);
});
}
ms.push(m)
})
markers = L.layerGroup(ms).addTo(mymap);
})
});
var _dblClickTimer = null;
mymap.addEventListener('click', function(ev) {
lat = ev.latlng.lat;
lon = ev.latlng.lng;
if (_dblClickTimer !== null) {
return;
}
_dblClickTimer = setTimeout(() => {
$.getJSON("/nearest", {'lat': lat, 'lon': lon}, function(data) {
clear();
var ms = [];
var m = L.marker([data.lat, data.lon], {icon: greenIcon});
update(data.name, data.id);
if (data.name != "null") {
m.bindPopup(data.name).on('click', function() {
update(data.name, data.id);
})
}
ms.push(m)
markers = L.layerGroup(ms).addTo(mymap);
});
_dblClickTimer = null;
}, 200);
}).on("dblclick", function() {
clearTimeout(_dblClickTimer);
_dblClickTimer = null;
// real 'dblclick' handler here (if any). Do not add anything to just have the default zoom behavior
});
})
\ No newline at end of file
This diff is collapsed.
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel='stylesheet' type='text/css' href='https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css'>
<link rel='stylesheet' type='text/css' href='/css/map.css'>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css"
integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="
crossorigin=""/>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="/js/map.js" type='text/javascript'></script>
<script src="/js/typeahead.js" type='text/javascript'></script>
<script src="/js/autocomplete.js" type='text/javascript'></script>
<script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js"
integrity="sha512-QVftwZFqvtRNi0ZyCtsznlKSWOStnDORoefr1enyq5mVL4tmKB3S/EnC3rRJcxCPavG10IcrVGSmPh6Qw5lwrg=="
crossorigin=""></script>
</head>
<body>
<nav class="navbar navbar-light bg-light">
<a class="navbar-brand" href="#">BeaverMaps</a>
</nav>
<br>
<div class="container container-fluid">
<ul class="nav nav-tabs">
<li class="nav-item">
<a id="search" class="nav-link active" href="#">Search</a>
</li>
<li class="nav-item">
<a id="directions" class="nav-link" href="#">Route</a>
</li>
</ul>
<br>
<div class="input-group">
<input class="form-control" id="place-name" placeholder="Location" autocomplete="off">
<br>
<input hidden=true class="form-control" id="end-name" placeholder="Destination" autocomplete="off">
<br>
<div class="input-group">
<button class="btn btn-outline-secondary" type="button" id="all">Find All</button>
<button class="btn btn-outline-secondary" type="button" id="nearby">Find Places Nearby</button>
<button hidden=true class="btn btn-outline-secondary" type="button" id="findpath">Find Route</button>
</div>
</div>
<br>
<div id="mapid" class="mapid"></div>
</div>
</body>
</html>
<script>
$('#place-name').keypress(function (e) {
var key = e.which;
if(key == 13) // the enter key code
{
if ($("#findpath").is(":hidden")) {
$('#all').click();
} else {
$("#findpath").click();
}
return false;
}
});
$('#end-name').keypress(function (e) {
var key = e.which;
if(key == 13) // the enter key code
{
$("#findpath").click();
return false;
}
});
</script>
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="com.github.javaparser:javaparser-core:3.5.12" level="project" />
<orderEntry type="library" name="org.hamcrest:hamcrest-all:1.3" level="project" />
<orderEntry type="library" name="org.junit.jupiter:junit-jupiter-params:5.4.0-RC2" level="project" />
<orderEntry type="library" name="com.google.code.gson:gson:2.8.5" level="project" />
</component>
</module>
\ No newline at end of file
package edu.caltech.cs2.datastructures;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import edu.caltech.cs2.interfaces.IDeque;
import edu.caltech.cs2.interfaces.IDictionary;
import edu.caltech.cs2.interfaces.ISet;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class BeaverMapsGraph extends Graph<Long, Double> {
private static JsonParser JSON_PARSER = new JsonParser();
private IDictionary<Long, Location> ids;
private ISet<Location> buildings;
public BeaverMapsGraph() {
super();
this.buildings = new ChainingHashSet<>();
this.ids = new ChainingHashDictionary<>(MoveToFrontDictionary::new);
}
/**
* Reads in buildings, waypoinnts, and roads file into this graph.
* Populates the ids, buildings, vertices, and edges of the graph
* @param buildingsFileName the buildings filename
* @param waypointsFileName the waypoints filename
* @param roadsFileName the roads filename
*/
public BeaverMapsGraph(String buildingsFileName, String waypointsFileName, String roadsFileName) {
this();
// TODO (student): Write This
}
/**
* Returns a deque of all the locations with the name locName.
* @param locName the name of the locations to return
* @return a deque of all location with the name locName
*/
public IDeque<Location> getLocationByName(String locName) {
// TODO (student): Write This
return null;
}
/**
* Returns the Location object corresponding to the provided id
* @param id the id of the object to return
* @return the location identified by id
*/
public Location getLocationByID(long id) {
// TODO (student): Write This
return null;
}
/**
* Adds the provided location to this map.
* @param n the location to add
* @return true if n is a new location and false otherwise
*/
public boolean addVertex(Location n) {
// TODO (student): Write This
return false;
}
/**
* Returns the closest building to the location (lat, lon)
* @param lat the latitude of the location to search near
* @param lon the longitute of the location to search near
* @return the building closest to (lat, lon)
*/
public Location getClosestBuilding(double lat, double lon) {
// TODO (student): Write This
return null;
}
/**
* Returns a set of locations which are no more than threshold feet
* away from start.
* @param start the location to search around
* @param threshold the number of feet in the search radius
* @return
*/
public ISet<Location> dfs(Location start, double threshold) {
// TODO (student): Write This
return null;
}
/**
* Returns a list of Locations corresponding to
* buildings in the current map.
* @return a list of all building locations
*/
public ISet<Location> getBuildings() {
return this.buildings;
}
/**
* Returns a shortest path (i.e., a deque of vertices) between the start
* and target locations (including the start and target locations).
* @param start the location to start the path from
* @param target the location to end the path at
* @return a shortest path between start and target
*/
public IDeque<Location> dijkstra(Location start, Location target) {
// TODO (student): Write This
return null;
}
/**
* Returns a JsonElement corresponding to the data in the file
* with the filename filename
* @param filename the name of the file to return the data from
* @return the JSON data from filename
*/
private static JsonElement fromFile(String filename) {
try {
return JSON_PARSER.parse(
new FileReader(
new File(filename)
)
);
} catch (IOException e) {
return null;
}
}
}
\ No newline at end of file
package edu.caltech.cs2.datastructures;
import edu.caltech.cs2.interfaces.ICollection;
import edu.caltech.cs2.interfaces.ISet;
public class ChainingHashSet<E> extends ISet<E> {
public ChainingHashSet() {
super(new ChainingHashDictionary<>(MoveToFrontDictionary::new));
}
public ChainingHashSet(ICollection<E> c) {
this();
for (E x : c) {
this.add(x);
}
}
}
package edu.caltech.cs2.datastructures;
import edu.caltech.cs2.interfaces.*;
public class Graph<V, E> extends IGraph<V, E> {
@Override
public boolean addVertex(V vertex) {
return false;
}
@Override
public boolean addEdge(V src, V dest, E e) {
return false;
}
@Override
public boolean addUndirectedEdge(V src, V dest, E e) {
return false;
}
@Override
public boolean removeEdge(V src, V dest) {
return false;
}
@Override
public ISet<V> vertices() {
return null;
}
@Override
public E adjacent(V i, V j) {
return null;
}
@Override
public ISet<V> neighbors(V vertex) {
return null;
}
}
\ No newline at end of file
package edu.caltech.cs2.datastructures;
import com.google.gson.JsonObject;
import java.util.List;
public class Location {
public enum Type {
BUILDING,
WAYPOINT;
}
public static final double EARTH_RAD_FT = 20925721.784777;
public final long id;
public final double lat;
public final double lon;
public final String amenity;
public String name;
public final String address;
public final String shop;
public final Type type;
public Location(long id, double latitude, double longitude,
String name, String addr, String amenity, String shop, String type) {
this.id = id;
this.lat = latitude;
this.lon = longitude;
this.type = type.equals("building") ? Type.BUILDING : Type.WAYPOINT;
this.amenity = amenity;
this.shop = shop;
this.name = name;
this.address = addr;
}
public Location(long id) {
this(id, 0, 0, null, null, null, null, "waypoint");
}
public Location(JsonObject e) {
this.id = Long.parseLong(e.get("id").getAsString());
this.lat = e.get("lat").getAsDouble();
this.lon = e.get("lon").getAsDouble();
String[] props = new String[5];
int i = 0;
for (String prop : List.of("name", "amenity", "shop", "type", "address")) {
if (e.has(prop)) {
props[i] = e.get(prop).getAsString();
}
i++;
}
this.name = props[0];
this.amenity = props[1];
this.shop = props[2];
this.type = props[3].equals("building") ? Type.BUILDING : Type.WAYPOINT;
this.address = props[4];
}
public String displayString() {
String s = this.name;
if (this.address != null) {
s += " (" + this.address + ")";
} else {
s += " (" + this.lat + ", " + this.lon + ")";
}
return s;
}
public double getDistance(double lat, double lon) {
double dLat = Math.toRadians(lat - this.lat);
double dLon = Math.toRadians(lon - this.lon);
return 2 * EARTH_RAD_FT * Math.asin(Math.sqrt(
Math.pow(Math.sin(dLat / 2), 2) + Math.pow(Math.sin(dLon / 2), 2) *
Math.cos(Math.toRadians(this.lat)) *
Math.cos(Math.toRadians(lat))));
}
public double getDistance(Location other) {
return this.getDistance(other.lat, other.lon);
}
public static double getDistance(double lat1, double lon1, double lat2, double lon2) {
return new Location(0, lat1, lon1, null, null, null, null, "building").getDistance(lat2, lon2);
}
public String toString() {
StringBuilder s = new StringBuilder();
s.append("{");
s.append("\"id\": " + "\"" + this.id + "\"");
s.append(", ");
s.append("\"lat\": " + this.lat);
s.append(", ");
s.append("\"lon\": " + this.lon);
s.append(", ");
s.append("\"type\": " + "\"" + (this.type == Type.BUILDING ? "building" : "footpath") + "\"");
if (this.amenity != null) {
s.append(", \"amenity\": " + "\"" + this.amenity + "\"");
}
if (this.address != null) {
s.append(", \"address\": " + "\"" + this.address + "\"");
}
if (this.shop != null) {
s.append(", \"shop\": " + "\"" + this.shop + "\"");
}
if (this.name != null) {
s.append(", \"name\": " + "\"" + this.name.replace("\"", "\\\"") + "\"");
}
s.append("}");
return s.toString();
}
public int hashCode() {
return Long.hashCode(this.id);
}
public boolean equals(Object o) {
if (!(o instanceof Location)) {
return false;
}
return this.id == ((Location)o).id;
}
}
package edu.caltech.cs2.interfaces;
import java.util.Iterator;
/**
* This interface represents some group or collection of elements.
* @param <E> Element type
*/
public interface ICollection<E> extends Iterable<E> {
/**
* Add an element to the collection.
* @param e Element to add
*/
public void add(E e);
/**
* Removes all elements from the collection.
*/
public void clear();
/**
* Generates an iterator over the collection.
* @return Iterator over the collection
*/
@Override
public Iterator<E> iterator();
/**
* Checks if an element is contained in the collection.
* @param e Element to check for
* @return True if element is contained in collection, false otherwise
*/
default public boolean contains(E e) {
for (E item : this) {
if (e == null ? item == null : e.equals(item)) {
return true;
}
}
return false;
}
/**
* Calculates the size of the collection.
* @return Number of elements in the collection
*/
public int size();
/**
* Checks whether the collection contains no elements.
* @return True if no elements are contained, false otherwise
*/
default public boolean isEmpty() {
return this.size() == 0;
}
}
package edu.caltech.cs2.interfaces;
/**
* This interface represents a deque - a data structure that can add and remove elements from either end of a list.
* @param <E> Element type
*/
public interface IDeque<E> extends ICollection<E> {
/**
* Add an element to the front end of the deque.
* @param e Element to add
*/
public void addFront(E e);
/**
* Add an element to the back end of the deque.
* @param e Element to add
*/
public void addBack(E e);
/**
* Adds an element to the collection.
* @param e Element to add
*/
@Override
default public void add(E e){
this.addFront(e);
}
/**
* Adds a collection of elements to this collection.
* @param c Collection of elements to add
*/
default public void addAll(ICollection<E> c) {
for (E e : c) {
this.add(e);
}
}
/**
* Removes and returns the element at the front end of the deque. Returns null if deque is empty.
* @return Element at front, if one exists; null otherwise
*/
public E removeFront();
/**
* Removes and returns the element at the back end of the deque. Returns null if deque is empty.
* @return Element at back, if one exists; null otherwise
*/
public E removeBack();
/**
* Removes all elements in the deque.
*/
@Override
default public void clear() {
while (!this.isEmpty()) {
this.removeBack();
}
}
/**
* Returns (but does not remove) the element at one end of the deque. Returns null if deque is empty.
* Note: The side you peek from should be chosen such that both the IQueue and IStack interfaces are implemented correctly.
* @return Element at one end, if one exists; null otherwise
*/
public E peek();
/**
* Returns (but does not remove) the element at the front end of the deque. Returns null if deque is empty.
* @return Element at front, if one exists; null otherwise
*/
public E peekFront();
/**
* Returns (but does not remove) the element at the back end of the deque. Returns null if deque is empty.
* @return Element at back, if one exists; null otherwise
*/
public E peekBack();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment