Skip to content

Commit

Permalink
Merge pull request #450 from eclipse/update-record
Browse files Browse the repository at this point in the history
Update record reducing code
  • Loading branch information
otaviojava authored Nov 11, 2023
2 parents 3fe0364 + 73b7098 commit 0c10a85
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,13 @@
/**
* The default implementation of {@link ColumnDeleteQuery}
*/
class DefaultColumnDeleteQuery implements ColumnDeleteQuery {
record DefaultColumnDeleteQuery(String name, ColumnCondition columnCondition, List<String> columns)
implements ColumnDeleteQuery {

private final String columnFamily;

private final ColumnCondition condition;

private final List<String> columns;

DefaultColumnDeleteQuery(String columnFamily, ColumnCondition condition, List<String> columns) {
this.columnFamily = columnFamily;
this.condition = ofNullable(condition).map(ColumnCondition::readOnly).orElse(null);
this.columns = columns;
}

@Override
public String name() {
return columnFamily;
}

@Override
public Optional<ColumnCondition> condition() {
return ofNullable(condition);
return ofNullable(columnCondition);
}

@Override
Expand All @@ -65,21 +50,15 @@ public boolean equals(Object o) {
if (!(o instanceof ColumnDeleteQuery that)) {
return false;
}
return Objects.equals(columnFamily, that.name()) &&
Objects.equals(condition, that.condition().orElse(null)) &&
return Objects.equals(name, that.name()) &&
Objects.equals(columnCondition, that.condition().orElse(null)) &&
Objects.equals(columns, that.columns());
}

@Override
public int hashCode() {
return Objects.hash(columnFamily, condition, columns);
return Objects.hash(name, columnCondition, columns);
}

@Override
public String toString() {
return "DefaultColumnDeleteQuery{" + "columnFamily='" + columnFamily + '\'' +
", condition=" + condition +
", columns=" + columns +
'}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,49 +31,14 @@
/**
* The default implementation of column query.
*/
class DefaultColumnQuery implements ColumnQuery {
record DefaultColumnQuery(long limit, long skip, String name,
List<String> columns, List<Sort> sorts, ColumnCondition columnCondition)
implements ColumnQuery {

private final long maxResults;

private final long firstResult;

private final String columnFamily;

private final List<String> columns;

private final List<Sort> sorts;

private final ColumnCondition condition;


DefaultColumnQuery(long maxResults, long firstResult, String columnFamily,
List<String> columns, List<Sort> sorts, ColumnCondition condition) {
this.maxResults = maxResults;
this.firstResult = firstResult;
this.columnFamily = columnFamily;
this.columns = columns;
this.sorts = sorts;
this.condition = ofNullable(condition).map(ColumnCondition::readOnly).orElse(null);
}

@Override
public long limit() {
return maxResults;
}

@Override
public long skip() {
return firstResult;
}

@Override
public String name() {
return columnFamily;
}

@Override
public Optional<ColumnCondition> condition() {
return ofNullable(condition);
return ofNullable(columnCondition).map(ColumnCondition::readOnly);
}

@Override
Expand All @@ -94,29 +59,20 @@ public boolean equals(Object o) {
if (!(o instanceof ColumnQuery that)) {
return false;
}
return maxResults == that.limit() &&
firstResult == that.skip() &&
Objects.equals(columnFamily, that.name()) &&
return limit == that.limit() &&
skip == that.skip() &&
Objects.equals(name, that.name()) &&
Objects.equals(columns, that.columns()) &&
Objects.equals(sorts, that.sorts()) &&
Objects.equals(condition, that.condition().orElse(null));
Objects.equals(columnCondition, that.condition().orElse(null));
}

@Override
public int hashCode() {
return Objects.hash(maxResults, firstResult, columnFamily, columns, sorts, condition);
return Objects.hash(limit, skip, name, columns, sorts, columnCondition);
}

@Override
public String toString() {
return "ColumnQuery{" + "maxResults=" + maxResults +
", firstResult=" + firstResult +
", columnFamily='" + columnFamily + '\'' +
", columns=" + columns +
", sorts=" + sorts +
", condition=" + condition +
'}';
}

static ColumnQuery countBy(ColumnQuery query) {
return new DefaultColumnQuery(0, 0, query.name(), query.columns(),
Collections.emptyList(), query.condition().orElse(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,12 @@
/**
* Defines the default implementation of {@link Value}
*/
final class DefaultValue implements Value {
record DefaultValue(Object value) implements Value {

private static final ValueReader SERVICE_PROVIDER = ValueReaderDecorator.getInstance();

private static final TypeReferenceReader REFERENCE_READER = TypeReferenceReaderDecorator.getInstance();

private final Object value;

DefaultValue(Object value) {
this.value = value;
}


@Override
public Object get() {
Expand Down Expand Up @@ -76,10 +70,4 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hashCode(value);
}

@Override
public String toString() {
return "DefaultValue{" + "value=" + value +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,13 @@
/**
* The default implementation of {@link DocumentDeleteQuery}
*/
final class DefaultDocumentDeleteQuery implements DocumentDeleteQuery {
record DefaultDocumentDeleteQuery (String name,

private final String documentCollection;

private final DocumentCondition condition;

private final List<String> documents;

DefaultDocumentDeleteQuery(String documentCollection, DocumentCondition condition, List<String> documents) {
this.documentCollection = documentCollection;
this.condition = ofNullable(condition).map(DocumentCondition::readOnly).orElse(null);
this.documents = documents;
}

@Override
public String name() {
return documentCollection;
}
DocumentCondition documentCondition, List<String> documents) implements DocumentDeleteQuery {

@Override
public Optional<DocumentCondition> condition() {
return ofNullable(condition);
return ofNullable(documentCondition).map(DocumentCondition::readOnly);
}

@Override
Expand All @@ -65,21 +50,14 @@ public boolean equals(Object o) {
if (!(o instanceof DocumentDeleteQuery that)) {
return false;
}
return Objects.equals(documentCollection, that.name()) &&
Objects.equals(condition, that.condition().orElse(null)) &&
return Objects.equals(name, that.name()) &&
Objects.equals(documentCondition, that.condition().orElse(null)) &&
Objects.equals(documents, that.documents());
}

@Override
public int hashCode() {
return Objects.hash(documentCollection, condition, documents);
return Objects.hash(name, documentCondition, documents);
}

@Override
public String toString() {
return "DefaultDocumentDeleteQuery{" + "documentCollection='" + documentCollection + '\'' +
", condition=" + condition +
", documents=" + documents +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,49 +27,14 @@
import static java.util.Collections.unmodifiableList;
import static java.util.Optional.ofNullable;

class DefaultDocumentQuery implements DocumentQuery {
record DefaultDocumentQuery(long limit, long skip, String name,
List<String> documents, List<Sort> sorts, DocumentCondition documentCondition) implements DocumentQuery {

private final long limit;

private final long skip;

private final String documentCollection;

private final DocumentCondition condition;

private final List<Sort> sorts;

private final List<String> documents;

DefaultDocumentQuery(long limit, long skip, String documentCollection,
List<String> documents, List<Sort> sorts, DocumentCondition condition) {

this.limit = limit;
this.skip = skip;
this.documentCollection = documentCollection;
this.condition = ofNullable(condition).map(DocumentCondition::readOnly).orElse(null);
this.sorts = sorts;
this.documents = documents;
}

@Override
public long limit() {
return limit;
}

@Override
public long skip() {
return skip;
}

@Override
public String name() {
return documentCollection;
}

@Override
public Optional<DocumentCondition> condition() {
return ofNullable(condition);
return ofNullable(documentCondition).map(DocumentCondition::readOnly);
}

@Override
Expand All @@ -92,27 +57,17 @@ public boolean equals(Object o) {
}
return limit == that.limit() &&
skip == that.skip() &&
Objects.equals(documentCollection, that.name()) &&
Objects.equals(condition, that.condition().orElse(null)) &&
Objects.equals(name, that.name()) &&
Objects.equals(documentCondition, that.condition().orElse(null)) &&
Objects.equals(sorts, that.sorts()) &&
Objects.equals(documents, that.documents());
}

@Override
public int hashCode() {
return Objects.hash(limit, skip, documentCollection, condition, sorts, documents);
return Objects.hash(limit, skip, name, documentCondition, sorts, documents);
}

@Override
public String toString() {
return "DocumentQuery{" + "maxResult=" + limit +
", firstResult=" + skip +
", documentCollection='" + documentCollection + '\'' +
", condition=" + condition +
", sorts=" + sorts +
", documents=" + documents +
'}';
}

static DocumentQuery countBy(DocumentQuery query) {
return new DefaultDocumentQuery(0, 0, query.name(), query.documents(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,14 @@
* and ({@link org.eclipse.jnosql.communication.Condition#AND}), or ({@link org.eclipse.jnosql.communication.Condition#OR})
* and negation ({@link org.eclipse.jnosql.communication.Condition#NOT}).
*/
public class ConditionQueryValue implements QueryValue<List<QueryCondition>> {
public record ConditionQueryValue(List<QueryCondition> conditions) implements QueryValue<List<QueryCondition>> {

private final List<QueryCondition> conditions;

private ConditionQueryValue(List<QueryCondition> conditions) {
this.conditions = conditions;
}

@Override
public List<QueryCondition> get() {
return unmodifiableList(conditions);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ConditionQueryValue that)) {
return false;
}
return Objects.equals(conditions, that.conditions);
}

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

@Override
public String toString() {
return conditions.toString();
}

/**
* Create Condition query value
* @param conditions the conditions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@
/**
* A sequence of elements that can be either {@link NumberQueryValue} or {@link StringQueryValue}
*/
final class DefaultArrayQueryValue implements ArrayQueryValue {
record DefaultArrayQueryValue(QueryValue<?>[] values) implements ArrayQueryValue {

private final QueryValue<?>[] values;

private DefaultArrayQueryValue(QueryValue<?>[] values) {
this.values = values;
}

@Override
public QueryValue<?>[] get() {
Expand Down
Loading

0 comments on commit 0c10a85

Please sign in to comment.