Skip to content

Commit

Permalink
Created NotNull and Nullable annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
retrodaredevil committed May 7, 2020
1 parent 1724564 commit 4f97e65
Show file tree
Hide file tree
Showing 96 changed files with 211 additions and 234 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ General rule of thumb:
* If something is Nullable, you should probably annotate it with Nullable.
* Just because something is NotNull doesn't mean you need to annotate it and everything else with NotNull.
* But if something is commonly used (public api), then annotating with NotNull can be helpful.
* Use `org.jetbrains.annotations.Nullable` or `javax.validation.constraints.NotNull`
* Why? Because the `javax.validation` variant is available at runtime, which is useful in some cases.
* Use `me.retrodaredevil.solarthing.annotations.Nullable` or `me.retrodaredevil.solarthing.annotations.NotNull`
* Why the custom NotNull/Nullable? We want good Kotlin support, and we want to be able to annotate more than just methods.

### Customizing
The different command line options give you may ways to receive data and export data. CouchDB and InfluxDB
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
![SolarThing](other/docs/solarthing_logo.png "SolarThing")
Stores solar data in a database to view on Android, Grafana, or PVOutput

<p align="center">
<a href="#supported-products">Supported Products</a> &bull;
<a href="other/docs/quickstart.md">Quickstart</a> &bull;
<a href="#features">Features</a> &bull;
<a href="#supported-databases">Supported Databases</a> &bull;
<a href="#examples">Examples</a>
</p>

