Skip to content
Snippets Groups Projects
Commit 71fa7dac authored by Christopher Schankula's avatar Christopher Schankula :earth_africa:
Browse files

done all JavaDoc?

parent 2c6a02c0
No related branches found
No related tags found
No related merge requests found
UML.png

865 KiB | W: | H:

UML.png

861 KiB | W: | H:

UML.png
UML.png
UML.png
UML.png
  • 2-up
  • Swipe
  • Onion skin
No preview for this file type
//Based on Bag from Sedgewick & Wayne Algorithms 4th Edition (2011).
package graph;
import java.util.Iterator;
public class Bag<Integer> implements Iterable<Integer> {
/**
* A class for storing an unordered collection of items.
* @author TrawlStars, Inc.
*
* @param <Value> The type of value to store in the Bag.
*/
public class Bag<Value> implements Iterable<Value> {
/**
* The first item in the bag.
*/
private BagNode first; //pointer to head of linked list
/**
* A node in the bag (like a linked-list node).
* @author TrawlStars, Inc.
*
*/
private class BagNode{
Integer item;
/**
* The item in the node
*/
Value item;
/**
* A pointer to the next node.
*/
BagNode next;
}
......@@ -15,31 +37,52 @@ public class Bag<Integer> implements Iterable<Integer> {
* Adds new node to linked list
* @param item the item to be added to the linked list
*/
public void add(Integer item){
public void add(Value item){
BagNode oldfirst = first;
first = new BagNode();
first.item = item;
first.next = oldfirst;
}
/**
* Provides an iterator of items in the bag.
*/
@Override
public Iterator<Integer> iterator() {
public Iterator<Value> iterator() {
return new ListIterator();
}
private class ListIterator implements Iterator<Integer>{
/**
* Generates an iterator of items in the bag.
* @author TrawlStars, Inc.
*
*/
private class ListIterator implements Iterator<Value>{
/**
* The first item in the bag.
*/
private BagNode current = first;
/**
* Returns whether there are more items in the bag.
* @return true if there are more items available, false otherwise.
*/
public boolean hasNext(){
return current != null;
}
/**
* Remove an item from the current iterator.
*/
public void remove(){
current.next = current.next.next;
}
public Integer next(){
/**
* Get the next value in the bag.
*/
public Value next(){
Integer item = current.item;
Value item = current.item;
current = current.next;
return item;
......
/*
* Based on implementation from Sedgewick & Wayne, Algorithms 4th Edition (2011).
*/
package graph;
import java.util.ArrayList;
/**
* Find the connected components in an undirected graph.
* @author TrawlStars, Inc.
*
*/
public class CC {
/**
* Whether a node has been visited by the DFS.
*/
private boolean[] marked;
/**
* A mapping from node to its component id.
*/
private int[] id;
/**
* The number of connected components in the graph.
*/
private int count;
public static void main(String[] args) {
Graph g = new Graph(7);
g.addEdge(4, 3);
g.addEdge(2, 3);
g.addEdge(1, 2);
g.addEdge(0, 2);
g.addEdge(5, 6);
CC component = new CC(g);
System.out.println(component.connected(2, 0)); //true
System.out.println(component.connected(0,1)); //true
System.out.println(component.connected(1, 5)); //false
//System.out.println(component.connected(1,6)); //throws exception (supposed to)
System.out.println(component.id(0));
System.out.println(component.id(5));
System.out.println(component.id(6));
}
/**
* Constructor for Connected Component
* @param G Graph object consisting of a completed graph
......
......@@ -10,6 +10,11 @@ import sort.Bound;
import sort.GeneralRange;
import sort.RangeHelper;
/**
* Class for clustering TrawlExpert Records according to an area of similarity.
* @author TrawlStars, Inc.
*
*/
public class Cluster {
/**
* Cluster the results of a basic search into groupings based on an area.
......@@ -64,6 +69,13 @@ public class Cluster {
return clusters;
}
/**
* Generate range functions for the search around a given node.
* @param lat The latitude about which to search.
* @param lon The longitude about which to search.
* @param area The area of searching.
* @return The GeneralRange functions for performing the range search.
*/
private static ArrayList<GeneralRange<Record>> ranges(double lat, double lon, double area){
double dist = Math.sqrt(area);
......@@ -75,10 +87,21 @@ public class Cluster {
return range;
}
/**
* Convert a distance to a range in terms of longitude (depends on latitude).
* @param dist The distance
* @param lat The current latitude.
* @return The amount of longitude degrees in half that distance.
*/
private static double lngRange(double dist, double lat){
return dist/(Math.cos(Math.toRadians(lat))*222);
}
/**
* Convert a distance to a range in terms of latitude (not dependant on longitude).
* @param dist The distance
* @return The amount of latitude degrees in half that distance.
*/
private static double latRange(double dist){
return (dist/222);
}
......
/*
* Based on code from Sedgewick & Wayne, Algorithms 4th Edition (2011).
*/
package graph;
/**
* An ADT for representing an undirected, unweighted graph.
* @author TrawlStars, Inc.
*
*/
public class Graph {
private final int V; // Number of nodes
private int E; // Number of edges
private Bag<Integer>[] adj; // Adjacency list for a node
/**
* Number of nodes in graph.
*/
private final int V;
/**
* Number of edges in graph
*/
private int E;
/**
* Adjacency list for all nodes.
*/
private Bag<Integer>[] adj;
public static void main(String[] args) {
}
/**
* Constructor used to build a graph of a specified size
* @param V The size of graph, or, the number of nodes in graph
......
......@@ -2,7 +2,13 @@ package search;
import java.io.Serializable;
// The interface for a function that returns one field (piece of data) from a record
/**
* The interface for a function that returns one field (piece of data) from a record
* @author Haley Glavina
*
* @param <Key> The key's type (extracted from the value) -- must implement Comparable
* @param <Value> The value's type (from which to extract the key)
*/
public interface Field<Key extends Comparable<Key>, Value> extends Serializable {
/**
* Given a value of type Value, extract a key of type Key from the Value.
......
......@@ -6,11 +6,11 @@ import java.util.ArrayList;
import sort.GeneralCompare;
/**
*
* @author HaleyGlavina
* Implements a Red-Black tree for maintaining a balanced binary tree.
* @author Haley Glavina
*
* @param <Key>
* @param <Value>
* @param <Key> The type of key to search by, must be comparable as defined by the GeneralCompare function given.
* @param <Value> The type of value to store in the tree.
*/
public class RedBlackTree<Key extends Comparable<Key>, Value> implements Serializable {
/**
......
package sort;
/**
* Enumeration of bound types.
* @author Christopher W. Schankula
*
*/
*/
public enum Bound {
LOWER, UPPER, LOWHIGH, ANY, EQUALS;
}
package sort;
import java.io.Serializable;
/**
* Interface describing a lambda function that takes two objects of a type T and compares them in some way.
* Should return < 0 if the first is less, = 0 if they are equal and > 0 if the first is larger.
* @author Christopher W. Schankula
*
* @param <T> The type parameter, can be any Comparable object.
*/
public interface GeneralCompare<T extends Comparable<T>> extends Serializable {
/**
* Compare two Comparable elements based on an arbitrary ordering definition.
......
package sort;
/**
* Interface describing a lambda function that takes one object of a type T and returns whether some aspect of it
* is in some range defined by the function.
* Should return < 0 if it is less than the range, = 0 if it is in the range and > 0 if it is bigger than the range.
* @author Christopher W. Schankula
*
* @param <T> The type parameter, can be any Comparable object.
*/
public interface GeneralRange<T extends Comparable<T>> {
/**
* Compare two Comparable elements based on an arbitrary ordering definition.
* @param a1 The first value to be compared.
* @param a2 The second value to be compared
* @return Integer < 0 if a1 is less than a2, 0 if equal and > 0 if a1 is bigger than a2
* @return Integer < 0 if it is less than the range, = 0 if it is in the range and > 0 if it is bigger than the range.
*/
public int isInBounds(T a1);
}
package sort;
/**
* An implementation of the MergeSort algorithm.
* @author Haley Glavina
*
*/
public class MergeSort{
/*// Main Function for Testing Purposes Only
public static void main(String[] args) {
......
package test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import graph.CC;
import graph.Graph;
public class TestConnectedComponents {
Graph g;
CC component;
@Before
public void setUp() throws Exception {
g = new Graph(7);
g.addEdge(4, 3);
g.addEdge(2, 3);
g.addEdge(1, 2);
g.addEdge(0, 2);
g.addEdge(5, 6);
component = new CC(g);
}
@Test
public void testConnected() {
assert(component.connected(2, 0)); //true
assert(component.connected(0,1)); //true
assert(!component.connected(1, 5)); //false
}
@Test
public void testComponentId() {
assert(component.id(0) == 0);
assert(component.id(5) == 1);
assert(component.id(6) == 1);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment