Skip to content

Commit ffe5fcf

Browse files
authored
[codestyle] Require static importing from Preconditions (#473)
1 parent 99fd922 commit ffe5fcf

File tree

96 files changed

+362
-282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+362
-282
lines changed

fluss-client/src/main/java/com/alibaba/fluss/client/table/getter/PartitionGetter.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
import com.alibaba.fluss.types.DataType;
2121
import com.alibaba.fluss.types.DataTypeRoot;
2222
import com.alibaba.fluss.types.RowType;
23-
import com.alibaba.fluss.utils.Preconditions;
2423

2524
import java.util.List;
2625

26+
import static com.alibaba.fluss.utils.Preconditions.checkArgument;
27+
import static com.alibaba.fluss.utils.Preconditions.checkNotNull;
28+
2729
/** A getter to get partition name from a row. */
2830
public class PartitionGetter {
2931

@@ -40,15 +42,15 @@ public PartitionGetter(RowType rowType, List<String> partitionKeys) {
4042
List<String> fieldNames = rowType.getFieldNames();
4143
String partitionColumnName = partitionKeys.get(0);
4244
int partitionColumnIndex = fieldNames.indexOf(partitionColumnName);
43-
Preconditions.checkArgument(
45+
checkArgument(
4446
partitionColumnIndex >= 0,
4547
"The partition column %s is not in the row %s.",
4648
partitionColumnName,
4749
rowType);
4850

4951
// check the data type of the partition column
5052
DataType partitionColumnDataType = rowType.getTypeAt(partitionColumnIndex);
51-
Preconditions.checkArgument(
53+
checkArgument(
5254
partitionColumnDataType.getTypeRoot() == DataTypeRoot.STRING,
5355
"Currently, partitioned table only supports STRING type partition key, but got partition key '%s' with data type %s.",
5456
partitionColumnName,
@@ -59,7 +61,7 @@ public PartitionGetter(RowType rowType, List<String> partitionKeys) {
5961

6062
public String getPartition(InternalRow row) {
6163
Object partitionValue = partitionFieldGetter.getFieldOrNull(row);
62-
Preconditions.checkNotNull(partitionValue, "Partition value shouldn't be null.");
64+
checkNotNull(partitionValue, "Partition value shouldn't be null.");
6365
return partitionValue.toString();
6466
}
6567
}

fluss-client/src/main/java/com/alibaba/fluss/client/write/ArrowLogWriteBatch.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
import com.alibaba.fluss.row.InternalRow;
2929
import com.alibaba.fluss.row.arrow.ArrowWriter;
3030
import com.alibaba.fluss.rpc.messages.ProduceLogRequest;
31-
import com.alibaba.fluss.utils.Preconditions;
3231

3332
import javax.annotation.concurrent.NotThreadSafe;
3433

3534
import java.io.IOException;
3635
import java.util.List;
3736

37+
import static com.alibaba.fluss.utils.Preconditions.checkArgument;
38+
import static com.alibaba.fluss.utils.Preconditions.checkNotNull;
39+
3840
/**
3941
* A batch of log records managed in ARROW format that is or will be sent to server by {@link
4042
* ProduceLogRequest}.
@@ -63,13 +65,12 @@ public ArrowLogWriteBatch(
6365
@Override
6466
public boolean tryAppend(WriteRecord writeRecord, WriteCallback callback) throws Exception {
6567
InternalRow row = writeRecord.getRow();
66-
Preconditions.checkArgument(
68+
checkArgument(
6769
writeRecord.getTargetColumns() == null,
6870
"target columns must be null for log record");
69-
Preconditions.checkArgument(
70-
writeRecord.getKey() == null, "key must be null for log record");
71-
Preconditions.checkNotNull(row != null, "row must not be null for log record");
72-
Preconditions.checkNotNull(callback, "write callback must be not null");
71+
checkArgument(writeRecord.getKey() == null, "key must be null for log record");
72+
checkNotNull(row != null, "row must not be null for log record");
73+
checkNotNull(callback, "write callback must be not null");
7374
if (recordsBuilder.isFull() || recordsBuilder.isClosed()) {
7475
return false;
7576
} else {

fluss-client/src/main/java/com/alibaba/fluss/client/write/RecordAccumulator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import com.alibaba.fluss.shaded.arrow.org.apache.arrow.memory.RootAllocator;
4040
import com.alibaba.fluss.utils.CopyOnWriteMap;
4141
import com.alibaba.fluss.utils.MathUtils;
42-
import com.alibaba.fluss.utils.Preconditions;
4342
import com.alibaba.fluss.utils.clock.Clock;
4443

4544
import org.slf4j.Logger;
@@ -59,6 +58,7 @@
5958
import java.util.concurrent.atomic.AtomicInteger;
6059

6160
import static com.alibaba.fluss.record.LogRecordBatch.NO_WRITER_ID;
61+
import static com.alibaba.fluss.utils.Preconditions.checkNotNull;
6262

6363
/* This file is based on source code of Apache Kafka Project (https://kafka.apache.org/), licensed by the Apache
6464
* Software Foundation (ASF) under the Apache License, Version 2.0. See the NOTICE file distributed with this work for
@@ -636,7 +636,7 @@ private List<WriteBatch> drainBatchesForOneNode(Cluster cluster, ServerNode node
636636
}
637637

638638
// the rest of the work by processing outside the lock close() is particularly expensive
639-
Preconditions.checkNotNull(batch, "batch should not be null");
639+
checkNotNull(batch, "batch should not be null");
640640
batch.close();
641641
size += batch.estimatedSizeInBytes();
642642
ready.add(batch);

fluss-client/src/main/java/com/alibaba/fluss/client/write/Sender.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import com.alibaba.fluss.rpc.messages.PutKvResponse;
3838
import com.alibaba.fluss.rpc.protocol.ApiError;
3939
import com.alibaba.fluss.rpc.protocol.Errors;
40-
import com.alibaba.fluss.utils.Preconditions;
4140

4241
import org.slf4j.Logger;
4342
import org.slf4j.LoggerFactory;
@@ -53,6 +52,7 @@
5352

5453
import static com.alibaba.fluss.client.utils.ClientRpcMessageUtils.makeProduceLogRequest;
5554
import static com.alibaba.fluss.client.utils.ClientRpcMessageUtils.makePutKvRequest;
55+
import static com.alibaba.fluss.utils.Preconditions.checkNotNull;
5656

5757
/* This file is based on source code of Apache Kafka Project (https://kafka.apache.org/), licensed by the Apache
5858
* Software Foundation (ASF) under the Apache License, Version 2.0. See the NOTICE file distributed with this work for
@@ -121,7 +121,7 @@ public Sender(
121121
this.inFlightBatches = new HashMap<>();
122122

123123
this.metadataUpdater = metadataUpdater;
124-
Preconditions.checkNotNull(metadataUpdater.getCoordinatorServer());
124+
checkNotNull(metadataUpdater.getCoordinatorServer());
125125

126126
this.idempotenceManager = idempotenceManager;
127127
this.writerMetricGroup = writerMetricGroup;

fluss-client/src/main/java/com/alibaba/fluss/client/write/WriteBatch.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.alibaba.fluss.metadata.TableBucket;
2424
import com.alibaba.fluss.record.LogRecordBatch;
2525
import com.alibaba.fluss.record.bytesview.BytesView;
26-
import com.alibaba.fluss.utils.Preconditions;
2726

2827
import org.slf4j.Logger;
2928
import org.slf4j.LoggerFactory;
@@ -36,6 +35,8 @@
3635
import java.util.concurrent.atomic.AtomicInteger;
3736
import java.util.concurrent.atomic.AtomicReference;
3837

38+
import static com.alibaba.fluss.utils.Preconditions.checkNotNull;
39+
3940
/** The abstract write batch contains write callback object to wait write request feedback. */
4041
@Internal
4142
public abstract class WriteBatch {
@@ -161,7 +162,7 @@ public boolean complete() {
161162
* contained in the batch.
162163
*/
163164
public boolean completeExceptionally(Exception exception) {
164-
Preconditions.checkNotNull(exception);
165+
checkNotNull(exception);
165166
return done(exception);
166167
}
167168

fluss-common/src/main/java/com/alibaba/fluss/config/ConfigBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
package com.alibaba.fluss.config;
1818

1919
import com.alibaba.fluss.annotation.PublicStable;
20-
import com.alibaba.fluss.utils.Preconditions;
2120

2221
import java.time.Duration;
2322
import java.util.Arrays;
2423
import java.util.List;
2524
import java.util.Map;
2625

26+
import static com.alibaba.fluss.utils.Preconditions.checkNotNull;
27+
2728
/**
2829
* The config builder is used to create a {@link ConfigOption}.
2930
*
@@ -99,7 +100,7 @@ private ConfigBuilder(String key) {
99100
* @return The builder for the config option with the given key.
100101
*/
101102
public static ConfigBuilder key(String key) {
102-
Preconditions.checkNotNull(key);
103+
checkNotNull(key);
103104
return new ConfigBuilder(key);
104105
}
105106

fluss-common/src/main/java/com/alibaba/fluss/config/Configuration.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.alibaba.fluss.annotation.PublicStable;
2020
import com.alibaba.fluss.utils.CollectionUtils;
21-
import com.alibaba.fluss.utils.Preconditions;
2221

2322
import org.slf4j.Logger;
2423
import org.slf4j.LoggerFactory;
@@ -32,6 +31,8 @@
3231
import java.util.Properties;
3332
import java.util.Set;
3433

34+
import static com.alibaba.fluss.utils.Preconditions.checkNotNull;
35+
3536
/* This file is based on source code of Apache Flink Project (https://flink.apache.org/), licensed by the Apache
3637
* Software Foundation (ASF) under the Apache License, Version 2.0. See the NOTICE file distributed with this work for
3738
* additional information regarding copyright ownership. */
@@ -442,8 +443,8 @@ public String getValue(ConfigOption<?> configOption) {
442443
*/
443444
public <T extends Enum<T>> T getEnum(
444445
final Class<T> enumClass, final ConfigOption<String> configOption) {
445-
Preconditions.checkNotNull(enumClass, "enumClass must not be null");
446-
Preconditions.checkNotNull(configOption, "configOption must not be null");
446+
checkNotNull(enumClass, "enumClass must not be null");
447+
checkNotNull(configOption, "configOption must not be null");
447448

448449
Object rawValue = getRawValueFromOption(configOption).orElseGet(configOption::defaultValue);
449450
try {

fluss-common/src/main/java/com/alibaba/fluss/config/MemorySize.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.alibaba.fluss.config;
1818

1919
import com.alibaba.fluss.annotation.PublicStable;
20-
import com.alibaba.fluss.utils.Preconditions;
2120

2221
import java.math.BigDecimal;
2322
import java.util.Arrays;
@@ -27,6 +26,9 @@
2726
import java.util.Optional;
2827
import java.util.stream.IntStream;
2928

29+
import static com.alibaba.fluss.utils.Preconditions.checkArgument;
30+
import static com.alibaba.fluss.utils.Preconditions.checkNotNull;
31+
3032
/* This file is based on source code of Apache Flink Project (https://flink.apache.org/), licensed by the Apache
3133
* Software Foundation (ASF) under the Apache License, Version 2.0. See the NOTICE file distributed with this work for
3234
* additional information regarding copyright ownership. */
@@ -75,7 +77,7 @@ public class MemorySize implements java.io.Serializable, Comparable<MemorySize>
7577
* @param bytes The size, in bytes. Must be zero or larger.
7678
*/
7779
public MemorySize(long bytes) {
78-
Preconditions.checkArgument(bytes >= 0, "bytes must be >= 0");
80+
checkArgument(bytes >= 0, "bytes must be >= 0");
7981
this.bytes = bytes;
8082
}
8183

@@ -205,7 +207,7 @@ public MemorySize subtract(MemorySize that) {
205207
}
206208

207209
public MemorySize multiply(double multiplier) {
208-
Preconditions.checkArgument(multiplier >= 0, "multiplier must be >= 0");
210+
checkArgument(multiplier >= 0, "multiplier must be >= 0");
209211

210212
BigDecimal product =
211213
BigDecimal.valueOf(this.bytes).multiply(BigDecimal.valueOf(multiplier));
@@ -216,7 +218,7 @@ public MemorySize multiply(double multiplier) {
216218
}
217219

218220
public MemorySize divide(long by) {
219-
Preconditions.checkArgument(by >= 0, "divisor must be >= 0");
221+
checkArgument(by >= 0, "divisor must be >= 0");
220222
return new MemorySize(bytes / by);
221223
}
222224

@@ -244,7 +246,7 @@ public static MemorySize parse(String text) throws IllegalArgumentException {
244246
* @throws IllegalArgumentException Thrown, if the expression cannot be parsed.
245247
*/
246248
public static long parseBytes(String text) throws IllegalArgumentException {
247-
Preconditions.checkNotNull(text, "text");
249+
checkNotNull(text, "text");
248250
if (!MemoryUnit.hasUnit(text)) {
249251
throw new IllegalArgumentException(
250252
"The memory value '"
@@ -255,8 +257,7 @@ public static long parseBytes(String text) throws IllegalArgumentException {
255257
}
256258

257259
final String trimmed = text.trim();
258-
Preconditions.checkArgument(
259-
!trimmed.isEmpty(), "argument is an empty- or whitespace-only string");
260+
checkArgument(!trimmed.isEmpty(), "argument is an empty- or whitespace-only string");
260261

261262
final int len = trimmed.length();
262263
int pos = 0;
@@ -375,11 +376,10 @@ public static String getAllUnits() {
375376
}
376377

377378
public static boolean hasUnit(String text) {
378-
Preconditions.checkNotNull(text, "text");
379+
checkNotNull(text, "text");
379380

380381
final String trimmed = text.trim();
381-
Preconditions.checkArgument(
382-
!trimmed.isEmpty(), "argument is an empty- or whitespace-only string");
382+
checkArgument(!trimmed.isEmpty(), "argument is an empty- or whitespace-only string");
383383

384384
final int len = trimmed.length();
385385
int pos = 0;

fluss-common/src/main/java/com/alibaba/fluss/config/StructuredOptionsSplitter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
package com.alibaba.fluss.config;
1818

19-
import com.alibaba.fluss.utils.Preconditions;
20-
2119
import java.util.ArrayList;
2220
import java.util.Arrays;
2321
import java.util.List;
2422

23+
import static com.alibaba.fluss.utils.Preconditions.checkNotNull;
24+
2525
/** Helper class for splitting a string on a given delimiter with quoting logic. */
2626
class StructuredOptionsSplitter {
2727

@@ -44,7 +44,7 @@ class StructuredOptionsSplitter {
4444
* @return a list of splits
4545
*/
4646
static List<String> splitEscaped(String string, char delimiter) {
47-
List<Token> tokens = tokenize(Preconditions.checkNotNull(string), delimiter);
47+
List<Token> tokens = tokenize(checkNotNull(string), delimiter);
4848
return processTokens(tokens);
4949
}
5050

fluss-common/src/main/java/com/alibaba/fluss/fs/ClosingFSDataInputStream.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
package com.alibaba.fluss.fs;
1818

1919
import com.alibaba.fluss.annotation.Internal;
20-
import com.alibaba.fluss.utils.Preconditions;
2120
import com.alibaba.fluss.utils.WrappingProxy;
2221

2322
import java.io.IOException;
2423

24+
import static com.alibaba.fluss.utils.Preconditions.checkNotNull;
25+
2526
/**
2627
* This class is a {@link WrappingProxy} for {@link FSDataInputStream} that is used to implement a
2728
* safety net against unclosed streams.
@@ -40,8 +41,8 @@ public class ClosingFSDataInputStream extends FSDataInputStreamWrapper
4041
private ClosingFSDataInputStream(
4142
FSDataInputStream delegate, SafetyNetCloseableRegistry registry, String debugInfo) {
4243
super(delegate);
43-
this.registry = Preconditions.checkNotNull(registry);
44-
this.debugInfo = Preconditions.checkNotNull(debugInfo);
44+
this.registry = checkNotNull(registry);
45+
this.debugInfo = checkNotNull(debugInfo);
4546
this.closed = false;
4647
}
4748

0 commit comments

Comments
 (0)