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

Feature/framework v2 #41

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
20 changes: 20 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# DrawIO backup files
**/*.bkp
**/*.bkp
/bin/
/target/
/data/
*.kml
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PLP</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
8 changes: 8 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=21
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
71 changes: 71 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>PLP</groupId>
<artifactId>PLP</artifactId>
<version>1.0.0</version>

<properties>
<slf4j.version>2.0.16</slf4j.version>
</properties>

<repositories>
<repository>
<id>JOSM</id>
<name>JOSM</name>
<url>https://josm.openstreetmap.de/nexus/content/repositories/releases/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.uber</groupId>
<artifactId>h3</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>uk.m0nom</groupId>
<artifactId>javaapiforkml</artifactId>
<version>3.0.10</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
<version>1.20.0</version>
</dependency>
<dependency>
<groupId>org.openstreetmap.jmapviewer</groupId>
<artifactId>jmapviewer</artifactId>
<version>2.22</version>
</dependency>
</dependencies>

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>21</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
5 changes: 5 additions & 0 deletions src/plp/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package plp;

public class Config {
public static final int H3_RESOLUTION = 9; // Shared configuration variable for resolution
}
51 changes: 51 additions & 0 deletions src/plp/SystemRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package plp;

import java.util.List;

import plp.filter.DataFilter;
import plp.filters.*;
import plp.location.LocationCell;
import plp.operator.LogicalOperator;
import plp.output.KMLGenerator;

public class SystemRunner {
public static void main(String[] args) {

// Create Filters
LightPollutionFilter lightPollutionFilter = new LightPollutionFilter();
lightPollutionFilter.setRequirements(21.65); // Minimum SQM value

LightPollutionFilter lightPollutionFilterNot = new LightPollutionFilter();
lightPollutionFilterNot.setRequirements(21.6); // Minimum SQM value

BoundingBoxFilter boundingBoxFilter = new BoundingBoxFilter();
boundingBoxFilter.setRequirements(new double[]{33.5, 34.2, -116.5, -115.0}); // Desert bounding box

// Use DataFilter
DataFilter dataFilter = new DataFilter(boundingBoxFilter);

// SQM less than 17.9
OperatorFilter notFilter = new OperatorFilter();
notFilter.setRequirements(LogicalOperator.NOT);
notFilter.addFilter(lightPollutionFilterNot);

// SQM less than 17.9 or greater than 18.1
OperatorFilter orFilter = new OperatorFilter();
orFilter.setRequirements(LogicalOperator.OR);
orFilter.addFilter(notFilter);
orFilter.addFilter(lightPollutionFilter);
dataFilter.addFilter(orFilter);


// Apply Filters
List<LocationCell> filteredLocations = dataFilter.filterLocations();

// Print Results
System.out.println("Filtered Locations: " + filteredLocations);

// Generate KML file with hexagon boundaries
String kmlFileName = "filtered_hexagons.kml";
KMLGenerator.generateKML(filteredLocations, kmlFileName);

}
}
28 changes: 28 additions & 0 deletions src/plp/filter/DataFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package plp.filter;

import java.util.List;


import plp.filters.BoundingBoxFilter;
import plp.location.LocationCell;

public class DataFilter {
private final FilterManager filterManager = new FilterManager();
private final List<LocationCell> allCells;

public DataFilter(InitialFilter initialFilter) {
allCells = initialFilter.getValidCells();
if (allCells.isEmpty()) {
throw new IllegalArgumentException("Zero cells in the initialFilter: " + initialFilter.getClass().getSimpleName());
}
}


public void addFilter(Filter filter) {
filterManager.addFilter(filter);
}

public List<LocationCell> filterLocations() {
return filterManager.applyFilters(allCells);
}
}
73 changes: 73 additions & 0 deletions src/plp/filter/Filter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package plp.filter;

import java.util.Arrays;
import java.util.List;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import plp.location.LocationCell;

public interface Filter {

/**
* Set the requirements from the CLI or other source.
* Must detect the wanted Object type and handle accordingly.
* @param requirements The filter's requirements in it's wanted type.
* @throws IllegalArgumentException If object is of wrong type or arguments are invalid
*/
void setRequirements(Object requirements) throws IllegalArgumentException; // Main Handling

/**
* A String representation of the Filter's currently inputed requirements
* @return A user-friendly string
*/
String getRequirements();

/**
* Set the initial locations to filter upon
* @param Previous {@link plp.location.LocationCell LocationCells} to work with
*/
void setLocations(List<LocationCell> locations);

/**
* The action of filtering the locations.
* Should handle loading data in and caching, if necessary.
* @return All matching {@link plp.location.LocationCell LocationCells}
*/
List<LocationCell> process(); // Action of filtering the locations

/**
* Accept requirements from the Parameter Panel that this filter provides
* @param modifiedParameterPanel The panel from {@link #getParameterPanel(int, int) getParameterPanel}, modified with the user's input.
* @throws IllegalArgumentException If arguments are invalid.
*/
default void setRequirements(JPanel modifiedParameterPanel) throws IllegalArgumentException { // Handle from UI
JTextField[] fields = (JTextField[]) modifiedParameterPanel.getClientProperty("fields"); // Get the first component (the filter's parameter panel), Extract input fields

try {
String[] inputValues = new String[fields.length];
for (int i = 0; i < fields.length; i++) {
// Explicitly focus out of each field to ensure the latest value is captured
fields[i].transferFocus();
inputValues[i] = fields[i].getText();
}

System.out.println(Arrays.toString(inputValues));
setRequirements(fields); // Set the requirements dynamically
} catch (Exception ex) {
JOptionPane.showMessageDialog(modifiedParameterPanel, "Invalid input: " + ex.getMessage());
}
}

/**
* Construct a JPanel for the UI so that the user can input the requirements for this filter.
* @return A panel with fields, such as {@link javax.swing.JTextField JTextFields}
*/
default JPanel getParameterPanel() {
JPanel panel = new JPanel();
panel.putClientProperty("fields", new JTextField[]{});
return panel;
}
}
27 changes: 27 additions & 0 deletions src/plp/filter/FilterManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package plp.filter;

import java.util.ArrayList;
import java.util.List;

import plp.location.LocationCell;

public class FilterManager {
private final List<Filter> filters = new ArrayList<>();

public void addFilter(Filter filter) {
filters.add(filter);
}

public List<LocationCell> applyFilters(List<LocationCell> locations) {
List<LocationCell> filteredLocations = locations;
System.out.println("Inital bounds: " + filteredLocations.size());

for (Filter filter : filters) {
filter.setLocations(filteredLocations);
filteredLocations = filter.process();
System.out.println("After " + filter.getClass().getSimpleName() + ": " + filteredLocations.size());
}

return filteredLocations;
}
}
18 changes: 18 additions & 0 deletions src/plp/filter/InitialFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package plp.filter;

import java.util.List;

import plp.location.LocationCell;

/*
* This type of filter can be used at the beginning of a sequence to get points from nothing.
*/
public interface InitialFilter extends Filter {

/**
* Get the valid cells of the filter.
* Must not require {@link plp.filter.Filter#setLocations(List)} to be called first.
* @return List of Cell h3 indexes
*/
List<LocationCell> getValidCells();
}
Loading