-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from avlo/refactor_generics
Generics Refactor
- Loading branch information
Showing
47 changed files
with
711 additions
and
503 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package nostr.base; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public interface FEncoder<T> { | ||
ObjectMapper MAPPER = new ObjectMapper().setSerializationInclusion(Include.NON_NULL); | ||
|
||
String encode(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
package nostr.base; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public abstract class FNostrList<T> extends ArrayList<T> { | ||
|
||
public boolean addAll(List<T> list) { | ||
return super.addAll(list); | ||
} | ||
|
||
public List<T> getList() { | ||
return super.stream().toList(); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return super.size(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
|
||
package nostr.base; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* | ||
* @author squirrel | ||
* @param <T> | ||
*/ | ||
public interface INostrList<T> extends IElement { | ||
public abstract class INostrList<T extends IElement> extends ArrayList<T> { | ||
|
||
void add(T elt); | ||
public boolean add(T... elt) { | ||
return this.addAll(List.of(elt)); | ||
} | ||
|
||
void addAll(INostrList<T> list); | ||
public boolean addAll(List<T> list) { | ||
return super.addAll(list); | ||
} | ||
|
||
List<T> getList(); | ||
public List<T> getList() { | ||
return super.stream().toList(); | ||
} | ||
|
||
int size(); | ||
public int size() { | ||
return super.size(); | ||
} | ||
} |
12 changes: 4 additions & 8 deletions
12
nostr-java-event/src/main/java/nostr/event/BaseMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 68 additions & 85 deletions
153
nostr-java-event/src/main/java/nostr/event/impl/Filters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,68 @@ | ||
|
||
package nostr.event.impl; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import nostr.base.GenericTagQuery; | ||
import nostr.base.annotation.Key; | ||
import nostr.event.BaseEvent; | ||
import nostr.event.json.deserializer.CustomGenericTagQueryDeserializer; | ||
import nostr.event.json.serializer.CustomGenericTagQuerySerializer; | ||
import nostr.event.json.serializer.CustomIdEventListSerializer; | ||
import nostr.event.list.EventList; | ||
import nostr.event.list.KindList; | ||
import nostr.event.list.PublicKeyList; | ||
|
||
/** | ||
* | ||
* @author squirrel | ||
*/ | ||
@Builder | ||
@Data | ||
@EqualsAndHashCode(callSuper = false) | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Filters extends BaseEvent { | ||
|
||
@Key | ||
@JsonProperty("ids") | ||
@JsonSerialize(using=CustomIdEventListSerializer.class) | ||
private EventList events; | ||
|
||
@Key | ||
@JsonProperty("authors") | ||
private PublicKeyList authors; | ||
|
||
@Key | ||
private KindList kinds; | ||
|
||
@Key | ||
@JsonProperty("#e") | ||
@JsonSerialize(using=CustomIdEventListSerializer.class) | ||
private EventList referencedEvents; | ||
|
||
@Key | ||
@JsonProperty("#p") | ||
private PublicKeyList referencePubKeys; | ||
|
||
@Key | ||
private Long since; | ||
|
||
@Key | ||
private Long until; | ||
|
||
@Key | ||
private Integer limit; | ||
|
||
@Key(nip = 12) | ||
@JsonSerialize(using=CustomGenericTagQuerySerializer.class) | ||
@JsonDeserialize(using=CustomGenericTagQueryDeserializer.class) | ||
private GenericTagQuery genericTagQuery; | ||
|
||
@Override | ||
public String toBech32() { | ||
throw new UnsupportedOperationException("This operation is not supported."); | ||
} | ||
|
||
@JsonIgnore | ||
@Override | ||
public Integer getNip() { | ||
return 1; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public String getId() { | ||
throw new UnsupportedOperationException("Not supported."); | ||
} | ||
} | ||
|
||
package nostr.event.impl; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import nostr.base.GenericTagQuery; | ||
import nostr.base.PublicKey; | ||
import nostr.base.annotation.Key; | ||
import nostr.event.Kind; | ||
import nostr.event.json.deserializer.CustomGenericTagQueryDeserializer; | ||
import nostr.event.json.serializer.CustomGenericTagQuerySerializer; | ||
import nostr.event.json.serializer.CustomIdEventListSerializer; | ||
import nostr.event.list.EventList; | ||
import nostr.event.list.KindList; | ||
import nostr.event.list.PublicKeyList; | ||
|
||
/** | ||
* | ||
* @author squirrel | ||
*/ | ||
@Builder | ||
@Data | ||
@EqualsAndHashCode(callSuper = false) | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Filters { | ||
|
||
@Key | ||
@JsonProperty("ids") | ||
@JsonSerialize(using=CustomIdEventListSerializer.class) | ||
private EventList<GenericEvent> events; | ||
|
||
@Key | ||
@JsonProperty("authors") | ||
private PublicKeyList<PublicKey> authors; | ||
|
||
@Key | ||
private KindList kinds; | ||
|
||
@Key | ||
@JsonProperty("#e") | ||
@JsonSerialize(using=CustomIdEventListSerializer.class) | ||
private EventList<GenericEvent> referencedEvents; | ||
|
||
@Key | ||
@JsonProperty("#p") | ||
private PublicKeyList<PublicKey> referencePubKeys; | ||
|
||
@Key | ||
private Long since; | ||
|
||
@Key | ||
private Long until; | ||
|
||
@Key | ||
private Integer limit; | ||
|
||
@Key(nip = 12) | ||
@JsonSerialize(using=CustomGenericTagQuerySerializer.class) | ||
@JsonDeserialize(using=CustomGenericTagQueryDeserializer.class) | ||
private GenericTagQuery genericTagQuery; | ||
} |
17 changes: 4 additions & 13 deletions
17
nostr-java-event/src/main/java/nostr/event/json/codec/BaseEventEncoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.