From b1317e5e62bb044cd8a676cb3fc2da86e9922caf Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 28 Jul 2016 16:36:17 -0400 Subject: Added debugging aid for finding single instantiation violations. Also, fixed a single instantiation violation into BoundLazyPair --- .../main/java/bjc/utils/data/BoundLazyPair.java | 33 +++++++++++----------- .../main/java/bjc/utils/data/SingleSupplier.java | 20 +++++++++++-- 2 files changed, 34 insertions(+), 19 deletions(-) (limited to 'BJC-Utils2/src/main') diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java index dcf9cca..2b20349 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/BoundLazyPair.java @@ -26,8 +26,8 @@ class BoundLazyPair @Override public IPair bind( BiFunction> bindr) { - IHolder> newPair = - new Identity<>(boundPair); + IHolder> newPair = new Identity<>( + boundPair); IHolder newPairMade = new Identity<>(pairBound); Supplier leftSupp = () -> { @@ -35,7 +35,7 @@ class BoundLazyPair newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get())); - newPairMade.replace(false); + newPairMade.replace(true); } return newPair.unwrap((pair) -> pair.getLeft()); @@ -46,7 +46,7 @@ class BoundLazyPair newPair.replace(binder.apply(leftSupplier.get(), rightSupplier.get())); - newPairMade.replace(false); + newPairMade.replace(true); } return newPair.unwrap((pair) -> pair.getRight()); @@ -90,11 +90,11 @@ class BoundLazyPair } @Override - public MergedType - merge(BiFunction merger) { + public MergedType merge( + BiFunction merger) { if (!pairBound) { - boundPair = - binder.apply(leftSupplier.get(), rightSupplier.get()); + boundPair = binder.apply(leftSupplier.get(), + rightSupplier.get()); pairBound = true; } @@ -112,8 +112,8 @@ class BoundLazyPair } @Override - public IPair - mapLeft(Function mapper) { + public IPair mapLeft( + Function mapper) { Supplier leftSupp = () -> { if (!pairBound) { NewLeft leftVal = binder @@ -140,8 +140,8 @@ class BoundLazyPair } @Override - public IPair - mapRight(Function mapper) { + public IPair mapRight( + Function mapper) { Supplier leftSupp = () -> { if (!pairBound) { return binder @@ -168,11 +168,10 @@ class BoundLazyPair } @Override - public - IPair - combine(IPair otherPair, - BiFunction leftCombiner, - BiFunction rightCombiner) { + public IPair combine( + IPair otherPair, + BiFunction leftCombiner, + BiFunction rightCombiner) { return otherPair.bind((otherLeft, otherRight) -> { return bind((leftVal, rightVal) -> { return new LazyPair<>( diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java b/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java index 016f492..989f1a5 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java @@ -9,6 +9,10 @@ public class SingleSupplier implements Supplier { private long id; + // This is bad practice, but I want to know where the single + // instantiation was, in case of duplicate initiations + private Exception instSite; + private static long nextID = 0; public SingleSupplier(Supplier supp) { @@ -22,13 +26,25 @@ public class SingleSupplier implements Supplier { @Override public T get() { if (gotten == true) { - throw new IllegalStateException( + IllegalStateException isex = new IllegalStateException( "Attempted to get value more than once" - + " from single supplier #" + id); + + " from single supplier #" + id + + ". Previous instantiation below."); + + isex.initCause(instSite); + + throw isex; } gotten = true; + try { + throw new IllegalStateException( + "Previous instantiation here."); + } catch (IllegalStateException isex) { + instSite = isex; + } + return source.get(); } } -- cgit v1.2.3