code
stringlengths 25
201k
| docstring
stringlengths 19
96.2k
| func_name
stringlengths 0
235
| language
stringclasses 1
value | repo
stringlengths 8
51
| path
stringlengths 11
314
| url
stringlengths 62
377
| license
stringclasses 7
values |
|---|---|---|---|---|---|---|---|
@Memoized
@Override
Iterable<? extends RecursableDiffEntity> childEntities() {
return breakdown().asSet();
}
|
A detailed breakdown of the comparison between the messages. Present iff {@code actual()}
and {@code expected()} are {@link Message}s.
|
childEntities
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
|
Apache-2.0
|
@Memoized
@Override
Iterable<? extends RecursableDiffEntity> childEntities() {
// Assemble the diffs in field number order so it most closely matches the schema.
ImmutableList.Builder<RecursableDiffEntity> builder =
ImmutableList.builderWithExpectedSize(
singularFields().size() + repeatedFields().size() + unknownFields().asSet().size());
Set<Integer> fieldNumbers = Sets.union(singularFields().keySet(), repeatedFields().keySet());
for (int fieldNumber : Ordering.natural().sortedCopy(fieldNumbers)) {
builder.addAll(singularFields().get(fieldNumber));
builder.addAll(repeatedFields().get(fieldNumber));
}
builder.addAll(unknownFields().asSet());
return builder.build();
}
|
The result of comparing the message's {@link UnknownFieldSet}s. Not present if unknown fields
were not compared.
|
childEntities
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
|
Apache-2.0
|
boolean isEmpty() {
return children.isEmpty();
}
|
Returns whether this {@code FieldNumberTree} has no children.
|
isEmpty
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldNumberTree.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldNumberTree.java
|
Apache-2.0
|
FieldNumberTree child(SubScopeId subScopeId) {
FieldNumberTree child = children.get(subScopeId);
return child == null ? EMPTY : child;
}
|
Returns the {@code FieldNumberTree} corresponding to this sub-field.
<p>{@code empty()} if there is none.
|
child
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldNumberTree.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldNumberTree.java
|
Apache-2.0
|
private void merge(FieldNumberTree other) {
for (SubScopeId subScopeId : other.children.keySet()) {
FieldNumberTree value = other.children.get(subScopeId);
if (!this.children.containsKey(subScopeId)) {
this.children.put(subScopeId, value);
} else {
this.children.get(subScopeId).merge(value);
}
}
}
|
Adds the other tree onto this one. May destroy {@code other} in the process.
|
merge
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldNumberTree.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldNumberTree.java
|
Apache-2.0
|
final boolean contains(Descriptor rootDescriptor, SubScopeId subScopeId) {
return policyFor(rootDescriptor, subScopeId).included();
}
|
Returns whether the given field is included in this FieldScopeLogic.
|
contains
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeLogic.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeLogic.java
|
Apache-2.0
|
@Override
public final FieldScopeLogic subScope(Descriptor rootDescriptor, SubScopeId subScopeId) {
FieldScopeResult result = policyFor(rootDescriptor, subScopeId);
if (result.recursive()) {
return result.included() ? all() : none();
} else {
return subScopeImpl(rootDescriptor, subScopeId);
}
}
|
Returns a {@code FieldScopeLogic} to handle the message pointed to by this descriptor.
<p>Subclasses which can return non-recursive {@link FieldScopeResult}s must override {@link
#subScopeImpl} to implement those cases.
|
subScope
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeLogic.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeLogic.java
|
Apache-2.0
|
@ForOverride
FieldScopeLogic subScopeImpl(Descriptor rootDescriptor, SubScopeId subScopeId) {
throw new UnsupportedOperationException("subScopeImpl not implemented for " + getClass());
}
|
Returns {@link #subScope} for {@code NONRECURSIVE} results.
<p>Throws an {@link UnsupportedOperationException} by default. Subclasses which can return
{@code NONRECURSIVE} results must override this method.
|
subScopeImpl
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeLogic.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeLogic.java
|
Apache-2.0
|
public static <V> FieldScopeLogicMap<V> defaultValue(V value) {
return new FieldScopeLogicMap<>(ImmutableList.of(Entry.of(FieldScopeLogic.all(), value)));
}
|
Returns a map which maps all fields to the given value by default.
|
defaultValue
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeLogicMap.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeLogicMap.java
|
Apache-2.0
|
public static FieldScopeResult of(boolean included, boolean recursively) {
if (included) {
return recursively ? INCLUDED_RECURSIVELY : INCLUDED_NONRECURSIVELY;
} else {
return recursively ? EXCLUDED_RECURSIVELY : EXCLUDED_NONRECURSIVELY;
}
}
|
This field and all its children are excluded from the scope.
|
of
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeResult.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeResult.java
|
Apache-2.0
|
boolean included() {
return included;
}
|
Whether this field should be included or not.
|
included
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeResult.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeResult.java
|
Apache-2.0
|
boolean recursive() {
return recursive;
}
|
Whether this field's sub-children should also be unilaterally included or excluded, conditional
on {@link #included()}
|
recursive
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeResult.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeResult.java
|
Apache-2.0
|
public static FieldScope fromSetFields(
Iterable<? extends Message> messages,
TypeRegistry typeRegistry,
ExtensionRegistry extensionRegistry) {
return FieldScopeImpl.createFromSetFields(messages, typeRegistry, extensionRegistry);
}
|
Creates a {@link FieldScope} covering the fields set in every message in the provided list of
messages, with the same semantics as in {@link #fromSetFields(Message)}.
<p>This can be thought of as the union of the {@link FieldScope}s for each individual message,
or the {@link FieldScope} for the merge of all the messages. These are equivalent.
<p>If there are {@code google.protobuf.Any} protos anywhere within these messages, they will be
unpacked using the provided {@link TypeRegistry} and {@link ExtensionRegistry} to determine
which fields within them should be compared.
@see ProtoFluentAssertion#unpackingAnyUsing
@since 1.2
|
fromSetFields
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
Apache-2.0
|
public static FieldScope ignoringFields(int firstFieldNumber, int... rest) {
return FieldScopeImpl.createIgnoringFields(asList(firstFieldNumber, rest));
}
|
Returns a {@link FieldScope} which matches everything except the provided field numbers for the
top level message type.
<p>The field numbers are ignored recursively on this type. That is, if {@code YourMessage}
contains another {@code YourMessage} somewhere within its subtree, field number {@code X} will
be ignored for all submessages of type {@code YourMessage}, as well as for the top-level
message.
@see FieldScope#ignoringFields(int, int...)
|
ignoringFields
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
Apache-2.0
|
public static FieldScope ignoringFields(Iterable<Integer> fieldNumbers) {
return FieldScopeImpl.createIgnoringFields(fieldNumbers);
}
|
Returns a {@link FieldScope} which matches everything except the provided field numbers for the
top level message type.
<p>The field numbers are ignored recursively on this type. That is, if {@code YourMessage}
contains another {@code YourMessage} somewhere within its subtree, field number {@code X} will
be ignored for all submessages of type {@code YourMessage}, as well as for the top-level
message.
@see FieldScope#ignoringFields(Iterable)
|
ignoringFields
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
Apache-2.0
|
public static FieldScope ignoringFieldDescriptors(
FieldDescriptor firstFieldDescriptor, FieldDescriptor... rest) {
return FieldScopeImpl.createIgnoringFieldDescriptors(asList(firstFieldDescriptor, rest));
}
|
Returns a {@link FieldScope} which matches everything except the provided field descriptors for
the message.
@see FieldScope#ignoringFieldDescriptors(FieldDescriptor, FieldDescriptor...)
|
ignoringFieldDescriptors
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
Apache-2.0
|
public static FieldScope ignoringFieldDescriptors(Iterable<FieldDescriptor> fieldDescriptors) {
return FieldScopeImpl.createIgnoringFieldDescriptors(fieldDescriptors);
}
|
Returns a {@link FieldScope} which matches everything except the provided field descriptors for
the message.
@see FieldScope#ignoringFieldDescriptors(Iterable)
|
ignoringFieldDescriptors
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
Apache-2.0
|
public static FieldScope allowingFields(int firstFieldNumber, int... rest) {
return FieldScopeImpl.createAllowingFields(asList(firstFieldNumber, rest));
}
|
Returns a {@link FieldScope} which matches nothing except the provided field numbers for the
top level message type.
@see FieldScope#allowingFields(int, int...)
|
allowingFields
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
Apache-2.0
|
public static FieldScope allowingFields(Iterable<Integer> fieldNumbers) {
return FieldScopeImpl.createAllowingFields(fieldNumbers);
}
|
Returns a {@link FieldScope} which matches nothing except the provided field numbers for the
top level message type.
@see FieldScope#allowingFields(Iterable)
|
allowingFields
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
Apache-2.0
|
public static FieldScope allowingFieldDescriptors(
FieldDescriptor firstFieldDescriptor, FieldDescriptor... rest) {
return FieldScopeImpl.createAllowingFieldDescriptors(asList(firstFieldDescriptor, rest));
}
|
Returns a {@link FieldScope} which matches nothing except the provided field descriptors for
the message.
@see FieldScope#allowingFieldDescriptors(FieldDescriptor, FieldDescriptor...)
|
allowingFieldDescriptors
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
Apache-2.0
|
public static FieldScope allowingFieldDescriptors(Iterable<FieldDescriptor> fieldDescriptors) {
return FieldScopeImpl.createAllowingFieldDescriptors(fieldDescriptors);
}
|
Returns a {@link FieldScope} which matches nothing except the provided field descriptors for
the message.
@see FieldScope#allowingFieldDescriptors(Iterable)
|
allowingFieldDescriptors
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
Apache-2.0
|
public static FieldScope all() {
return FieldScopeImpl.all();
}
|
Returns a {@link FieldScope} which matches all fields without exception. Generally not needed,
since the other factory functions will build on top of this for you.
|
all
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
Apache-2.0
|
public static FieldScope none() {
return FieldScopeImpl.none();
}
|
Returns a {@link FieldScope} which matches no fields. A comparison made using this scope alone
will always trivially pass. Generally not needed, since the other factory functions will build
on top of this for you.
|
none
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
|
Apache-2.0
|
static Function<Optional<Descriptor>, String> fieldNumbersFunction(
String fmt, Iterable<Integer> fieldNumbers) {
return optDescriptor -> resolveFieldNumbers(optDescriptor, fmt, fieldNumbers);
}
|
Returns a function which translates integer field numbers into field names using the Descriptor
if available.
@param fmt Format string that must contain exactly one '%s' and no other format parameters.
|
fieldNumbersFunction
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeUtil.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeUtil.java
|
Apache-2.0
|
static Function<Optional<Descriptor>, String> fieldScopeFunction(
String fmt, FieldScope fieldScope) {
return optDescriptor -> String.format(fmt, fieldScope.usingCorrespondenceString(optDescriptor));
}
|
Returns a function which formats the given string by getting the usingCorrespondenceString from
the given FieldScope with the argument descriptor.
@param fmt Format string that must contain exactly one '%s' and no other format parameters.
|
fieldScopeFunction
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeUtil.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeUtil.java
|
Apache-2.0
|
static Function<Optional<Descriptor>, String> concat(
Function<? super Optional<Descriptor>, String> function1,
Function<? super Optional<Descriptor>, String> function2) {
return optDescriptor -> function1.apply(optDescriptor) + function2.apply(optDescriptor);
}
|
Returns a function which concatenates the outputs of the two input functions.
|
concat
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeUtil.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeUtil.java
|
Apache-2.0
|
static Optional<Descriptor> getSingleDescriptor(Iterable<? extends Message> messages) {
Optional<Descriptor> optDescriptor = Optional.absent();
for (Message message : messages) {
if (message != null) {
Descriptor descriptor = message.getDescriptorForType();
if (!optDescriptor.isPresent()) {
optDescriptor = Optional.of(descriptor);
} else if (descriptor != optDescriptor.get()) {
// Two different descriptors - abandon ship.
return Optional.absent();
}
}
}
return optDescriptor;
}
|
Returns the singular descriptor used by all non-null messages in the list.
<p>If there is no descriptor, or more than one, returns {@code Optional.absent()}.
|
getSingleDescriptor
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeUtil.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeUtil.java
|
Apache-2.0
|
private static String resolveFieldNumbers(
Optional<Descriptor> optDescriptor, String fmt, Iterable<Integer> fieldNumbers) {
if (optDescriptor.isPresent()) {
Descriptor descriptor = optDescriptor.get();
List<String> strings = new ArrayList<>();
for (int fieldNumber : fieldNumbers) {
FieldDescriptor field = descriptor.findFieldByNumber(fieldNumber);
strings.add(field != null ? field.toString() : String.format("%d (?)", fieldNumber));
}
return String.format(fmt, join(strings));
} else {
return String.format(fmt, join(fieldNumbers));
}
}
|
Formats {@code fmt} with the field numbers, concatenated, if a descriptor is available to
resolve them to field names. Otherwise it uses the raw integers.
@param fmt Format string that must contain exactly one '%s' and no other format parameters.
|
resolveFieldNumbers
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeUtil.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeUtil.java
|
Apache-2.0
|
@Override
protected String actualCustomStringRepresentation() {
if (actual == null) {
return "null";
}
StringBuilder sb = new StringBuilder().append('[');
boolean first = true;
for (M element : actual) {
if (!first) {
sb.append(", ");
}
first = false;
try {
protoPrinter.print(element, sb);
} catch (IOException impossible) {
throw new AssertionError(impossible);
}
}
return sb.append(']').toString();
}
|
Truth subject for the iterables of protocol buffers.
<p>{@code ProtoTruth.assertThat(actual).containsExactly(expected)} performs the same assertion as
{@code Truth.assertThat(actual).containsExactly(expected)}. By default, the assertions are strict
with respect to repeated field order, missing fields, etc. This behavior can be changed with the
configuration methods on this subject, e.g. {@code
ProtoTruth.assertThat(actual).ignoringRepeatedFieldOrder().containsExactlyEntriesIn(expected)}.
<p>By default, floating-point fields are compared using exact equality, which is <a
href="https://truth.dev/floating_point">probably not what you want</a> if the values are the
results of some arithmetic. To check for approximate equality, use {@link #usingDoubleTolerance},
{@link #usingFloatTolerance}, and {@linkplain #usingDoubleToleranceForFields(double, int, int...)
their per-field equivalents}.
<p>Equality tests, and other methods, may yield slightly different behavior for versions 2 and 3
of Protocol Buffers. If testing protos of multiple versions, make sure you understand the
behaviors of default and unknown fields so you don't under or over test.
@param <M> the type of the messages in the {@code Iterable}
|
actualCustomStringRepresentation
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/IterableOfProtosSubject.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/IterableOfProtosSubject.java
|
Apache-2.0
|
@Override
@Deprecated
public final void isInStrictOrder() {
throw new ClassCastException(
"Protos do not implement Comparable, so you must supply a Comparator.");
}
|
@deprecated Protos do not implement {@link Comparable}, so you must {@linkplain
#isInStrictOrder(Comparator) supply a comparator}.
@throws ClassCastException always
|
isInStrictOrder
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/IterableOfProtosSubject.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/IterableOfProtosSubject.java
|
Apache-2.0
|
MapWithProtoValuesFluentAssertion<M> usingConfig(FluentEqualityConfig newConfig) {
return new MapWithProtoValuesFluentAssertionImpl<>(
new MapWithProtoValuesSubject<>(metadata, newConfig, actual));
}
|
Truth subject for maps with protocol buffers for values.
<p>{@code ProtoTruth.assertThat(actual).containsExactlyEntriesIn(expected)} performs the same
assertion as {@code Truth.assertThat(actual).containsExactlyEntriesIn(expected)}. By default, the
assertions are strict with respect to repeated field order, missing fields, etc. This behavior
can be changed with the configuration methods on this subject, e.g. {@code
ProtoTruth.assertThat(actual).ignoringRepeatedFieldOrder().containsExactly(expected)}.
<p>By default, floating-point fields are compared using exact equality, which is <a
href="https://truth.dev/floating_point">probably not what you want</a> if the values are the
results of some arithmetic. To check for approximate equality, use {@link
#usingDoubleToleranceForValues}, {@link #usingFloatToleranceForValues}, and {@linkplain
#usingDoubleToleranceForFieldsForValues(double, int, int...) their per-field equivalents}.
<p>Equality tests, and other methods, may yield slightly different behavior for versions 2 and 3
of Protocol Buffers. If testing protos of multiple versions, make sure you understand the
behaviors of default and unknown fields so you don't under or over test.
@param <M> the type of the message values in the map
|
usingConfig
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MapWithProtoValuesSubject.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MapWithProtoValuesSubject.java
|
Apache-2.0
|
ProtoFluentAssertionImpl usingConfig(FluentEqualityConfig newConfig) {
return new ProtoFluentAssertionImpl(new ProtoSubject(metadata, newConfig, actual));
}
|
Truth subject for the full version of Protocol Buffers.
<p>{@code ProtoTruth.assertThat(actual).isEqualTo(expected)} performs the same assertion as
{@code Truth.assertThat(actual).isEqualTo(expected)}, but with a better failure message. By
default, the assertions are strict with respect to repeated field order, missing fields, etc.
This behavior can be changed with the configuration methods on this subject, e.g. {@code
ProtoTruth.assertThat(actual).ignoringRepeatedFieldOrder().isEqualTo(expected)}.
<p>By default, floating-point fields are compared using exact equality, which is <a
href="https://truth.dev/floating_point">probably not what you want</a> if the values are the
results of some arithmetic. To check for approximate equality, use {@link #usingDoubleTolerance},
{@link #usingFloatTolerance}, and {@linkplain #usingDoubleToleranceForFields(double, int, int...)
their per-field equivalents}.
<p>Equality tests, and other methods, may yield slightly different behavior for versions 2 and 3
of Protocol Buffers. If testing protos of multiple versions, make sure you understand the
behaviors of default and unknown fields so you don't under or over test.
|
usingConfig
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubject.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubject.java
|
Apache-2.0
|
boolean testIsEqualTo(@Nullable Message expected) {
if (notMessagesWithSameDescriptor(protoSubject.actual, expected)) {
return Objects.equals(protoSubject.actual, expected);
} else {
return protoSubject
.makeDifferencer(expected)
.diffMessages(protoSubject.actual, expected)
.isMatched();
}
}
|
Same as {@link #isEqualTo(Message)}, except it returns true on success and false on failure
without throwing any exceptions.
|
testIsEqualTo
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubject.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubject.java
|
Apache-2.0
|
public static CustomSubjectBuilder.Factory<ProtoSubjectBuilder> protos() {
return ProtoSubjectBuilder.factory();
}
|
Returns a {@link CustomSubjectBuilder.Factory}, akin to a {@link
com.google.common.truth.Subject.Factory}, which can be used to assert on multiple types of
Protos and collections containing them.
|
protos
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java
|
Apache-2.0
|
public static LiteProtoSubject assertThat(@Nullable MessageLite messageLite) {
return assertAbout(protos()).that(messageLite);
}
|
Assert on a single {@link MessageLite} instance.
|
assertThat
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java
|
Apache-2.0
|
public static ProtoSubject assertThat(@Nullable Message message) {
return assertAbout(protos()).that(message);
}
|
Assert on a single {@link Message} instance.
|
assertThat
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java
|
Apache-2.0
|
public static <M extends Message> IterableOfProtosSubject<M> assertThat(
@Nullable Iterable<M> messages) {
return assertAbout(protos()).that(messages);
}
|
Assert on a sequence of {@link Message}s.
<p>This allows for the equality configurations on {@link ProtoSubject} to be applied to all
comparison tests available on {@link IterableSubject.UsingCorrespondence}.
|
assertThat
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java
|
Apache-2.0
|
public static <M extends Message> MapWithProtoValuesSubject<M> assertThat(
@Nullable Map<?, M> map) {
return assertAbout(protos()).that(map);
}
|
Assert on a map with {@link Message} values.
<p>This allows for the equality configurations on {@link ProtoSubject} to be applied to all
comparison tests available on {@link MapSubject.UsingCorrespondence}.
|
assertThat
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java
|
Apache-2.0
|
public static <M extends Message> MultimapWithProtoValuesSubject<M> assertThat(
@Nullable Multimap<?, M> multimap) {
return assertAbout(protos()).that(multimap);
}
|
Assert on a {@link Multimap} with {@link Message} values.
<p>This allows for the equality configurations on {@link ProtoSubject} to be applied to all
comparison tests available on {@link MultimapSubject.UsingCorrespondence}.
|
assertThat
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java
|
Apache-2.0
|
static ProtoTruthMessageDifferencer create(
FluentEqualityConfig rootConfig, Descriptor descriptor) {
return new ProtoTruthMessageDifferencer(rootConfig, descriptor);
}
|
Create a new {@link ProtoTruthMessageDifferencer} for the given config and descriptor.
|
create
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruthMessageDifferencer.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruthMessageDifferencer.java
|
Apache-2.0
|
private static Set<Integer> setForRange(int max) {
Set<Integer> set = new LinkedHashSet<>();
for (int i = 0; i < max; i++) {
set.add(i);
}
return set;
}
|
Returns a {@link LinkedHashSet} containing the integers in {@code [0, max)}, in order.
|
setForRange
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruthMessageDifferencer.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruthMessageDifferencer.java
|
Apache-2.0
|
final boolean isAnyChildMatched() {
if (isAnyChildMatched == null) {
isAnyChildMatched = false;
for (RecursableDiffEntity entity : childEntities()) {
if ((entity.isMatched() && !entity.isContentEmpty()) || entity.isAnyChildMatched()) {
isAnyChildMatched = true;
break;
}
}
}
return isAnyChildMatched;
}
|
Returns true if some child entity matched.
<p>Caches the result for future calls.
|
isAnyChildMatched
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/RecursableDiffEntity.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/RecursableDiffEntity.java
|
Apache-2.0
|
final boolean isAnyChildIgnored() {
if (isAnyChildIgnored == null) {
isAnyChildIgnored = false;
for (RecursableDiffEntity entity : childEntities()) {
if ((entity.isIgnored() && !entity.isContentEmpty()) || entity.isAnyChildIgnored()) {
isAnyChildIgnored = true;
break;
}
}
}
return isAnyChildIgnored;
}
|
Returns true if some child entity was ignored.
<p>Caches the result for future calls.
|
isAnyChildIgnored
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/RecursableDiffEntity.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/RecursableDiffEntity.java
|
Apache-2.0
|
final void printChildContents(boolean includeMatches, String fieldPrefix, StringBuilder sb) {
for (RecursableDiffEntity entity : childEntities()) {
entity.printContents(includeMatches, fieldPrefix, sb);
}
}
|
Returns true if this entity has no contents to print, with or without includeMatches.
|
printChildContents
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/RecursableDiffEntity.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/RecursableDiffEntity.java
|
Apache-2.0
|
protected final void expectFailureMatches(String regex) {
expectThatFailure().hasMessageThat().matches(Pattern.compile(regex, Pattern.DOTALL));
}
|
Expects the current {@link ExpectFailure} failure message to match the provided regex, using
{@code Pattern.DOTALL} to match newlines.
|
expectFailureMatches
|
java
|
google/truth
|
extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java
|
Apache-2.0
|
public static Subject.Factory<Re2jStringSubject, String> re2jString() {
return Re2jStringSubject::new;
}
|
Returns a subject factory for {@link String} subjects which you can use to assert things about
{@link com.google.re2j.Pattern} regexes.
<p>This subject does not replace Truth's built-in {@link com.google.common.truth.StringSubject}
but instead provides only the methods needed to deal with regular expressions.
@see com.google.common.truth.StringSubject
|
re2jString
|
java
|
google/truth
|
extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
https://github.com/google/truth/blob/master/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
Apache-2.0
|
@Override
protected String actualCustomStringRepresentation() {
return quote(checkNotNull(actual));
}
|
Subject for {@link String} subjects which you can use to assert things about {@link
com.google.re2j.Pattern} regexes.
@see #re2jString
|
actualCustomStringRepresentation
|
java
|
google/truth
|
extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
https://github.com/google/truth/blob/master/extensions/re2j/src/main/java/com/google/common/truth/extensions/re2j/Re2jSubjects.java
|
Apache-2.0
|
private static ImmutableList<CorrespondenceCode> computePossibleReplacements(
ClassTree classTree, VisitorState state) {
ImmutableSetMultimap<MemberType, Tree> members =
classTree.getMembers().stream()
.collect(toImmutableSetMultimap(m -> MemberType.from(m, state), m -> m));
if (members.containsKey(MemberType.OTHER)
|| members.get(CONSTRUCTOR).size() != 1
|| members.get(COMPARE_METHOD).size() != 1
|| members.get(TO_STRING_METHOD).size() != 1) {
return ImmutableList.of();
}
MethodTree constructor = (MethodTree) getOnlyElement(members.get(CONSTRUCTOR));
MethodTree compareMethod = (MethodTree) getOnlyElement(members.get(COMPARE_METHOD));
MethodTree toStringMethod = (MethodTree) getOnlyElement(members.get(TO_STRING_METHOD));
if (!constructorCallsOnlySuper(constructor)) {
return ImmutableList.of();
}
ImmutableList<BinaryPredicateCode> binaryPredicates =
makeBinaryPredicates(classTree, compareMethod, state);
ExpressionTree toStringReturns = returnExpression(toStringMethod);
if (toStringReturns == null) {
return ImmutableList.of();
}
/*
* Replace bad toString() implementations that merely `return null`, since the factories make
* that an immediate error.
*/
String description =
toStringReturns.getKind() == NULL_LITERAL
? "\"corresponds to\""
: state.getSourceForNode(toStringReturns);
return binaryPredicates.stream()
.map(p -> CorrespondenceCode.create(p, description))
.collect(toImmutableList());
}
|
If the given correspondence implementation is "simple enough," returns one or more possible
replacements for its definition and instantiation sites.
|
computePossibleReplacements
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private static ImmutableList<BinaryPredicateCode> makeBinaryPredicates(
ClassTree classTree, MethodTree compareMethod, VisitorState state) {
Tree comparison = maybeMakeLambdaBody(compareMethod, state);
if (comparison == null) {
ClassTree enclosing = findStrictlyEnclosing(state, ClassTree.class);
CharSequence newCompareMethodOwner;
String newCompareMethodName;
if (enclosing == null) {
newCompareMethodName = "compare";
newCompareMethodOwner = classTree.getSimpleName();
} else {
newCompareMethodName =
"compare" + classTree.getSimpleName().toString().replaceFirst("Correspondence$", "");
newCompareMethodOwner = enclosing.getSimpleName();
}
// TODO(cpovirk): We're unlikely to get away with declaring everything `static`.
String supportingMethodDefinition =
format(
"private static boolean %s(%s, %s) %s",
newCompareMethodName,
state.getSourceForNode(compareMethod.getParameters().get(0)),
state.getSourceForNode(compareMethod.getParameters().get(1)),
state.getSourceForNode(compareMethod.getBody()));
return ImmutableList.of(
BinaryPredicateCode.create(
newCompareMethodOwner + "::" + newCompareMethodName, supportingMethodDefinition));
}
// First try without types, then try with.
return ImmutableList.of(
BinaryPredicateCode.fromParamsAndExpression(
compareMethod.getParameters().get(0).getName(),
compareMethod.getParameters().get(1).getName(),
state.getSourceForNode(comparison)),
BinaryPredicateCode.fromParamsAndExpression(
state.getSourceForNode(compareMethod.getParameters().get(0)),
state.getSourceForNode(compareMethod.getParameters().get(1)),
state.getSourceForNode(comparison)));
}
|
Returns one or more possible replacements for the given correspondence's {@code compare} method's definition and for code to pass to {@code Correspondence.from) to construct a correspondence that uses the replacement.
|
makeBinaryPredicates
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private static <T extends Tree> @Nullable T findStrictlyEnclosing(
VisitorState state, Class<T> clazz) {
return stream(state.getPath().getParentPath())
.filter(clazz::isInstance)
.map(clazz::cast)
.findAny()
.orElse(null);
}
|
Like {@link VisitorState#findEnclosing} but doesn't consider the leaf to enclose itself.
|
findStrictlyEnclosing
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
private static @Nullable Tree findChildOfStrictlyEnclosing(
VisitorState state, Class<? extends Tree> clazz) {
Tree previous = state.getPath().getLeaf();
for (Tree t : state.getPath().getParentPath()) {
if (clazz.isInstance(t)) {
return previous;
}
previous = t;
}
return null;
}
|
Like {@link #findStrictlyEnclosing} but returns not the found element but its child along the
path. For example, if called with {@code ClassTree}, it might return a {@code MethodTree}
inside the class.
|
findChildOfStrictlyEnclosing
|
java
|
google/truth
|
refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
https://github.com/google/truth/blob/master/refactorings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
|
Apache-2.0
|
public static <V> FloatMap<V> from(IMap<Number, V> m) {
if (m instanceof FloatMap) {
return (FloatMap) m.forked();
} else {
return from(m.entries());
}
}
|
A map which has floating-point keys, built atop {@link IntMap}, with which it shares performance characteristics.
<p>
Since this is intended foremost as a sorted data structure, it does not allow {@code NaN} and treats {@code -0.0} as
equivalent to {@code 0.0}. Anyone looking for identity-based semantics should use a normal {@code Map} instead.
@author ztellman
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/FloatMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/FloatMap.java
|
MIT
|
public static <V> FloatMap<V> from(java.util.Map<Number, V> m) {
return from(m.entrySet());
}
|
@param m a Java map
@return a forked copy of the map
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/FloatMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/FloatMap.java
|
MIT
|
public static <V, E> Optional<IList<V>> shortestPath(
IGraph<V, E> graph,
V start,
Predicate<V> accept,
ToDoubleFunction<IEdge<V, E>> cost
) {
return shortestPath(graph, LinearList.of(start), accept, cost);
}
|
@param graph a graph
@param start the starting vertex
@param accept a predicate for whether a vertex represents a search end state
@param cost the cost associated with each edge
@return the shortest path, if one exists, between the starting vertex and an accepted vertex, excluding trivial
solutions where a starting vertex is accepted
|
shortestPath
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Graphs.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Graphs.java
|
MIT
|
public static <V, E> Optional<IList<V>> shortestPath(
IGraph<V, E> graph,
Iterable<V> start,
Predicate<V> accept,
ToDoubleFunction<IEdge<V, E>> cost
) {
IMap<V, IMap<V, ShortestPathState<V>>> originStates = new LinearMap<>();
PriorityQueue<ShortestPathState<V>> queue = new PriorityQueue<>(Comparator.comparingDouble(x -> x.distance));
for (V v : start) {
if (graph.vertices().contains(v)) {
ShortestPathState<V> init = new ShortestPathState<>(v);
originStates.getOrCreate(v, LinearMap::new).put(v, init);
queue.add(init);
}
}
ShortestPathState<V> curr;
for (; ; ) {
curr = queue.poll();
if (curr == null) {
return Optional.empty();
}
IMap<V, ShortestPathState<V>> states = originStates.get(curr.origin).get();
if (states.get(curr.node).get() != curr) {
continue;
} else if (curr.prev != null && accept.test(curr.node)) {
return Optional.of(List.from(curr.path()));
}
for (V v : graph.out(curr.node)) {
double edge = cost.applyAsDouble(new DirectedEdge<V, E>(graph.edge(curr.node, v), curr.node, v));
if (edge < 0) {
throw new IllegalArgumentException("negative edge weights are unsupported");
}
ShortestPathState<V> next = states.get(v, null);
if (next == null) {
next = new ShortestPathState<V>(v, curr, edge);
} else if (curr.distance + edge < next.distance) {
next = new ShortestPathState<V>(v, curr, edge);
} else {
continue;
}
states.put(v, next);
queue.add(next);
}
}
}
|
@param graph a graph
@param start a list of starting vertices
@param accept a predicate for whether a vertex represents a search end state
@param cost the cost associated with each edge
@return the shortest path, if one exists, between a starting vertex and an accepted vertex, excluding trivial
solutions where a starting vertex is accepted
|
shortestPath
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Graphs.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Graphs.java
|
MIT
|
public static <V> Set<Set<V>> connectedComponents(IGraph<V, ?> graph) {
if (graph.isDirected()) {
throw new IllegalArgumentException("graph must be undirected");
}
LinearSet<V> traversed = new LinearSet<>((int) graph.vertices().size(), graph.vertexHash(), graph.vertexEquality());
Set<Set<V>> result = new Set<Set<V>>().linear();
for (V seed : graph.vertices()) {
if (!traversed.contains(seed)) {
Set<V> group = new Set<>(graph.vertexHash(), graph.vertexEquality()).linear();
bfsVertices(LinearList.of(seed), graph::out).forEach(group::add);
result.add(group.forked());
group.forEach(traversed::add);
}
}
return result.forked();
}
|
@return sets of vertices, where each vertex can reach every other vertex within the set
|
connectedComponents
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Graphs.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Graphs.java
|
MIT
|
public static <V> Set<Set<V>> biconnectedComponents(IGraph<V, ?> graph) {
Set<V> cuts = articulationPoints(graph);
Set<Set<V>> result = new Set<Set<V>>().linear();
for (Set<V> component : connectedComponents(graph.select(graph.vertices().difference(cuts)))) {
result.add(
component.union(
cuts.stream()
.filter(v -> graph.out(v).containsAny(component))
.collect(Sets.collector())));
}
for (int i = 0; i < cuts.size() - 1; i++) {
for (int j = i + 1; j < cuts.size(); j++) {
V a = cuts.nth(i);
V b = cuts.nth(i + 1);
if (graph.out(a).contains(b)) {
result.add(Set.of(a, b));
}
}
}
return result.forked();
}
|
@return sets of vertices, where each vertex can reach every other vertex within the set, even if a single vertex
is removed
|
biconnectedComponents
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Graphs.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Graphs.java
|
MIT
|
public static <V> Set<V> articulationPoints(IGraph<V, ?> graph) {
if (graph.isDirected()) {
throw new IllegalArgumentException("graph must be undirected");
}
// algorithmic state
IMap<V, ArticulationPointState<V>> state = new LinearMap<>(
(int) graph.vertices().size(),
graph.vertexHash(),
graph.vertexEquality()
);
// call-stack state
LinearList<ArticulationPointState<V>> path = new LinearList<>();
LinearList<Iterator<V>> branches = new LinearList<>();
Set<V> result = new Set<V>().linear();
for (V seed : graph.vertices()) {
if (state.contains(seed)) {
continue;
}
ArticulationPointState<V> s = new ArticulationPointState<>(seed, 0);
path.addLast(s);
branches.addLast(graph.out(seed).iterator());
state.put(seed, s);
while (path.size() > 0) {
// traverse deeper
if (branches.last().hasNext()) {
V w = branches.last().next();
ArticulationPointState<V> vs = path.last();
ArticulationPointState<V> ws = state.get(w, null);
if (ws == null) {
ws = new ArticulationPointState<>(w, (int) path.size());
vs.childCount++;
state.put(w, ws);
path.addLast(ws);
branches.addLast(graph.out(w).iterator());
} else {
vs.lowlink = min(vs.lowlink, ws.depth);
}
// return
} else {
branches.popLast();
ArticulationPointState<V> ws = path.popLast();
if (path.size() > 0) {
ArticulationPointState<V> vs = path.last();
vs.lowlink = min(ws.lowlink, vs.lowlink);
if ((path.size() > 1 && ws.lowlink >= vs.depth)
|| (path.size() == 1 && vs.childCount > 1)) {
result.add(vs.node);
}
}
}
}
}
return result.forked();
}
|
@return all articulation or "cut" vertices, where the removal of that vertex will partition the graph
|
articulationPoints
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Graphs.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Graphs.java
|
MIT
|
default boolean isLinear() {
return false;
}
|
@return true, if the list is linear
|
isLinear
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IList.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IList.java
|
MIT
|
default IList<V> slice(long start, long end) {
return Lists.slice(this, start, end);
}
|
@param start the inclusive start of the range
@param end the exclusive end of the range
@return a sub-range of the list within {@code [start, end)}, which is linear if {@code this} is linear
|
slice
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IList.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IList.java
|
MIT
|
default IList<V> concat(IList<V> l) {
return Lists.concat(this, l);
}
|
@param l another list
@return a new collection representing the concatenation of the two lists, which is linear if {@code this} is linear
|
concat
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IList.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IList.java
|
MIT
|
default V first() {
if (size() == 0) {
throw new IndexOutOfBoundsException();
}
return nth(0);
}
|
@return the first element
@throws IndexOutOfBoundsException if the collection is empty
|
first
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IList.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IList.java
|
MIT
|
default V get(K key, V defaultValue) {
OptionalLong idx = indexOf(key);
return idx.isPresent()
? nth(idx.getAsLong()).value()
: defaultValue;
}
|
@return the value under {@code key}, or {@code defaultValue} if there is no such key
|
get
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default Optional<V> get(K key) {
return Optional.ofNullable(get(key, null));
}
|
@return an {@link Optional} containing the value under {@code key}, or nothing if the value is {@code null} or
is not contained within the map.
|
get
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default V getOrCreate(K key, Supplier<V> f) {
V val = get(key, null);
if (val == null) {
val = f.get();
put(key, val);
}
return val;
}
|
@return the value under {@code key}, or one generated by {@code f} if there is no such key
|
getOrCreate
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default boolean contains(K key) {
return indexOf(key).isPresent();
}
|
@return true if {@code key} is in the map, false otherwise
|
contains
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default IList<IEntry<K, V>> entries() {
return Lists.from(size(), this::nth, this::iterator);
}
|
@return a list containing all the entries within the map
|
entries
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default ISet<K> keys() {
return Sets.from(Lists.lazyMap(entries(), IEntry::key), this::indexOf);
}
|
@return a set representing all keys in the map
|
keys
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default IList<V> values() {
return Lists.lazyMap(entries(), IEntry::value);
}
|
@return a list representing all values in the map
|
values
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default <U> IMap<K, U> mapValues(BiFunction<K, V, U> f) {
Map<K, U> m = new Map<K, U>(keyHash(), keyEquality()).linear();
this.forEach(e -> m.put(e.key(), f.apply(e.key(), e.value())));
return isLinear() ? m : m.forked();
}
|
@param f a function which transforms the values
@param <U> the new type of the values
@return a transformed map which shares the same equality semantics
|
mapValues
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default boolean containsAll(ISet<K> set) {
return set.elements().stream().allMatch(this::contains);
}
|
@return true if this map contains all elements in {@code set}
|
containsAll
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default boolean containsAll(IMap<K, ?> map) {
return containsAll(map.keys());
}
|
@return true if this map contains all keys in {@code map}
|
containsAll
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default boolean containsAny(ISet<K> set) {
return set.elements().stream().anyMatch(this::contains);
}
|
@return true if this map contains any element in {@code set}
|
containsAny
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default boolean containsAny(IMap<K, ?> map) {
return containsAny(map.keys());
}
|
@return true if this map contains any element in {@code map}
|
containsAny
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default java.util.Map<K, V> toMap() {
return Maps.toMap(this);
}
|
@return the collection, represented as a normal Java map, which will throw {@link UnsupportedOperationException}
on writes
|
toMap
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default Iterator<IEntry<K, V>> iterator(long startIndex) {
return Iterators.range(startIndex, size(), this::nth);
}
|
@return an iterator over all entries in the map
|
iterator
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default IMap<K, V> merge(IMap<K, V> b, BinaryOperator<V> mergeFn) {
return Maps.merge(this, b, mergeFn);
}
|
@param b another map
@param mergeFn a function which, in the case of key collisions, takes two values and returns the merged result
@return a new map representing the merger of the two maps
|
merge
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default IMap<K, V> difference(ISet<K> keys) {
return Maps.difference(this, keys);
}
|
@return a new map representing the current map, less the keys in {@code keys}
|
difference
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default IMap<K, V> intersection(ISet<K> keys) {
IMap<K, V> result = Maps.intersection(new Map<K, V>(keyHash(), keyEquality()).linear(), this, keys);
return isLinear() ? result : result.forked();
}
|
@return a new map representing the current map, but only with the keys in {@code keys}
|
intersection
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default IMap<K, V> union(IMap<K, V> m) {
return merge(m, Maps.MERGE_LAST_WRITE_WINS);
}
|
@return a combined map, with the values from {@code m} shadowing those in this amp
|
union
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default IMap<K, V> difference(IMap<K, ?> m) {
return difference(m.keys());
}
|
@return a new map representing the current map, less the keys in {@code m}
|
difference
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default IMap<K, V> intersection(IMap<K, ?> m) {
return intersection(m.keys());
}
|
@return a new map representing the current map, but only with the keys in {@code m}
|
intersection
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default IMap<K, V> update(K key, UnaryOperator<V> update) {
return this.put(key, update.apply(this.get(key, null)));
}
|
@param update a function which takes the existing value, or {@code null} if none exists, and returns an updated
value.
@return an updated map with {@code update(value)} under {@code key}.
|
update
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default IMap<K, V> put(K key, V value) {
return put(key, value, Maps.MERGE_LAST_WRITE_WINS);
}
|
@return an updated map with {@code value} stored under {@code key}
|
put
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
default boolean equals(IMap<K, V> m, BiPredicate<V, V> equals) {
return Maps.equals(this, m, equals);
}
|
@param m another map
@param equals a predicate which checks value equalities
@return true, if the maps are equivalent
|
equals
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
@Override
default V apply(K k) {
V defaultVal = (V) new Object();
V val = get(k, defaultVal);
if (val == defaultVal) {
throw new IllegalArgumentException("key not found");
}
return val;
}
|
@return the corresponding value
@throws IllegalArgumentException if no such key is inside the map
|
apply
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IMap.java
|
MIT
|
public static <V> IntMap<V> from(IMap<Number, V> m) {
if (m instanceof IntMap) {
return (IntMap) m.forked();
} else {
return from(m.entries());
}
}
|
@param m another map
@return a forked copy of the map
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/IntMap.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/IntMap.java
|
MIT
|
default boolean contains(V value) {
return indexOf(value).isPresent();
}
|
@return true, if the set contains {@code value}
|
contains
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/ISet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/ISet.java
|
MIT
|
default IList<V> elements() {
return Lists.from(size(), this::nth, this::iterator);
}
|
@return a list containing all the elements in the set
|
elements
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/ISet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/ISet.java
|
MIT
|
default <U> IMap<V, U> zip(Function<V, U> f) {
return Maps.from(this, f);
}
|
@return a map which has a corresponding value, computed by {@code f}, for each element in the set
|
zip
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/ISet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/ISet.java
|
MIT
|
default boolean containsAll(ISet<V> set) {
return set.elements().stream().allMatch(this::contains);
}
|
@return true if this set contains every element in {@code set}
|
containsAll
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/ISet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/ISet.java
|
MIT
|
default boolean containsAll(IMap<V, ?> map) {
return containsAll(map.keys());
}
|
@return true if this set contains every key in {@code map}
|
containsAll
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/ISet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/ISet.java
|
MIT
|
default boolean containsAny(ISet<V> set) {
if (size() < set.size()) {
return set.containsAny(this);
} else {
return set.elements().stream().anyMatch(this::contains);
}
}
|
@return true if this set contains any element in {@code set}
|
containsAny
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/ISet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/ISet.java
|
MIT
|
default boolean containsAny(IMap<V, ?> map) {
return containsAny(map.keys());
}
|
@return true if this set contains any key in {@code map}
|
containsAny
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/ISet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/ISet.java
|
MIT
|
default Stream<V> stream() {
return StreamSupport.stream(spliterator(), false);
}
|
@return a {@link java.util.stream.Stream}, representing the elements in the set
|
stream
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/ISet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/ISet.java
|
MIT
|
default ISet<V> union(ISet<V> set) {
return Sets.union(this, set);
}
|
@return a new set, representing the union with {@code set}
|
union
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/ISet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/ISet.java
|
MIT
|
default ISet<V> difference(ISet<V> set) {
return Sets.difference(this, set);
}
|
@return a new set, representing the difference with {@code set}
|
difference
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/ISet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/ISet.java
|
MIT
|
default ISet<V> intersection(ISet<V> set) {
ISet<V> result = Sets.intersection(new Set(valueHash(), valueEquality()).linear(), this, set);
return isLinear() ? result : result.forked();
}
|
@return a new set, representing the intersection with {@code set}
|
intersection
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/ISet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/ISet.java
|
MIT
|
default java.util.Set<V> toSet() {
return Sets.toSet(elements(), this::contains);
}
|
@return the collection, represented as a normal Java set, which will throw {@link UnsupportedOperationException}
on writes
|
toSet
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/ISet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/ISet.java
|
MIT
|
public static <V> LinearList<V> of(V... elements) {
LinearList<V> list = new LinearList<V>(elements.length);
for (V e : elements) {
list.addLast(e);
}
return list;
}
|
A simple implementation of a mutable list combining the best characteristics of {@link java.util.ArrayList} and
{@link java.util.ArrayDeque}, allowing elements to be added and removed from both ends of the collection <i>and</i>
allowing random-access reads and updates. Unlike {@link List}, it can only hold {@code Integer.MAX_VALUE} elements.
<p>
Calls to {@link #concat(IList)}, {@link #slice(long, long)}, and {@link #split(int)} create virtual collections which
retain a reference to the whole underlying collection, and are somewhat less efficient than {@code LinearList}.
@author ztellman
|
of
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/LinearList.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/LinearList.java
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.