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

Support Java 11 #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version>
<java.version>11</java.version>
<github.global.server>github</github.global.server>
<project.build.timestamp>${maven.build.timestamp}</project.build.timestamp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,52 @@
import foundation.identity.did.representations.Representations;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public interface RepresentationConsumer {

public record Result(Map<String, Object> didDocument,
Map<String, Map<String, Object>> representationSpecificEntries) {

public class Result {
private final Map<String, Object> didDocument;
private final Map<String, Map<String, Object>> representationSpecificEntries;

public Result(Map<String, Object> didDocument,
Map<String, Map<String, Object>> representationSpecificEntries) {
this.didDocument = Map.copyOf(didDocument);
Map<String, Map<String, Object>> tempMap = new HashMap<>();
representationSpecificEntries.forEach((key, value) ->
tempMap.put(key, Map.copyOf(value))
);
this.representationSpecificEntries = Collections.unmodifiableMap(tempMap);
}

public Map<String, Object> getDidDocument() {
return didDocument;
}

public Map<String, Map<String, Object>> getRepresentationSpecificEntries() {
return representationSpecificEntries;
}

// Implement equals and hashCode to mimic the behavior of a record
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Result result = (Result) o;

if (!didDocument.equals(result.didDocument)) return false;
return representationSpecificEntries.equals(result.representationSpecificEntries);
}

@Override
public int hashCode() {
int result = didDocument.hashCode();
result = 31 * result + representationSpecificEntries.hashCode();
return result;
}
}

public static Result consume(byte[] representation, String mediaType) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,43 @@

public interface RepresentationProducer {

public record Result(String mediaType, byte[] representation) {

public class Result {
private final String mediaType;
private final byte[] representation;

public Result(String mediaType, byte[] representation) {
this.mediaType = mediaType;
// It's important to clone the array to maintain immutability
this.representation = representation.clone();
}

public String getMediaType() {
return mediaType;
}

public byte[] getRepresentation() {
// Also clone the array on getter to prevent external modification
return representation.clone();
}

// Implement equals and hashCode to mimic the behavior of a record
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Result result = (Result) o;

if (!mediaType.equals(result.mediaType)) return false;
return java.util.Arrays.equals(representation, result.representation);
}

@Override
public int hashCode() {
int result = mediaType.hashCode();
result = 31 * result + java.util.Arrays.hashCode(representation);
return result;
}
}

public static RepresentationProducer.Result produce(Map<String, Object> didDocument, Map<String, Object> representationSpecificEntries, String mediaType) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private RepresentationProducerCBOR() {
public RepresentationProducer.Result produce(Map<String, Object> didDocument, Map<String, Object> representationSpecificEntries) throws IOException {

RepresentationProducer.Result jsonResult = RepresentationProducerJSON.getInstance().produce(didDocument, representationSpecificEntries);
CBORObject cborObject = CBORObject.FromJSONBytes(jsonResult.representation());
CBORObject cborObject = CBORObject.FromJSONBytes(jsonResult.getRepresentation());
byte[] representation = cborObject.EncodeToBytes();
return new RepresentationProducer.Result(MEDIA_TYPE, representation);
}
Expand Down