Skip to content

Commit

Permalink
ARC-1700: Pull impls into internal records.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrichner-oviva committed May 24, 2024
1 parent c0ffee0 commit c0ffee8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 64 deletions.
32 changes: 2 additions & 30 deletions api/src/main/java/com/oviva/spicegen/api/ObjectRef.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.oviva.spicegen.api;

import java.util.Objects;
import com.oviva.spicegen.api.internal.ObjectRefImpl;

public interface ObjectRef {
String kind();
Expand All @@ -14,35 +14,7 @@ static ObjectRef of(String kind, String id) {
if (id == null) {
throw new IllegalArgumentException("id must not be null");
}
return new ObjectRef() {
@Override
public String kind() {
return kind;
}

@Override
public String id() {
return id;
}

@Override
public String toString() {
return "%s:%s".formatted(kind, id);
}

@Override
public int hashCode() {
return Objects.hash(kind, id);
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof ObjectRef ref)) {
return false;
}

return Objects.equals(this.kind(), ref.kind()) && Objects.equals(this.id(), ref.id());
}
};
return new ObjectRefImpl(kind, id);
}
}
39 changes: 5 additions & 34 deletions api/src/main/java/com/oviva/spicegen/api/SubjectRef.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,16 @@
package com.oviva.spicegen.api;

import java.util.Objects;
import com.oviva.spicegen.api.internal.SubjectRefImpl;

public interface SubjectRef {
String kind();

String id();

static SubjectRef ofObject(ObjectRef o) {
return new SubjectRef() {
@Override
public String kind() {
return o.kind();
}

@Override
public String id() {
return o.id();
}

@Override
public int hashCode() {
return Objects.hash(o);
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof SubjectRef that)) {
return false;
}
return Objects.equals(this.kind(), that.kind()) && Objects.equals(this.id(), that.id());
}

@Override
public String toString() {
if (o == null) {
return "";
}

return o.toString();
}
};
if (o == null) {
return null;
}
return new SubjectRefImpl(o.kind(), o.id());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.oviva.spicegen.api.internal;

import com.oviva.spicegen.api.ObjectRef;

public record ObjectRefImpl(String kind, String id) implements ObjectRef {

@Override
public String toString() {
return "%s:%s".formatted(kind, id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.oviva.spicegen.api.internal;

import com.oviva.spicegen.api.SubjectRef;

public record SubjectRefImpl(String kind, String id) implements SubjectRef {
@Override
public String toString() {
return "%s:%s".formatted(kind, id);
}
}

0 comments on commit c0ffee8

Please sign in to comment.