Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Adopt google format #9

Merged
merged 1 commit into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ apply from: "${rootDir}/gradle/check-licenses.gradle"
spotless {
groovyGradle {
target '**/*.gradle'
greclipse().configFile(rootProject.file('gradle/greclipse-gradle-tuweni-style.properties'))
endWithNewline()
}
}
Expand All @@ -114,13 +113,15 @@ subprojects {
targetExclude '**/SECP256K1.java'
removeUnusedImports()
licenseHeaderFile rootProject.file('gradle/spotless.license.txt')
eclipse().configFile(rootProject.file('gradle/eclipse-java-tuweni-style.xml'))
googleJavaFormat('1.17.0')
importOrder 'org.apache', 'java', ''
trimTrailingWhitespace()
endWithNewline()
}
kotlin {
licenseHeaderFile rootProject.file('gradle/spotless.license.txt')
ktlint("0.47.1").editorConfigOverride(['indent_size': '2', 'continuation_indent_size' : '2'])
ktlint("0.49.1").editorConfigOverride(['indent_size': '2', 'continuation_indent_size' : '2'])
trimTrailingWhitespace()
endWithNewline()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
package org.apache.tuweni.bytes;

/**
* An abstract {@link Bytes} value that provides implementations of {@link #equals(Object)}, {@link #hashCode()} and
* {@link #toString()}.
* An abstract {@link Bytes} value that provides implementations of {@link #equals(Object)}, {@link
* #hashCode()} and {@link #toString()}.
*/
public abstract class AbstractBytes implements Bytes {

Expand All @@ -16,8 +16,7 @@ public abstract class AbstractBytes implements Bytes {
/**
* Compare this value and the provided one for equality.
*
* <p>
* Two {@link Bytes} values are equal is they have contain the exact same bytes.
* <p>Two {@link Bytes} values are equal is they have contain the exact same bytes.
*
* @param obj The object to test for equality with.
* @return {@code true} if this value and {@code obj} are equal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public Bytes slice(int i, int length) {
this.length - i,
i);

return length == Bytes32.SIZE ? new ArrayWrappingBytes32(bytes, offset + i)
return length == Bytes32.SIZE
? new ArrayWrappingBytes32(bytes, offset + i)
: new ArrayWrappingBytes(bytes, offset + i, length);
}

Expand Down Expand Up @@ -139,7 +140,6 @@ public void appendTo(Buffer buffer) {
buffer.appendBytes(bytes, offset, length);
}


@Override
public byte[] toArray() {
return Arrays.copyOfRange(bytes, offset, offset + length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public byte[] toArray() {
return super.toArray();
}
int arrayOffset = byteBuffer.arrayOffset();
return Arrays.copyOfRange(byteBuffer.array(), arrayOffset + offset, arrayOffset + offset + length);
return Arrays.copyOfRange(
byteBuffer.array(), arrayOffset + offset, arrayOffset + offset + length);
}

@Override
Expand Down
384 changes: 192 additions & 192 deletions bytes/src/main/java/org/apache/tuweni/bytes/Bytes.java

Large diffs are not rendered by default.

85 changes: 38 additions & 47 deletions bytes/src/main/java/org/apache/tuweni/bytes/Bytes32.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import java.security.SecureRandom;
import java.util.Random;

/**
* A {@link Bytes} value that is guaranteed to contain exactly 32 bytes.
*/
/** A {@link Bytes} value that is guaranteed to contain exactly 32 bytes. */
public interface Bytes32 extends Bytes {
/** The number of bytes in this value - i.e. 32 */
int SIZE = 32;
Expand All @@ -31,9 +29,8 @@ static Bytes32 repeat(byte b) {
/**
* Wrap the provided byte array, which must be of length 32, as a {@link Bytes32}.
*
* <p>
* Note that value is not copied, only wrapped, and thus any future update to {@code value} will be reflected in the
* returned value.
* <p>Note that value is not copied, only wrapped, and thus any future update to {@code value}
* will be reflected in the returned value.
*
* @param bytes The bytes to wrap.
* @return A {@link Bytes32} wrapping {@code value}.
Expand All @@ -48,15 +45,14 @@ static Bytes32 wrap(byte[] bytes) {
/**
* Wrap a slice/sub-part of the provided array as a {@link Bytes32}.
*
* <p>
* Note that value is not copied, only wrapped, and thus any future update to {@code value} within the wrapped parts
* will be reflected in the returned value.
* <p>Note that value is not copied, only wrapped, and thus any future update to {@code value}
* within the wrapped parts will be reflected in the returned value.
*
* @param bytes The bytes to wrap.
* @param offset The index (inclusive) in {@code value} of the first byte exposed by the returned value. In other
* words, you will have {@code wrap(value, i).get(0) == value[i]}.
* @return A {@link Bytes32} that exposes the bytes of {@code value} from {@code offset} (inclusive) to
* {@code offset + 32} (exclusive).
* @param offset The index (inclusive) in {@code value} of the first byte exposed by the returned
* value. In other words, you will have {@code wrap(value, i).get(0) == value[i]}.
* @return A {@link Bytes32} that exposes the bytes of {@code value} from {@code offset}
* (inclusive) to {@code offset + 32} (exclusive).
* @throws IndexOutOfBoundsException if {@code offset < 0 || (value.length > 0 && offset >=
* value.length)}.
* @throws IllegalArgumentException if {@code length < 0 || offset + 32 > value.length}.
Expand All @@ -83,10 +79,10 @@ static Bytes32 secure(byte[] bytes) {
* Secures a slice/sub-part of the provided array as a {@link Bytes32}.
*
* @param bytes The bytes to secure.
* @param offset The index (inclusive) in {@code value} of the first byte exposed by the returned value. In other
* words, you will have {@code wrap(value, i).get(0) == value[i]}.
* @return A {@link Bytes32} that holds securely the bytes of {@code value} from {@code offset} (inclusive) to
* {@code offset + 32} (exclusive).
* @param offset The index (inclusive) in {@code value} of the first byte exposed by the returned
* value. In other words, you will have {@code wrap(value, i).get(0) == value[i]}.
* @return A {@link Bytes32} that holds securely the bytes of {@code value} from {@code offset}
* (inclusive) to {@code offset + 32} (exclusive).
* @throws IndexOutOfBoundsException if {@code offset < 0 || (value.length > 0 && offset >=
* value.length)}.
* @throws IllegalArgumentException if {@code length < 0 || offset + 32 > value.length}.
Expand All @@ -99,9 +95,8 @@ static Bytes32 secure(byte[] bytes, int offset) {
/**
* Wrap a the provided value, which must be of size 32, as a {@link Bytes32}.
*
* <p>
* Note that value is not copied, only wrapped, and thus any future update to {@code value} will be reflected in the
* returned value.
* <p>Note that value is not copied, only wrapped, and thus any future update to {@code value}
* will be reflected in the returned value.
*
* @param value The bytes to wrap.
* @return A {@link Bytes32} that exposes the bytes of {@code value}.
Expand All @@ -119,15 +114,14 @@ static Bytes32 wrap(Bytes value) {
/**
* Wrap a slice/sub-part of the provided value as a {@link Bytes32}.
*
* <p>
* Note that value is not copied, only wrapped, and thus any future update to {@code value} within the wrapped parts
* will be reflected in the returned value.
* <p>Note that value is not copied, only wrapped, and thus any future update to {@code value}
* within the wrapped parts will be reflected in the returned value.
*
* @param value The bytes to wrap.
* @param offset The index (inclusive) in {@code value} of the first byte exposed by the returned value. In other
* words, you will have {@code wrap(value, i).get(0) == value.get(i)}.
* @return A {@link Bytes32} that exposes the bytes of {@code value} from {@code offset} (inclusive) to
* {@code offset + 32} (exclusive).
* @param offset The index (inclusive) in {@code value} of the first byte exposed by the returned
* value. In other words, you will have {@code wrap(value, i).get(0) == value.get(i)}.
* @return A {@link Bytes32} that exposes the bytes of {@code value} from {@code offset}
* (inclusive) to {@code offset + 32} (exclusive).
* @throws IndexOutOfBoundsException if {@code offset < 0 || (value.size() > 0 && offset >=
* value.size())}.
* @throws IllegalArgumentException if {@code length < 0 || offset + 32 > value.size()}.
Expand Down Expand Up @@ -200,16 +194,15 @@ static Bytes32 rightPad(Bytes value) {
/**
* Parse a hexadecimal string into a {@link Bytes32}.
*
* <p>
* This method is lenient in that {@code str} may of an odd length, in which case it will behave exactly as if it had
* an additional 0 in front.
* <p>This method is lenient in that {@code str} may of an odd length, in which case it will
* behave exactly as if it had an additional 0 in front.
*
* @param str The hexadecimal string to parse, which may or may not start with "0x". That representation may contain
* less than 32 bytes, in which case the result is left padded with zeros (see {@link #fromHexStringStrict} if
* this is not what you want).
* @param str The hexadecimal string to parse, which may or may not start with "0x". That
* representation may contain less than 32 bytes, in which case the result is left padded with
* zeros (see {@link #fromHexStringStrict} if this is not what you want).
* @return The value corresponding to {@code str}.
* @throws IllegalArgumentException if {@code str} does not correspond to a valid hexadecimal representation or
* contains more than 32 bytes.
* @throws IllegalArgumentException if {@code str} does not correspond to a valid hexadecimal
* representation or contains more than 32 bytes.
*/
static Bytes32 fromHexStringLenient(CharSequence str) {
checkNotNull(str);
Expand All @@ -219,15 +212,14 @@ static Bytes32 fromHexStringLenient(CharSequence str) {
/**
* Parse a hexadecimal string into a {@link Bytes32}.
*
* <p>
* This method is strict in that {@code str} must of an even length.
* <p>This method is strict in that {@code str} must of an even length.
*
* @param str The hexadecimal string to parse, which may or may not start with "0x". That representation may contain
* less than 32 bytes, in which case the result is left padded with zeros (see {@link #fromHexStringStrict} if
* this is not what you want).
* @param str The hexadecimal string to parse, which may or may not start with "0x". That
* representation may contain less than 32 bytes, in which case the result is left padded with
* zeros (see {@link #fromHexStringStrict} if this is not what you want).
* @return The value corresponding to {@code str}.
* @throws IllegalArgumentException if {@code str} does not correspond to a valid hexadecimal representation, is of an
* odd length, or contains more than 32 bytes.
* @throws IllegalArgumentException if {@code str} does not correspond to a valid hexadecimal
* representation, is of an odd length, or contains more than 32 bytes.
*/
static Bytes32 fromHexString(CharSequence str) {
checkNotNull(str);
Expand Down Expand Up @@ -258,14 +250,13 @@ static Bytes32 random(Random generator) {
/**
* Parse a hexadecimal string into a {@link Bytes32}.
*
* <p>
* This method is extra strict in that {@code str} must of an even length and the provided representation must have
* exactly 32 bytes.
* <p>This method is extra strict in that {@code str} must of an even length and the provided
* representation must have exactly 32 bytes.
*
* @param str The hexadecimal string to parse, which may or may not start with "0x".
* @return The value corresponding to {@code str}.
* @throws IllegalArgumentException if {@code str} does not correspond to a valid hexadecimal representation, is of an
* odd length or does not contain exactly 32 bytes.
* @throws IllegalArgumentException if {@code str} does not correspond to a valid hexadecimal
* representation, is of an odd length or does not contain exactly 32 bytes.
*/
static Bytes32 fromHexStringStrict(CharSequence str) {
checkNotNull(str);
Expand Down
Loading
Loading