Remove the copy of Guava from within the finance module. (#1362)

This commit is contained in:
Chris Rankin 2017-08-31 14:40:32 +01:00 committed by GitHub
parent 1139c1abf5
commit 03ddaaac11
3 changed files with 17 additions and 9 deletions

View File

@ -26,6 +26,8 @@ dependencies {
// ObjectWeb Asm: a library for synthesising and working with JVM bytecode. // ObjectWeb Asm: a library for synthesising and working with JVM bytecode.
compile "org.ow2.asm:asm:5.0.4" compile "org.ow2.asm:asm:5.0.4"
compile "com.google.guava:guava:$guava_version"
testCompile "junit:junit:$junit_version" testCompile "junit:junit:$junit_version"
testCompile project(':test-utils') testCompile project(':test-utils')
} }

View File

@ -15,8 +15,6 @@ dependencies {
// and CorDapps using :finance features should use 'cordapp' not 'compile' linkage. // and CorDapps using :finance features should use 'cordapp' not 'compile' linkage.
cordaCompile project(':core') cordaCompile project(':core')
compile "com.google.guava:guava:$guava_version"
testCompile project(':test-utils') testCompile project(':test-utils')
testCompile project(path: ':core', configuration: 'testArtifacts') testCompile project(path: ':core', configuration: 'testArtifacts')
testCompile "junit:junit:$junit_version" testCompile "junit:junit:$junit_version"

View File

@ -1,8 +1,6 @@
package net.corda.finance.contracts; package net.corda.finance.contracts;
import co.paralleluniverse.fibers.Suspendable; import co.paralleluniverse.fibers.Suspendable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import kotlin.Unit; import kotlin.Unit;
import net.corda.core.contracts.*; import net.corda.core.contracts.*;
import net.corda.core.crypto.testing.NullPublicKey; import net.corda.core.crypto.testing.NullPublicKey;
@ -20,6 +18,7 @@ import org.jetbrains.annotations.Nullable;
import java.time.Instant; import java.time.Instant;
import java.util.Collections; import java.util.Collections;
import java.util.Currency; import java.util.Currency;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -128,7 +127,7 @@ public class JavaCommercialPaper implements Contract {
@NotNull @NotNull
@Override @Override
public List<AbstractParty> getParticipants() { public List<AbstractParty> getParticipants() {
return ImmutableList.of(this.owner); return Collections.singletonList(this.owner);
} }
} }
@ -175,7 +174,7 @@ public class JavaCommercialPaper implements Contract {
final List<AuthenticatedObject<CommandData>> commands = tx.getCommands().stream().filter( final List<AuthenticatedObject<CommandData>> commands = tx.getCommands().stream().filter(
it -> it.getValue() instanceof Commands it -> it.getValue() instanceof Commands
).collect(Collectors.toList()); ).collect(Collectors.toList());
final AuthenticatedObject<CommandData> command = Iterables.getOnlyElement(commands); final AuthenticatedObject<CommandData> command = onlyElementOf(commands);
final TimeWindow timeWindow = tx.getTimeWindow(); final TimeWindow timeWindow = tx.getTimeWindow();
for (final LedgerTransaction.InOutGroup<State, State> group : groups) { for (final LedgerTransaction.InOutGroup<State, State> group : groups) {
@ -184,7 +183,7 @@ public class JavaCommercialPaper implements Contract {
if (command.getValue() instanceof Commands.Move) { if (command.getValue() instanceof Commands.Move) {
final AuthenticatedObject<Commands.Move> cmd = requireSingleCommand(tx.getCommands(), Commands.Move.class); final AuthenticatedObject<Commands.Move> cmd = requireSingleCommand(tx.getCommands(), Commands.Move.class);
// There should be only a single input due to aggregation above // There should be only a single input due to aggregation above
final State input = Iterables.getOnlyElement(inputs); final State input = onlyElementOf(inputs);
if (!cmd.getSigners().contains(input.getOwner().getOwningKey())) if (!cmd.getSigners().contains(input.getOwner().getOwningKey()))
throw new IllegalStateException("Failed requirement: the transaction is signed by the owner of the CP"); throw new IllegalStateException("Failed requirement: the transaction is signed by the owner of the CP");
@ -197,7 +196,7 @@ public class JavaCommercialPaper implements Contract {
final AuthenticatedObject<Commands.Redeem> cmd = requireSingleCommand(tx.getCommands(), Commands.Redeem.class); final AuthenticatedObject<Commands.Redeem> cmd = requireSingleCommand(tx.getCommands(), Commands.Redeem.class);
// There should be only a single input due to aggregation above // There should be only a single input due to aggregation above
final State input = Iterables.getOnlyElement(inputs); final State input = onlyElementOf(inputs);
if (!cmd.getSigners().contains(input.getOwner().getOwningKey())) if (!cmd.getSigners().contains(input.getOwner().getOwningKey()))
throw new IllegalStateException("Failed requirement: the transaction is signed by the owner of the CP"); throw new IllegalStateException("Failed requirement: the transaction is signed by the owner of the CP");
@ -218,7 +217,7 @@ public class JavaCommercialPaper implements Contract {
}); });
} else if (command.getValue() instanceof Commands.Issue) { } else if (command.getValue() instanceof Commands.Issue) {
final AuthenticatedObject<Commands.Issue> cmd = requireSingleCommand(tx.getCommands(), Commands.Issue.class); final AuthenticatedObject<Commands.Issue> cmd = requireSingleCommand(tx.getCommands(), Commands.Issue.class);
final State output = Iterables.getOnlyElement(outputs); final State output = onlyElementOf(outputs);
final Instant time = null == timeWindow final Instant time = null == timeWindow
? null ? null
: timeWindow.getUntilTime(); : timeWindow.getUntilTime();
@ -257,4 +256,13 @@ public class JavaCommercialPaper implements Contract {
tx.addOutputState(new TransactionState<>(new State(paper.getState().getData().getIssuance(), newOwner, paper.getState().getData().getFaceValue(), paper.getState().getData().getMaturityDate()), paper.getState().getNotary(), paper.getState().getEncumbrance())); tx.addOutputState(new TransactionState<>(new State(paper.getState().getData().getIssuance(), newOwner, paper.getState().getData().getFaceValue(), paper.getState().getData().getMaturityDate()), paper.getState().getNotary(), paper.getState().getEncumbrance()));
tx.addCommand(new Command<>(new Commands.Move(), paper.getState().getData().getOwner().getOwningKey())); tx.addCommand(new Command<>(new Commands.Move(), paper.getState().getData().getOwner().getOwningKey()));
} }
private static <T> T onlyElementOf(Iterable<T> iterable) {
Iterator<T> iter = iterable.iterator();
T item = iter.next();
if (iter.hasNext()) {
throw new IllegalArgumentException("Iterable has more than one element!");
}
return item;
}
} }