Skip to content

Commit 1065c25

Browse files
committed
fix
1 parent 2f90105 commit 1065c25

79 files changed

Lines changed: 23358 additions & 7 deletions

File tree

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/Equivalence.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public final <F> Equivalence<F> onResultOf(Function<? super F, ? extends T> func
161161
*
162162
* @since 10.0
163163
*/
164-
public final <S extends T> Wrapper<S> wrap(@ParametricNullness S reference) {
164+
public final <S extends T> Wrapper<S> wrap(S reference) {
165165
return new Wrapper<>(this, reference);
166166
}
167167

@@ -196,15 +196,14 @@ public static final class Wrapper<T extends Object> implements Serializable {
196196
*/
197197
private final Equivalence<? super T> equivalence;
198198

199-
@ParametricNullness private final T reference;
199+
private final T reference;
200200

201-
private Wrapper(Equivalence<? super T> equivalence, @ParametricNullness T reference) {
201+
private Wrapper(Equivalence<? super T> equivalence, T reference) {
202202
this.equivalence = checkNotNull(equivalence);
203203
this.reference = reference;
204204
}
205205

206206
/** Returns the (possibly null) reference wrapped by this instance. */
207-
@ParametricNullness
208207
public T get() {
209208
return reference;
210209
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (C) 2011 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+
import java.io.Serializable;
20+
21+
import static com.google.common.base.Preconditions.checkNotNull;
22+
23+
/**
24+
* Equivalence applied on functional result.
25+
*
26+
* @author Bob Lee
27+
* @since 10.0
28+
*/
29+
final class FunctionalEquivalence<F, T> extends Equivalence<F> implements Serializable {
30+
31+
private static final long serialVersionUID = 0;
32+
33+
private final Function<? super F, ? extends T> function;
34+
private final Equivalence<T> resultEquivalence;
35+
36+
FunctionalEquivalence(
37+
Function<? super F, ? extends T> function, Equivalence<T> resultEquivalence) {
38+
this.function = checkNotNull(function);
39+
this.resultEquivalence = checkNotNull(resultEquivalence);
40+
}
41+
42+
@Override
43+
protected boolean doEquivalent(F a, F b) {
44+
return resultEquivalence.equivalent(function.apply(a), function.apply(b));
45+
}
46+
47+
@Override
48+
protected int doHash(F a) {
49+
return resultEquivalence.hash(function.apply(a));
50+
}
51+
52+
@Override
53+
public boolean equals(@CheckForNull Object obj) {
54+
if (obj == this) {
55+
return true;
56+
}
57+
if (obj instanceof FunctionalEquivalence) {
58+
FunctionalEquivalence<?, ?> that = (FunctionalEquivalence<?, ?>) obj;
59+
return function.equals(that.function) && resultEquivalence.equals(that.resultEquivalence);
60+
}
61+
return false;
62+
}
63+
64+
@Override
65+
public int hashCode() {
66+
return Objects.hashCode(function, resultEquivalence);
67+
}
68+
69+
@Override
70+
public String toString() {
71+
return resultEquivalence + ".onResultOf(" + function + ")";
72+
}
73+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (C) 2011 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+
import java.io.Serializable;
20+
import java.util.Iterator;
21+
22+
final class PairwiseEquivalence<E, T extends E> extends Equivalence<Iterable<T>>
23+
implements Serializable {
24+
final Equivalence<E> elementEquivalence;
25+
26+
PairwiseEquivalence(Equivalence<E> elementEquivalence) {
27+
this.elementEquivalence = Preconditions.checkNotNull(elementEquivalence);
28+
}
29+
30+
@Override
31+
protected boolean doEquivalent(Iterable<T> iterableA, Iterable<T> iterableB) {
32+
Iterator<T> iteratorA = iterableA.iterator();
33+
Iterator<T> iteratorB = iterableB.iterator();
34+
35+
while (iteratorA.hasNext() && iteratorB.hasNext()) {
36+
if (!elementEquivalence.equivalent(iteratorA.next(), iteratorB.next())) {
37+
return false;
38+
}
39+
}
40+
41+
return !iteratorA.hasNext() && !iteratorB.hasNext();
42+
}
43+
44+
@Override
45+
protected int doHash(Iterable<T> iterable) {
46+
int hash = 78721;
47+
for (T element : iterable) {
48+
hash = hash * 24943 + elementEquivalence.hash(element);
49+
}
50+
return hash;
51+
}
52+
53+
@Override
54+
public boolean equals(@CheckForNull Object object) {
55+
if (object instanceof PairwiseEquivalence) {
56+
@SuppressWarnings("unchecked")
57+
PairwiseEquivalence<Object, Object> that = (PairwiseEquivalence<Object, Object>) object;
58+
return this.elementEquivalence.equals(that.elementEquivalence);
59+
}
60+
61+
return false;
62+
}
63+
64+
@Override
65+
public int hashCode() {
66+
return elementEquivalence.hashCode() ^ 0x46a3eb07;
67+
}
68+
69+
@Override
70+
public String toString() {
71+
return elementEquivalence + ".pairwise()";
72+
}
73+
74+
private static final long serialVersionUID = 1;
75+
}
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
* Copyright (C) 2007 The Guava Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.common.collect;
18+
19+
import javax.annotation.CheckForNull;
20+
21+
import java.util.NoSuchElementException;
22+
23+
import static com.google.common.base.Preconditions.checkState;
24+
import static com.google.common.collect.NullnessCasts.uncheckedCastNullableTToT;
25+
26+
/**
27+
* This class provides a skeletal implementation of the {@code Iterator} interface, to make this
28+
* interface easier to implement for certain types of data sources.
29+
*
30+
* <p>{@code Iterator} requires its implementations to support querying the end-of-data status
31+
* without changing the iterator's state, using the {@link #hasNext} method. But many data sources,
32+
* such as {@link java.io.Reader#read()}, do not expose this information; the only way to discover
33+
* whether there is any data left is by trying to retrieve it. These types of data sources are
34+
* ordinarily difficult to write iterators for. But using this class, one must implement only the
35+
* {@link #computeNext} method, and invoke the {@link #endOfData} method when appropriate.
36+
*
37+
* <p>Another example is an iterator that skips over null elements in a backing iterator. This could
38+
* be implemented as:
39+
*
40+
* <pre>{@code
41+
* public static Iterator<String> skipNulls(final Iterator<String> in) {
42+
* return new AbstractIterator<String>() {
43+
* protected String computeNext() {
44+
* while (in.hasNext()) {
45+
* String s = in.next();
46+
* if (s != null) {
47+
* return s;
48+
* }
49+
* }
50+
* return endOfData();
51+
* }
52+
* };
53+
* }
54+
* }</pre>
55+
*
56+
* <p>This class supports iterators that include null elements.
57+
*
58+
* @author Kevin Bourrillion
59+
* @since 2.0
60+
*/
61+
// When making changes to this class, please also update the copy at
62+
// com.google.common.base.AbstractIterator
63+
public abstract class AbstractIterator<T extends Object> extends UnmodifiableIterator<T> {
64+
private State state = State.NOT_READY;
65+
66+
/** Constructor for use by subclasses. */
67+
protected AbstractIterator() {}
68+
69+
private enum State {
70+
/** We have computed the next element and haven't returned it yet. */
71+
READY,
72+
73+
/** We haven't yet computed or have already returned the element. */
74+
NOT_READY,
75+
76+
/** We have reached the end of the data and are finished. */
77+
DONE,
78+
79+
/** We've suffered an exception and are kaput. */
80+
FAILED,
81+
}
82+
83+
@CheckForNull private T next;
84+
85+
/**
86+
* Returns the next element. <b>Note:</b> the implementation must call {@link #endOfData()} when
87+
* there are no elements left in the iteration. Failure to do so could result in an infinite loop.
88+
*
89+
* <p>The initial invocation of {@link #hasNext()} or {@link #next()} calls this method, as does
90+
* the first invocation of {@code hasNext} or {@code next} following each successful call to
91+
* {@code next}. Once the implementation either invokes {@code endOfData} or throws an exception,
92+
* {@code computeNext} is guaranteed to never be called again.
93+
*
94+
* <p>If this method throws an exception, it will propagate outward to the {@code hasNext} or
95+
* {@code next} invocation that invoked this method. Any further attempts to use the iterator will
96+
* result in an {@link IllegalStateException}.
97+
*
98+
* <p>The implementation of this method may not invoke the {@code hasNext}, {@code next}, or
99+
* {@link #peek()} methods on this instance; if it does, an {@code IllegalStateException} will
100+
* result.
101+
*
102+
* @return the next element if there was one. If {@code endOfData} was called during execution,
103+
* the return value will be ignored.
104+
* @throws RuntimeException if any unrecoverable error happens. This exception will propagate
105+
* outward to the {@code hasNext()}, {@code next()}, or {@code peek()} invocation that invoked
106+
* this method. Any further attempts to use the iterator will result in an {@link
107+
* IllegalStateException}.
108+
*/
109+
@CheckForNull
110+
protected abstract T computeNext();
111+
112+
/**
113+
* Implementations of {@link #computeNext} <b>must</b> invoke this method when there are no
114+
* elements left in the iteration.
115+
*
116+
* @return {@code null}; a convenience so your {@code computeNext} implementation can use the
117+
* simple statement {@code return endOfData();}
118+
*/
119+
@CheckForNull
120+
protected final T endOfData() {
121+
state = State.DONE;
122+
return null;
123+
}
124+
125+
@Override
126+
public final boolean hasNext() {
127+
checkState(state != State.FAILED);
128+
switch (state) {
129+
case DONE:
130+
return false;
131+
case READY:
132+
return true;
133+
default:
134+
}
135+
return tryToComputeNext();
136+
}
137+
138+
private boolean tryToComputeNext() {
139+
state = State.FAILED; // temporary pessimism
140+
next = computeNext();
141+
if (state != State.DONE) {
142+
state = State.READY;
143+
return true;
144+
}
145+
return false;
146+
}
147+
148+
@Override
149+
public final T next() {
150+
if (!hasNext()) {
151+
throw new NoSuchElementException();
152+
}
153+
state = State.NOT_READY;
154+
// Safe because hasNext() ensures that tryToComputeNext() has put a T into `next`.
155+
T result = uncheckedCastNullableTToT(next);
156+
next = null;
157+
return result;
158+
}
159+
160+
/**
161+
* Returns the next element in the iteration without advancing the iteration, according to the
162+
* contract of {@link PeekingIterator#peek()}.
163+
*
164+
* <p>Implementations of {@code AbstractIterator} that wish to expose this functionality should
165+
* implement {@code PeekingIterator}.
166+
*/
167+
public final T peek() {
168+
if (!hasNext()) {
169+
throw new NoSuchElementException();
170+
}
171+
// Safe because hasNext() ensures that tryToComputeNext() has put a T into `next`.
172+
return uncheckedCastNullableTToT(next);
173+
}
174+
}

0 commit comments

Comments
 (0)