## Supported Products
* **Outback MATEs** (FX Inverter, MX/FM Charge Controller)
* **Renogy Rover** (And other Renogy products) over modbus serial.
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ subprojects {
dependencies {
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junit5Version
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junit5Version
implementation 'org.jetbrains:annotations:15.0'
implementation 'javax.validation:validation-api:2.0.1.Final'
// https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
}
test {
useJUnitPlatform()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import me.retrodaredevil.solarthing.actions.ActionNode;
import me.retrodaredevil.solarthing.solar.outback.fx.charge.FXChargingSettings;
import me.retrodaredevil.solarthing.util.IgnoreCheckSum;
import org.jetbrains.annotations.Nullable;
import me.retrodaredevil.solarthing.annotations.Nullable;

import java.io.File;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,6 @@ private static void uploadStatus(PVOutputService service, AddStatusParameters ad
Call<String> call = service.addStatus(addStatusParameters);
executeCall(call);
}
private static void uploadBatchOutput(PVOutputService service, AddBatchOutputParameters parameters) {
Call<String> call = service.addBatchOutput(parameters);
executeCall(call);
}
private static void executeCall(Call<String> call) {
LOGGER.debug("Executing call");
Response<String> response = null;
Expand All @@ -322,7 +318,6 @@ private static void executeCall(Call<String> call) {
} else {
LOGGER.debug("Unsuccessful. Message: " + response.message() + " code: " + response.code());
}

}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.retrodaredevil.couchdb;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import javax.validation.constraints.NotNull;
import org.jetbrains.annotations.Nullable;
import me.retrodaredevil.solarthing.annotations.NotNull;
import me.retrodaredevil.solarthing.annotations.Nullable;

@JsonDeserialize(as = ImmutableCouchProperties.class)
public interface CouchProperties {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.retrodaredevil.couchdb;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

import static java.util.Objects.requireNonNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package me.retrodaredevil.solarthing.annotations;

import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierNickname;
import javax.annotation.meta.When;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;

@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@TypeQualifierNickname
@Nonnull(when = When.ALWAYS)
public @interface NotNull {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package me.retrodaredevil.solarthing.annotations;

import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierNickname;
import javax.annotation.meta.When;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
@Retention(RUNTIME)
@Documented
@TypeQualifierNickname
@Nonnull(when = When.UNKNOWN)
public @interface Nullable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import me.retrodaredevil.solarthing.packets.identification.IdentityInfo;
import me.retrodaredevil.solarthing.packets.identification.SingleTypeIdentifier;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

@JsonIgnoreProperties(value = {"cpuTemperatureFahrenheit"}, allowGetters = true)
public class CelsiusCpuTemperaturePacket implements CpuTemperaturePacket {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import me.retrodaredevil.solarthing.annotations.JsonExplicit;
import me.retrodaredevil.solarthing.packets.identification.Identifiable;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

@JsonDeserialize(as = CelsiusCpuTemperaturePacket.class)
@JsonExplicit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import me.retrodaredevil.solarthing.packets.identification.Identifier;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;
import java.util.Objects;

import static java.util.Objects.requireNonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import me.retrodaredevil.solarthing.annotations.JsonExplicit;
import me.retrodaredevil.solarthing.packets.identification.Identifiable;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

@JsonDeserialize(as = ImmutableExceptionErrorPacket.class)
@JsonTypeName("EXCEPTION_ERROR")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import me.retrodaredevil.solarthing.packets.identification.Identifier;
import me.retrodaredevil.solarthing.packets.identification.IdentityInfo;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -33,9 +34,8 @@ public ImmutableExceptionErrorPacket(
identityInfo = new ExceptionErrorIdentityInfo(identifier);
}

@NotNull
@Override
public Identifier getIdentifier() {
public @NotNull Identifier getIdentifier() {
return identifier;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

@JsonPropertyOrder({"packetType"}) // we want packetType to always be at the top
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "packetType")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package me.retrodaredevil.solarthing.packets.collection;

import me.retrodaredevil.solarthing.packets.instance.InstanceSourcePacket;
import org.jetbrains.annotations.Nullable;
import me.retrodaredevil.solarthing.annotations.Nullable;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

import static java.util.Objects.requireNonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import me.retrodaredevil.solarthing.packets.Packet;
import org.jetbrains.annotations.Nullable;
import me.retrodaredevil.solarthing.annotations.Nullable;

public interface JsonPacketParser {
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import me.retrodaredevil.solarthing.packets.Packet;
import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

public class ObjectMapperPacketConverter implements JsonPacketParser {
private final ObjectMapper mapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import me.retrodaredevil.solarthing.packets.collection.PacketGroup;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

public interface PacketGroupParser {
@NotNull PacketGroup parse(ObjectNode objectNode) throws PacketParseException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import me.retrodaredevil.solarthing.packets.Packet;
import org.jetbrains.annotations.Nullable;
import me.retrodaredevil.solarthing.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import me.retrodaredevil.solarthing.packets.collection.PacketGroup;
import me.retrodaredevil.solarthing.packets.collection.PacketGroups;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.retrodaredevil.solarthing.packets.handling.updating;

import me.retrodaredevil.solarthing.packets.Packet;
import org.jetbrains.annotations.Nullable;
import me.retrodaredevil.solarthing.annotations.Nullable;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.retrodaredevil.solarthing.packets.identification;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import me.retrodaredevil.solarthing.annotations.GraphQLInclude;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

/**
* Represents something that is "identifiable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

/**
* All {@link Identifier}s have their {@link #equals(Object)} and {@link #hashCode()} methods implemented so
Expand All @@ -13,7 +13,7 @@
* <p>
* {@link Identifier}s also inherit {@link Comparable<Identifier>} so they can be sorted using the default SolarThing order. (Their natural order).
*/
public interface Identifier extends Comparable<Identifier> {
public interface Identifier extends Comparable<Identifier> { // TODO make this not comparable
/**
* @return A representation of this identifier
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package me.retrodaredevil.solarthing.packets.identification;

import me.retrodaredevil.solarthing.packets.collection.PacketGroups;
import org.jetbrains.annotations.Nullable;
import me.retrodaredevil.solarthing.annotations.Nullable;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;
import java.util.Objects;

import static java.util.Objects.requireNonNull;
Expand All @@ -13,7 +13,7 @@
* {@link Comparable<IdentifierFragment>} to allow a group of {@link IdentifierFragment}s to be compared or sorted first by their
* fragmentId, next by {@link Identifier#compareTo(Identifier)}
*/
public final class IdentifierFragment implements Comparable<IdentifierFragment> {
public final class IdentifierFragment implements Comparable<IdentifierFragment> { // TODO make all implementations serializable into JSON
private final Integer fragmentId;
private final Identifier identifier;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.retrodaredevil.solarthing.packets.identification;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;
import java.util.Objects;

import static java.util.Objects.requireNonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import me.retrodaredevil.solarthing.annotations.GraphQLInclude;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

public interface SupplementaryIdentifiable extends Identifiable {
@GraphQLInclude("identifier") // TODO figure out why this has to be added here too
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

public interface SupplementaryIdentifier extends Identifier {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.retrodaredevil.solarthing.packets.identification;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;
import java.util.Objects;

import static java.util.Objects.requireNonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import me.retrodaredevil.solarthing.annotations.JsonExplicit;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

/**
* This packet is used to indicate that multiple {@link me.retrodaredevil.solarthing.packets.collection.PacketCollection}s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import me.retrodaredevil.solarthing.annotations.JsonExplicit;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

@JsonTypeName("SOURCE")
@JsonDeserialize(as = ImmutableInstanceSourcePacket.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import me.retrodaredevil.solarthing.annotations.JsonExplicit;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

@Deprecated // never used. Maybe used in the future
@JsonTypeName("TARGET")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import me.retrodaredevil.solarthing.annotations.JsonExplicit;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;
import java.security.PublicKey;

@JsonDeserialize(as = ImmutableAuthNewSenderPacket.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import me.retrodaredevil.solarthing.annotations.JsonExplicit;

import javax.validation.constraints.NotNull;
import me.retrodaredevil.solarthing.annotations.NotNull;

@JsonTypeName("INTEGRITY_PACKET")
@JsonDeserialize(as = ImmutableIntegrityPacket.class)
Expand Down
Loading

0 comments on commit 4f97e65

Please sign in to comment.