First commit, added all projects
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
package feature;
|
||||
|
||||
import geography.GeographicShape;
|
||||
import geography.PiecewiseLinearCurve;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a street containing one or more segments.
|
||||
*/
|
||||
public class Street extends AbstractFeature
|
||||
{
|
||||
private static final String SPACE = " ";
|
||||
|
||||
private PiecewiseLinearCurve shape;
|
||||
@SuppressWarnings("unused")
|
||||
private String category;
|
||||
@SuppressWarnings("unused")
|
||||
private String code;
|
||||
@SuppressWarnings("unused")
|
||||
private String name;
|
||||
@SuppressWarnings("unused")
|
||||
private String prefix;
|
||||
@SuppressWarnings("unused")
|
||||
private String suffix;
|
||||
private List<StreetSegment> segments;
|
||||
|
||||
|
||||
/**
|
||||
* @param prefix
|
||||
* @param name
|
||||
* @param category
|
||||
* @param suffix
|
||||
* @param code
|
||||
*/
|
||||
public Street(final String prefix, final String name, final String category, final String suffix,
|
||||
final String code)
|
||||
{
|
||||
super(code);
|
||||
this.shape = new PiecewiseLinearCurve(code);
|
||||
this.prefix = prefix;
|
||||
this.name = name;
|
||||
this.category = category;
|
||||
this.suffix = suffix;
|
||||
this.code = code;
|
||||
this.segments = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param segment
|
||||
*/
|
||||
public void addSegment(final StreetSegment segment)
|
||||
{
|
||||
segments.add(segment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a canonical name from street components.
|
||||
*
|
||||
* @param prefix
|
||||
* The street prefix (e.g., "N", "E")
|
||||
* @param name
|
||||
* The street name
|
||||
* @param category
|
||||
* The street category (e.g., "St", "Ave")
|
||||
* @param suffix
|
||||
* The street suffix (e.g., "NW", "SE")
|
||||
* @return The canonical street name
|
||||
*/
|
||||
public static String createCanonicalName(final String prefix, final String name,
|
||||
final String category, final String suffix)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (prefix != null)
|
||||
{
|
||||
sb.append(prefix).append(SPACE);
|
||||
}
|
||||
|
||||
if (name != null)
|
||||
{
|
||||
sb.append(name).append(SPACE);
|
||||
}
|
||||
|
||||
if (category != null)
|
||||
{
|
||||
sb.append(category).append(SPACE);
|
||||
}
|
||||
|
||||
if (suffix != null)
|
||||
{
|
||||
sb.append(suffix);
|
||||
}
|
||||
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the segments of this street.
|
||||
*
|
||||
* @param number
|
||||
* @return The list of segments
|
||||
*/
|
||||
public List<StreetSegment> getSegments(final int number)
|
||||
{
|
||||
List<StreetSegment> numSegments = new ArrayList<>();
|
||||
for (StreetSegment segment : this.segments)
|
||||
{
|
||||
if (segment.getLowAddress() <= number && segment.getHighAddress() >= number)
|
||||
{
|
||||
numSegments.add(segment);
|
||||
}
|
||||
}
|
||||
|
||||
return numSegments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The segments
|
||||
*/
|
||||
public Iterator<StreetSegment> getSegments()
|
||||
{
|
||||
return segments.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeographicShape getGeographicShape()
|
||||
{
|
||||
return shape;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The size
|
||||
*/
|
||||
public int getSize()
|
||||
{
|
||||
return segments.size();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user