Skip to content

Commit

Permalink
Merge pull request #193 from entur/prettier
Browse files Browse the repository at this point in the history
Prettier
  • Loading branch information
testower authored Aug 3, 2023
2 parents d71c9cc + 178291f commit d2001d9
Show file tree
Hide file tree
Showing 139 changed files with 7,539 additions and 6,132 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ GraphQL endpoint targeted at end-user clients. Documentation can be explored at
Requires a locally running redis instance. E.g.:

docker run -p 127.0.0.1:6379:6379 -d redis redis-server

## Codestyle
Lamassu uses [Prettier Java](https://github.com/jhipster/prettier-java). Use `mvn prettier:write` to reformat code before
pushing changes. You can also configure your IDE to reformat code when you save a file.
45 changes: 44 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<gbfs-validator-java.version>1.0.4</gbfs-validator-java.version>
<gbfs-java-model.version>3.0.1</gbfs-java-model.version>
<netex-utils.version>1.43</netex-utils.version>

<prettier-java.version>2.1.0</prettier-java.version>
<prettier-maven-plugin.version>0.20</prettier-maven-plugin.version>
</properties>

<distributionManagement>
Expand Down Expand Up @@ -222,7 +225,47 @@
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>com.hubspot.maven.plugins</groupId>
<artifactId>prettier-maven-plugin</artifactId>
<version>${prettier-maven-plugin.version}</version>
<configuration>
<prettierJavaVersion>${prettier-java.version}</prettierJavaVersion>
<printWidth>90</printWidth>
<tabWidth>2</tabWidth>
<useTabs>false</useTabs>
<ignoreConfigFile>true</ignoreConfigFile>
<ignoreEditorConfig>true</ignoreEditorConfig>
<!-- Use <inputGlobs> to override the default input patterns -->
<inputGlobs>
<!-- These are the default patterns, you can omit <inputGlobs> entirely unless you want to override them -->
<inputGlob>src/main/java/**/*.java</inputGlob>
<inputGlob>src/test/java/**/*.java</inputGlob>
</inputGlobs>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>${plugin.prettier.goal}</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>ci</id>
<activation>
<property>
<name>env.CI</name>
</property>
</activation>
<properties>
<!-- But in our CI environment we want to validate that code is formatted -->
<plugin.prettier.goal>check</plugin.prettier.goal>
</properties>
</profile>
</profiles>
</project>
8 changes: 3 additions & 5 deletions src/main/java/org/entur/lamassu/LamassuApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
@SpringBootApplication
public class LamassuApplication {

public static void main(String[] args) {
SpringApplication.run(LamassuApplication.class, args);
}


public static void main(String[] args) {
SpringApplication.run(LamassuApplication.class, args);
}
}
117 changes: 59 additions & 58 deletions src/main/java/org/entur/lamassu/cache/AbstractSpatialIndexId.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,62 +22,63 @@
import java.util.Objects;

public abstract class AbstractSpatialIndexId implements Serializable {
private String id;
private String codespace;
private String systemId;
private String operatorId;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getCodespace() {
return codespace;
}

public void setCodespace(String codespace) {
this.codespace = codespace;
}

public String getSystemId() {
return systemId;
}

public void setSystemId(String systemId) {
this.systemId = systemId;
}

public String getOperatorId() {
return operatorId;
}

public void setOperatorId(String operatorId) {
this.operatorId = operatorId;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

AbstractSpatialIndexId that = (AbstractSpatialIndexId) o;

if (!Objects.equals(id, that.id)) return false;
if (!Objects.equals(codespace, that.codespace)) return false;
if (!Objects.equals(systemId, that.systemId)) return false;
return Objects.equals(operatorId, that.operatorId);
}

@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (codespace != null ? codespace.hashCode() : 0);
result = 31 * result + (systemId != null ? systemId.hashCode() : 0);
result = 31 * result + (operatorId != null ? operatorId.hashCode() : 0);
return result;
}

private String id;
private String codespace;
private String systemId;
private String operatorId;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getCodespace() {
return codespace;
}

public void setCodespace(String codespace) {
this.codespace = codespace;
}

public String getSystemId() {
return systemId;
}

public void setSystemId(String systemId) {
this.systemId = systemId;
}

public String getOperatorId() {
return operatorId;
}

public void setOperatorId(String operatorId) {
this.operatorId = operatorId;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

AbstractSpatialIndexId that = (AbstractSpatialIndexId) o;

if (!Objects.equals(id, that.id)) return false;
if (!Objects.equals(codespace, that.codespace)) return false;
if (!Objects.equals(systemId, that.systemId)) return false;
return Objects.equals(operatorId, that.operatorId);
}

@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (codespace != null ? codespace.hashCode() : 0);
result = 31 * result + (systemId != null ? systemId.hashCode() : 0);
result = 31 * result + (operatorId != null ? operatorId.hashCode() : 0);
return result;
}
}
17 changes: 8 additions & 9 deletions src/main/java/org/entur/lamassu/cache/EntityCache.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package org.entur.lamassu.cache;

