Skip to content

Commit 74745ee

Browse files
committed
add com.google.common
1 parent 196959f commit 74745ee

42 files changed

Lines changed: 23882 additions & 0 deletions

Some content is hidden

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

iotdb-core/node-commons/src/main/java/com/google/common/base/Ascii.java

Lines changed: 632 additions & 0 deletions
Large diffs are not rendered by default.

iotdb-core/node-commons/src/main/java/com/google/common/base/CharMatcher.java

Lines changed: 1799 additions & 0 deletions
Large diffs are not rendered by default.

iotdb-core/node-commons/src/main/java/com/google/common/base/Converter.java

Lines changed: 600 additions & 0 deletions
Large diffs are not rendered by default.

iotdb-core/node-commons/src/main/java/com/google/common/base/Joiner.java

Lines changed: 492 additions & 0 deletions
Large diffs are not rendered by default.

iotdb-core/node-commons/src/main/java/com/google/common/base/Lists.java

Lines changed: 1187 additions & 0 deletions
Large diffs are not rendered by default.

iotdb-core/node-commons/src/main/java/com/google/common/base/MoreObjects.java

Lines changed: 434 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (C) 2021 The Guava Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
15+
package com.google.common.base;
16+
17+
import javax.annotation.CheckForNull;
18+
19+
/** A utility method to perform unchecked casts to suppress errors produced by nullness analyses. */
20+
final class NullnessCasts {
21+
/**
22+
* Accepts a {@code @Nullable T} and returns a plain {@code T}, without performing any check that
23+
* that conversion is safe.
24+
*
25+
* <p>This method is intended to help with usages of type parameters that have {@linkplain
26+
* ParametricNullness parametric nullness}. If a type parameter instead ranges over only non-null
27+
* types (or if the type is a non-variable type, like {@code String}), then code should almost
28+
* never use this method, preferring instead to call {@code requireNonNull} so as to benefit from
29+
* its runtime check.
30+
*
31+
* <p>An example use case for this method is in implementing an {@code Iterator<T>} whose {@code
32+
* next} field is lazily initialized. The type of that field would be {@code @Nullable T}, and the
33+
* code would be responsible for populating a "real" {@code T} (which might still be the value
34+
* {@code null}!) before returning it to callers. Depending on how the code is structured, a
35+
* nullness analysis might not understand that the field has been populated. To avoid that problem
36+
* without having to add {@code @SuppressWarnings}, the code can call this method.
37+
*
38+
* <p>Why <i>not</i> just add {@code SuppressWarnings}? The problem is that this method is
39+
* typically useful for {@code return} statements. That leaves the code with two options: Either
40+
* add the suppression to the whole method (which turns off checking for a large section of code),
41+
* or extract a variable, and put the suppression on that. However, a local variable typically
42+
* doesn't work: Because nullness analyses typically infer the nullness of local variables,
43+
* there's no way to assign a {@code @Nullable T} to a field {@code T foo;} and instruct the
44+
* analysis that that means "plain {@code T}" rather than the inferred type {@code @Nullable T}.
45+
* (Even if supported added {@code @NonNull}, that would not help, since the problem case
46+
* addressed by this method is the case in which {@code T} has parametric nullness -- and thus its
47+
* value may be legitimately {@code null}.)
48+
*/
49+
@SuppressWarnings("nullness")
50+
static <T extends Object> T uncheckedCastNullableTToT(@CheckForNull T t) {
51+
return t;
52+
}
53+
54+
private NullnessCasts() {}
55+
}

0 commit comments

Comments
 (0)