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

Fix warnings of raw use of parameterized class for the Value class #196

Merged
merged 2 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.scalar.db.exception.transaction.UnknownTransactionStatusException;
import com.scalar.db.io.IntValue;
import com.scalar.db.io.Key;
import com.scalar.db.io.Value;
import com.scalar.db.transaction.consensuscommit.Coordinator.State;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -868,7 +867,7 @@ public void getAndScan_CommitHappenedInBetween_ShouldReadRepeatably()
public void putAndCommit_PutGivenForNonExisting_ShouldCreateRecord()
throws CommitException, UnknownTransactionStatusException, CrudException {
// Arrange
Value expected = new IntValue(BALANCE, INITIAL_BALANCE);
IntValue expected = new IntValue(BALANCE, INITIAL_BALANCE);
Put put = preparePut(0, 0, TABLE_1).withValue(expected);
transaction = manager.start();

Expand Down Expand Up @@ -896,7 +895,7 @@ public void putAndCommit_PutGivenForExistingAfterRead_ShouldUpdateRecord()
// Act
Optional<Result> result = transaction.get(get);
int afterBalance = ((IntValue) result.get().getValue(BALANCE).get()).get() + 100;
Value expected = new IntValue(BALANCE, afterBalance);
IntValue expected = new IntValue(BALANCE, afterBalance);
Put put = preparePut(0, 0, TABLE_1).withValue(expected);
transaction.put(put);
transaction.commit();
Expand Down Expand Up @@ -929,7 +928,7 @@ public void putAndCommit_PutGivenForExistingAndNeverRead_ShouldThrowCommitExcept
throws CommitException, UnknownTransactionStatusException, ExecutionException,
CoordinatorException {
// Arrange
Value balance = new IntValue(BALANCE, INITIAL_BALANCE);
IntValue balance = new IntValue(BALANCE, INITIAL_BALANCE);
List<Put> puts = preparePuts(TABLE_1);
puts.get(0).withValue(balance);
puts.get(1).withValue(balance);
Expand All @@ -951,7 +950,7 @@ public void putAndCommit_TwoPartitionsMutationsGiven_ShouldAccessStorageTwiceFor
throws CommitException, UnknownTransactionStatusException, ExecutionException,
CoordinatorException {
// Arrange
Value balance = new IntValue(BALANCE, INITIAL_BALANCE);
IntValue balance = new IntValue(BALANCE, INITIAL_BALANCE);
List<Put> puts = preparePuts(TABLE_1);
puts.get(0).withValue(balance);
puts.get(NUM_TYPES).withValue(balance); // next account
Expand Down Expand Up @@ -1015,7 +1014,7 @@ private void commit_ConflictingPutsGivenForNonExisting_ShouldCommitOneAndAbortTh
// Arrange
boolean differentTables = !table1.equals(table2);

Value expected = new IntValue(BALANCE, INITIAL_BALANCE);
IntValue expected = new IntValue(BALANCE, INITIAL_BALANCE);
List<Put> puts1 = preparePuts(table1);
List<Put> puts2 = differentTables ? preparePuts(table2) : puts1;

Expand Down Expand Up @@ -1246,7 +1245,7 @@ public void commit_NonConflictingPutsForDifferentTablesGivenForExisting_ShouldCo
public void putAndCommit_GetsAndPutsForSameKeyButDifferentTablesGiven_ShouldCommitBoth()
throws CrudException {
// Arrange
Value expected = new IntValue(BALANCE, INITIAL_BALANCE);
IntValue expected = new IntValue(BALANCE, INITIAL_BALANCE);
List<Put> puts1 = preparePuts(TABLE_1);
List<Put> puts2 = preparePuts(TABLE_2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.scalar.db.exception.transaction.TransactionException;
import com.scalar.db.io.IntValue;
import com.scalar.db.io.Key;
import com.scalar.db.io.Value;
import com.scalar.db.storage.common.metadata.DataType;
import com.scalar.db.storage.jdbc.test.TestEnv;
import java.util.ArrayList;
Expand Down Expand Up @@ -109,7 +108,7 @@ public void scan_ScanGivenForNonExisting_ShouldReturnEmpty() throws TransactionE
@Test
public void putAndCommit_PutGivenForNonExisting_ShouldCreateRecord() throws TransactionException {
// Arrange
Value expected = new IntValue(BALANCE, INITIAL_BALANCE);
IntValue expected = new IntValue(BALANCE, INITIAL_BALANCE);
Put put = preparePut(0, 0, NAMESPACE, TABLE).withValue(expected);
DistributedTransaction transaction = manager.start();

Expand All @@ -136,7 +135,7 @@ public void putAndCommit_PutGivenForExistingAfterRead_ShouldUpdateRecord()
// Act
Optional<Result> result = transaction.get(get);
int afterBalance = ((IntValue) result.get().getValue(BALANCE).get()).get() + 100;
Value expected = new IntValue(BALANCE, afterBalance);
IntValue expected = new IntValue(BALANCE, afterBalance);
Put put = preparePut(0, 0, NAMESPACE, TABLE).withValue(expected);
transaction.put(put);
transaction.commit();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/scalar/db/api/ConditionalExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public class ConditionalExpression {
private final String name;
private final Value value;
private final Value<?> value;
private final Operator operator;

/**
Expand All @@ -23,7 +23,7 @@ public class ConditionalExpression {
* @param value value used to compare with the target value
* @param operator operator used to compare the target value specified with the name and the value
*/
public ConditionalExpression(String name, Value value, Operator operator) {
public ConditionalExpression(String name, Value<?> value, Operator operator) {
this.name = name;
this.value = value;
this.operator = operator;
Expand All @@ -44,7 +44,7 @@ public String getName() {
*
* @return the value used to compare with the target value
*/
public Value getValue() {
public Value<?> getValue() {
return value;
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/scalar/db/api/Put.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
@NotThreadSafe
public class Put extends Mutation {
private final Map<String, Value> values;
private final Map<String, Value<?>> values;

/**
* Constructs a {@code Put} with the specified partition {@link Key}.
Expand Down Expand Up @@ -46,7 +46,7 @@ public Put(Key partitionKey, Key clusteringKey) {
* @param value a {@code Value} to put
* @return this object
*/
public Put withValue(Value value) {
public Put withValue(Value<?> value) {
values.put(value.getName(), value);
return this;
}
Expand All @@ -57,7 +57,7 @@ public Put withValue(Value value) {
* @param values a collection of {@code Value}s to put
* @return this object
*/
public Put withValues(Collection<Value> values) {
public Put withValues(Collection<Value<?>> values) {
values.forEach(v -> this.values.put(v.getName(), v));
return this;
}
Expand All @@ -67,7 +67,7 @@ public Put withValues(Collection<Value> values) {
*
* @return a map of {@code Value}s
*/
public Map<String, Value> getValues() {
public Map<String, Value<?>> getValues() {
return ImmutableMap.copyOf(values);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/scalar/db/api/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public interface Result {
* @param name name of the {@code Value}
* @return an {@code Optional} with the {@code Value}
*/
Optional<Value> getValue(String name);
Optional<Value<?>> getValue(String name);

/**
* Returns a map of {@link Value}s
*
* @return a map of {@code Value}s
*/
Map<String, Value> getValues();
Map<String, Value<?>> getValues();
}
14 changes: 7 additions & 7 deletions src/main/java/com/scalar/db/io/Key.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
* @author Hiroyuki Yamada
*/
@Immutable
public final class Key implements Comparable<Key>, Iterable<Value> {
private final List<Value> values;
public final class Key implements Comparable<Key>, Iterable<Value<?>> {
private final List<Value<?>> values;

/**
* Constructs a {@code Key} with the specified {@link Value}s
*
* @param values one or more {@link Value}s which this key is composed of
*/
public Key(Value... values) {
public Key(Value<?>... values) {
checkNotNull(values);
this.values = new ArrayList<>(values.length);
Arrays.stream(values).forEach(v -> this.values.add(v));
Expand All @@ -38,7 +38,7 @@ public Key(Value... values) {
*
* @param values a list of {@link Value}s which this key is composed of
*/
public Key(List<Value> values) {
public Key(List<Value<?>> values) {
checkNotNull(values);
this.values = new ArrayList<>(values.size());
values.forEach(v -> this.values.add(v));
Expand All @@ -50,7 +50,7 @@ public Key(List<Value> values) {
* @return list of {@code Value} which this key is composed of
*/
@Nonnull
public List<Value> get() {
public List<Value<?>> get() {
return Collections.unmodifiableList(values);
}

Expand Down Expand Up @@ -104,14 +104,14 @@ public String toString() {
}

@Override
public Iterator<Value> iterator() {
public Iterator<Value<?>> iterator() {
return values.iterator();
}

@Override
public int compareTo(Key o) {
return ComparisonChain.start()
.compare(values, o.values, Ordering.<Value>natural().lexicographical())
.compare(values, o.values, Ordering.<Value<?>>natural().lexicographical())
.result();
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/scalar/db/io/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface Value<T> extends Comparable<T> {
* @param name name of a {@code Value}
* @return a {@code Value} which has the same content of this value
*/
Value copyWith(String name);
Value<?> copyWith(String name);

/**
* Accepts a {@link ValueVisitor} to be able to be traversed
Expand Down
29 changes: 14 additions & 15 deletions src/main/java/com/scalar/db/storage/cassandra/ResultImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.scalar.db.storage.cassandra;

import static com.google.common.base.Preconditions.checkNotNull;

import com.datastax.driver.core.ColumnDefinitions.Definition;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.Row;
Expand All @@ -16,11 +18,6 @@
import com.scalar.db.io.Key;
import com.scalar.db.io.TextValue;
import com.scalar.db.io.Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -32,14 +29,16 @@
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Immutable
public class ResultImpl implements Result {
private static final Logger LOGGER = LoggerFactory.getLogger(ResultImpl.class);
private final CassandraTableMetadata metadata;
private Map<String, Value> values;
private Map<String, Value<?>> values;

public ResultImpl(Row row, CassandraTableMetadata metadata) {
checkNotNull(row);
Expand All @@ -53,7 +52,7 @@ public ResultImpl(Row row, CassandraTableMetadata metadata) {
* @param values
*/
@VisibleForTesting
ResultImpl(Collection<Value> values, CassandraTableMetadata metadata) {
ResultImpl(Collection<Value<?>> values, CassandraTableMetadata metadata) {
this.metadata = metadata;
this.values = new HashMap<>();
values.forEach(v -> this.values.put(v.getName(), v));
Expand All @@ -70,13 +69,13 @@ public Optional<Key> getClusteringKey() {
}

@Override
public Optional<Value> getValue(String name) {
public Optional<Value<?>> getValue(String name) {
return Optional.ofNullable(values.get(name));
}

@Override
@Nonnull
public Map<String, Value> getValues() {
public Map<String, Value<?>> getValues() {
return Collections.unmodifiableMap(values);
}

Expand Down Expand Up @@ -111,7 +110,7 @@ void interpret(Row row) {
getColumnDefinitions(row)
.forEach(
(name, type) -> {
Value value = convert(row, name, type.getName());
Value<?> value = convert(row, name, type.getName());
values.put(name, value);
});
}
Expand All @@ -129,9 +128,9 @@ Map<String, DataType> getColumnDefinitions(Row row) {
}

private Optional<Key> getKey(LinkedHashSet<String> names) {
List<Value> list = new ArrayList<>();
List<Value<?>> list = new ArrayList<>();
for (String name : names) {
Value value = values.get(name);
Value<?> value = values.get(name);
if (value == null) {
LOGGER.warn("full key doesn't seem to be projected into the result");
return Optional.empty();
Expand All @@ -141,7 +140,7 @@ private Optional<Key> getKey(LinkedHashSet<String> names) {
return Optional.of(new Key(list));
}

private static Value convert(Row row, String name, DataType.Name type)
private static Value<?> convert(Row row, String name, DataType.Name type)
throws UnsupportedTypeException {
switch (type) {
case BOOLEAN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void setStart(Select.Where statement, Scan scan) {
scan.getStartClusteringKey()
.ifPresent(
k -> {
List<Value> start = k.get();
List<Value<?>> start = k.get();
IntStream.range(0, start.size())
.forEach(
i -> {
Expand All @@ -178,7 +178,7 @@ private void setEnd(Select.Where statement, Scan scan) {
scan.getEndClusteringKey()
.ifPresent(
k -> {
List<Value> end = k.get();
List<Value<?>> end = k.get();
IntStream.range(0, end.size())
.forEach(
i -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.scalar.db.io.ValueVisitor;
import com.scalar.db.storage.common.metadata.DataType;
import com.scalar.db.storage.common.metadata.TableMetadata;

import javax.annotation.concurrent.NotThreadSafe;

@NotThreadSafe
Expand All @@ -24,7 +23,7 @@ public ColumnChecker(TableMetadata tableMetadata) {
this.tableMetadata = tableMetadata;
}

public boolean check(Value value) {
public boolean check(Value<?> value) {
// Check if the column exists
if (!tableMetadata.getColumnNames().contains(getName(value))) {
return false;
Expand All @@ -35,12 +34,12 @@ public boolean check(Value value) {
return isValid;
}

public boolean check(String name, Value value) {
public boolean check(String name, Value<?> value) {
this.name = name;
return check(value);
}

private String getName(Value value) {
private String getName(Value<?> value) {
return name != null ? name : value.getName();
}

Expand Down
Loading