import org.entur.lamassu.model.entities.Entity;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.entur.lamassu.model.entities.Entity;

public interface EntityCache<T extends Entity> {
List<T> getAll(Set<String> keys);
List<T> getAll();
Map<String, T> getAllAsMap(Set<String> keys);
T get(String key);
void updateAll(Map<String, T> entities, int ttl, TimeUnit timeUnit);
void removeAll(Set<String> keys);
boolean hasKey(String key);
List<T> getAll(Set<String> keys);
List<T> getAll();
Map<String, T> getAllAsMap(Set<String> keys);
T get(String key);
void updateAll(Map<String, T> entities, int ttl, TimeUnit timeUnit);
void removeAll(Set<String> keys);
boolean hasKey(String key);
}
21 changes: 16 additions & 5 deletions src/main/java/org/entur/lamassu/cache/GBFSFeedCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,24 @@

package org.entur.lamassu.cache;

import java.util.concurrent.TimeUnit;
import org.entur.gbfs.v2_3.gbfs.GBFSFeedName;
import org.entur.lamassu.model.provider.FeedProvider;

import java.util.concurrent.TimeUnit;

public interface GBFSFeedCache {
<T> T find(GBFSFeedName feedName, FeedProvider feedProvider);
<T> void update(GBFSFeedName feedName, FeedProvider feedProvider, T feed, int ttl, TimeUnit timeUnit);
<T> T getAndUpdate(GBFSFeedName feedName, FeedProvider feedProvider, T feed, int ttl, TimeUnit timeUnit);
<T> T find(GBFSFeedName feedName, FeedProvider feedProvider);
<T> void update(
GBFSFeedName feedName,
FeedProvider feedProvider,
T feed,
int ttl,
TimeUnit timeUnit
);
<T> T getAndUpdate(
GBFSFeedName feedName,
FeedProvider feedProvider,
T feed,
int ttl,
TimeUnit timeUnit
);
}
21 changes: 13 additions & 8 deletions src/main/java/org/entur/lamassu/cache/SpatialIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@

package org.entur.lamassu.cache;

import org.entur.lamassu.model.entities.LocationEntity;
import org.redisson.api.GeoOrder;
import org.redisson.api.GeoUnit;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.entur.lamassu.model.entities.LocationEntity;
import org.redisson.api.GeoOrder;
import org.redisson.api.GeoUnit;

public interface SpatialIndex<S extends SpatialIndexId, T extends LocationEntity> {
void addAll(Map<S, T> spatialIndexUpdateMap);
void removeAll(Set<S> ids);
List<S> radius(Double longitude, Double latitude, Double radius, GeoUnit geoUnit, GeoOrder geoOrder);
Collection<S> getAll();
void addAll(Map<S, T> spatialIndexUpdateMap);
void removeAll(Set<S> ids);
List<S> radius(
Double longitude,
Double latitude,
Double radius,
GeoUnit geoUnit,
GeoOrder geoOrder
);
Collection<S> getAll();
}
3 changes: 1 addition & 2 deletions src/main/java/org/entur/lamassu/cache/SpatialIndexId.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@

package org.entur.lamassu.cache;

public interface SpatialIndexId {
}
public interface SpatialIndexId {}
3 changes: 1 addition & 2 deletions src/main/java/org/entur/lamassu/cache/StationCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@

import org.entur.lamassu.model.entities.Station;

public interface StationCache extends EntityCache<Station> {
}
public interface StationCache extends EntityCache<Station> {}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@

import org.entur.lamassu.model.entities.Station;

public interface StationSpatialIndex extends SpatialIndex<StationSpatialIndexId, Station> {}
public interface StationSpatialIndex
extends SpatialIndex<StationSpatialIndexId, Station> {}
Loading

0 comments on commit d2001d9

Please sign in to comment.