Remove some low-hanging Guava from core/main (#1048)

This commit is contained in:
Andrzej Cichocki 2017-07-31 13:27:48 +01:00 committed by GitHub
parent 36b50aab2d
commit 92a056f869
9 changed files with 29 additions and 23 deletions

View File

@ -1,9 +1,9 @@
package net.corda.core.concurrent package net.corda.core.concurrent
import com.google.common.annotations.VisibleForTesting
import com.google.common.util.concurrent.ListenableFuture import com.google.common.util.concurrent.ListenableFuture
import com.google.common.util.concurrent.SettableFuture import com.google.common.util.concurrent.SettableFuture
import net.corda.core.catch import net.corda.core.catch
import net.corda.core.internal.VisibleForTesting
import net.corda.core.match import net.corda.core.match
import net.corda.core.then import net.corda.core.then
import org.slf4j.Logger import org.slf4j.Logger

View File

@ -1,6 +1,6 @@
package net.corda.core.contracts package net.corda.core.contracts
import com.google.common.annotations.VisibleForTesting import net.corda.core.internal.VisibleForTesting
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import java.util.* import java.util.*

View File

@ -1,8 +1,9 @@
package net.corda.core.crypto package net.corda.core.crypto
import com.google.common.io.BaseEncoding
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.parseAsHex
import net.corda.core.utilities.toHexString
import java.security.MessageDigest import java.security.MessageDigest
/** /**
@ -18,7 +19,7 @@ sealed class SecureHash(bytes: ByteArray) : OpaqueBytes(bytes) {
} }
} }
override fun toString(): String = BaseEncoding.base16().encode(bytes) override fun toString(): String = bytes.toHexString()
fun prefixChars(prefixLen: Int = 6) = toString().substring(0, prefixLen) fun prefixChars(prefixLen: Int = 6) = toString().substring(0, prefixLen)
fun hashConcat(other: SecureHash) = (this.bytes + other.bytes).sha256() fun hashConcat(other: SecureHash) = (this.bytes + other.bytes).sha256()
@ -26,7 +27,7 @@ sealed class SecureHash(bytes: ByteArray) : OpaqueBytes(bytes) {
// Like static methods in Java, except the 'companion' is a singleton that can have state. // Like static methods in Java, except the 'companion' is a singleton that can have state.
companion object { companion object {
@JvmStatic @JvmStatic
fun parse(str: String) = BaseEncoding.base16().decode(str.toUpperCase()).let { fun parse(str: String) = str.toUpperCase().parseAsHex().let {
when (it.size) { when (it.size) {
32 -> SHA256(it) 32 -> SHA256(it)
else -> throw IllegalArgumentException("Provided string is ${it.size} bytes not 32 bytes in hex: $str") else -> throw IllegalArgumentException("Provided string is ${it.size} bytes not 32 bytes in hex: $str")

View File

@ -1,6 +1,5 @@
package net.corda.core.internal package net.corda.core.internal
import com.google.common.base.Throwables
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.sha256 import net.corda.core.crypto.sha256
import org.slf4j.Logger import org.slf4j.Logger
@ -8,10 +7,7 @@ import rx.Observable
import rx.Observer import rx.Observer
import rx.subjects.PublishSubject import rx.subjects.PublishSubject
import rx.subjects.UnicastSubject import rx.subjects.UnicastSubject
import java.io.ByteArrayInputStream import java.io.*
import java.io.ByteArrayOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.lang.reflect.Field import java.lang.reflect.Field
import java.math.BigDecimal import java.math.BigDecimal
import java.nio.charset.Charset import java.nio.charset.Charset
@ -30,7 +26,8 @@ import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream import java.util.zip.ZipOutputStream
import kotlin.reflect.KClass import kotlin.reflect.KClass
inline val Throwable.rootCause: Throwable get() = Throwables.getRootCause(this) val Throwable.rootCause: Throwable get() = cause?.rootCause ?: this
fun Throwable.getStackTraceAsString() = StringWriter().also { printStackTrace(PrintWriter(it)) }.toString()
infix fun Temporal.until(endExclusive: Temporal): Duration = Duration.between(this, endExclusive) infix fun Temporal.until(endExclusive: Temporal): Duration = Duration.between(this, endExclusive)
@ -249,3 +246,13 @@ class DeclaredField<T>(clazz: Class<*>, name: String, private val receiver: Any?
get() = javaField.get(receiver) as T get() = javaField.get(receiver) as T
set(value) = javaField.set(receiver, value) set(value) = javaField.set(receiver, value)
} }
/** The annotated object would have a more restricted visibility were it not needed in tests. */
@Target(AnnotationTarget.CLASS,
AnnotationTarget.PROPERTY,
AnnotationTarget.CONSTRUCTOR,
AnnotationTarget.FUNCTION,
AnnotationTarget.TYPEALIAS)
@Retention(AnnotationRetention.SOURCE)
@MustBeDocumented
annotation class VisibleForTesting

View File

@ -1,6 +1,5 @@
package net.corda.core.node package net.corda.core.node
import com.google.common.collect.Lists
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.crypto.DigitalSignature import net.corda.core.crypto.DigitalSignature
import net.corda.core.node.services.* import net.corda.core.node.services.*
@ -76,7 +75,7 @@ interface ServiceHub : ServicesForResolution {
* further processing. This is expected to be run within a database transaction. * further processing. This is expected to be run within a database transaction.
*/ */
fun recordTransactions(first: SignedTransaction, vararg remaining: SignedTransaction) { fun recordTransactions(first: SignedTransaction, vararg remaining: SignedTransaction) {
recordTransactions(Lists.asList(first, remaining)) recordTransactions(listOf(first, *remaining))
} }
/** /**

View File

@ -4,11 +4,11 @@ import com.esotericsoftware.kryo.*
import com.esotericsoftware.kryo.io.Input import com.esotericsoftware.kryo.io.Input
import com.esotericsoftware.kryo.io.Output import com.esotericsoftware.kryo.io.Output
import com.esotericsoftware.kryo.util.MapReferenceResolver import com.esotericsoftware.kryo.util.MapReferenceResolver
import com.google.common.annotations.VisibleForTesting
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.crypto.* import net.corda.core.crypto.*
import net.corda.core.crypto.composite.CompositeKey import net.corda.core.crypto.composite.CompositeKey
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.internal.VisibleForTesting
import net.corda.core.transactions.CoreTransaction import net.corda.core.transactions.CoreTransaction
import net.corda.core.transactions.NotaryChangeWireTransaction import net.corda.core.transactions.NotaryChangeWireTransaction
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction

View File

@ -1,6 +1,6 @@
package net.corda.core.serialization.amqp package net.corda.core.serialization.amqp
import com.google.common.base.Throwables import net.corda.core.internal.getStackTraceAsString
import net.corda.core.serialization.SerializedBytes import net.corda.core.serialization.SerializedBytes
import org.apache.qpid.proton.amqp.Binary import org.apache.qpid.proton.amqp.Binary
import org.apache.qpid.proton.amqp.DescribedType import org.apache.qpid.proton.amqp.DescribedType
@ -92,7 +92,7 @@ class DeserializationInput(internal val serializerFactory: SerializerFactory = S
} catch(nse: NotSerializableException) { } catch(nse: NotSerializableException) {
throw nse throw nse
} catch(t: Throwable) { } catch(t: Throwable) {
throw NotSerializableException("Unexpected throwable: ${t.message} ${Throwables.getStackTraceAsString(t)}") throw NotSerializableException("Unexpected throwable: ${t.message} ${t.getStackTraceAsString()}")
} finally { } finally {
objectHistory.clear() objectHistory.clear()
} }

View File

@ -2,9 +2,9 @@
package net.corda.core.utilities package net.corda.core.utilities
import com.google.common.io.BaseEncoding
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import java.io.ByteArrayInputStream import java.io.ByteArrayInputStream
import javax.xml.bind.DatatypeConverter
/** /**
* An abstraction of a byte array, with offset and size that does no copying of bytes unless asked to. * An abstraction of a byte array, with offset and size that does no copying of bytes unless asked to.
@ -109,7 +109,7 @@ sealed class ByteSequence : Comparable<ByteSequence> {
return result return result
} }
override fun toString(): String = "[${BaseEncoding.base16().encode(bytes, offset, size)}]" override fun toString(): String = "[${bytes.copyOfRange(offset, offset + size).toHexString()}]"
} }
/** /**
@ -136,12 +136,12 @@ fun ByteArray.opaque(): OpaqueBytes = OpaqueBytes(this)
fun ByteArray.sequence(offset: Int = 0, size: Int = this.size) = ByteSequence.of(this, offset, size) fun ByteArray.sequence(offset: Int = 0, size: Int = this.size) = ByteSequence.of(this, offset, size)
fun ByteArray.toHexString(): String = BaseEncoding.base16().encode(this) fun ByteArray.toHexString(): String = DatatypeConverter.printHexBinary(this)
fun String.parseAsHex(): ByteArray = BaseEncoding.base16().decode(this) fun String.parseAsHex(): ByteArray = DatatypeConverter.parseHexBinary(this)
private class OpaqueBytesSubSequence(override val bytes: ByteArray, override val offset: Int, override val size: Int) : ByteSequence() { private class OpaqueBytesSubSequence(override val bytes: ByteArray, override val offset: Int, override val size: Int) : ByteSequence() {
init { init {
require(offset >= 0 && offset < bytes.size) require(offset >= 0 && offset < bytes.size)
require(size >= 0 && size <= bytes.size) require(size >= 0 && size <= bytes.size)
} }
} }

View File

@ -1,6 +1,5 @@
package net.corda.core.utilities package net.corda.core.utilities
import com.google.common.collect.Iterators
import java.util.* import java.util.*
import java.util.function.Consumer import java.util.function.Consumer
import java.util.stream.Stream import java.util.stream.Stream
@ -50,7 +49,7 @@ class NonEmptySet<T> private constructor(private val elements: Set<T>) : Set<T>
/** Returns the first element of the set. */ /** Returns the first element of the set. */
fun head(): T = elements.iterator().next() fun head(): T = elements.iterator().next()
override fun isEmpty(): Boolean = false override fun isEmpty(): Boolean = false
override fun iterator(): Iterator<T> = Iterators.unmodifiableIterator(elements.iterator()) override fun iterator() = object : Iterator<T> by elements.iterator() {}
// Following methods are not delegated by Kotlin's Class delegation // Following methods are not delegated by Kotlin's Class delegation
override fun forEach(action: Consumer<in T>) = elements.forEach(action) override fun forEach(action: Consumer<in T>) = elements.forEach(action)