aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/gregtech/api/objects
diff options
context:
space:
mode:
authorDraknyte1 <Draknyte1@hotmail.com>2017-03-04 12:58:47 +1000
committerDraknyte1 <Draknyte1@hotmail.com>2017-03-04 12:58:47 +1000
commitae21012d216df71f31aed6fbc9d76215fc24ceed (patch)
treecc89accbe6ce5c04b72ed3c5e46b2a185f88be6a /src/Java/gtPlusPlus/xmod/gregtech/api/objects
parentba89972a22a316030f8c3bd99974f915b1d7aefc (diff)
downloadGT5-Unofficial-ae21012d216df71f31aed6fbc9d76215fc24ceed.tar.gz
GT5-Unofficial-ae21012d216df71f31aed6fbc9d76215fc24ceed.tar.bz2
GT5-Unofficial-ae21012d216df71f31aed6fbc9d76215fc24ceed.zip
+ New texture for the slow builders ring.
+ Added the Alkalus Disk. $ Fixed Frame Box Assembler Recipes. $ Fixed Missing 7Li material. $ Fixed Tiered Tanks not showing their capacity in the tooltip. $ Fixed tooltips for alloys containing Bronze or Steel. $ Fixed Clay Pipe Extruder Recipes. - Removed a handful of Plasma cells for misc. materials. % Changed the Industrial Coke Oven's tooltip, to better describe the input/output requirements. % Cleaned up The Entire Project.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/api/objects')
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechFluid.java32
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechItemData.java250
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechMaterialStack.java79
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/objects/XSTR.java387
4 files changed, 386 insertions, 362 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechFluid.java b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechFluid.java
index 56a48602c9..6c229b5055 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechFluid.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechFluid.java
@@ -5,23 +5,23 @@ import gtPlusPlus.core.lib.CORE;
import net.minecraftforge.fluids.Fluid;
public class GregtechFluid extends Fluid implements Runnable {
- public final String mTextureName;
- private final short[] mRGBa;
+ public final String mTextureName;
+ private final short[] mRGBa;
- public GregtechFluid(String aName, String aTextureName, short[] aRGBa) {
- super(aName);
- mRGBa = aRGBa;
- mTextureName = aTextureName;
- GregTech_API.sGTBlockIconload.add(this);
- }
+ public GregtechFluid(final String aName, final String aTextureName, final short[] aRGBa) {
+ super(aName);
+ this.mRGBa = aRGBa;
+ this.mTextureName = aTextureName;
+ GregTech_API.sGTBlockIconload.add(this);
+ }
- @Override
- public int getColor() {
- return (Math.max(0, Math.min(255, mRGBa[0])) << 16) | (Math.max(0, Math.min(255, mRGBa[1])) << 8) | Math.max(0, Math.min(255, mRGBa[2]));
- }
+ @Override
+ public int getColor() {
+ return (Math.max(0, Math.min(255, this.mRGBa[0])) << 16) | (Math.max(0, Math.min(255, this.mRGBa[1])) << 8) | Math.max(0, Math.min(255, this.mRGBa[2]));
+ }
- @Override
- public void run() {
- setIcons(GregTech_API.sBlockIcons.registerIcon(CORE.MODID+ ":" + "fluids/fluid." + mTextureName));
- }
+ @Override
+ public void run() {
+ this.setIcons(GregTech_API.sBlockIcons.registerIcon(CORE.MODID+ ":" + "fluids/fluid." + this.mTextureName));
+ }
} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechItemData.java b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechItemData.java
index f5a1a2d04f..0a5351afdc 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechItemData.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechItemData.java
@@ -1,126 +1,142 @@
package gtPlusPlus.xmod.gregtech.api.objects;
+import java.util.*;
+
import gregtech.api.objects.GT_ArrayList;
import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes;
import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials;
-
-import java.util.*;
-
import net.minecraft.item.ItemStack;
public class GregtechItemData {
- private static final GregtechMaterialStack[] EMPTY_GT_MaterialStack_ARRAY = new GregtechMaterialStack[0];
-
- public final List<Object> mExtraData = new GT_ArrayList<Object>(false, 1);
- public final GregtechOrePrefixes mPrefix;
- public final GregtechMaterialStack mMaterial;
- public final GregtechMaterialStack[] mByProducts;
- public boolean mBlackListed = false;
- public ItemStack mUnificationTarget = null;
-
- public GregtechItemData(GregtechOrePrefixes aPrefix, GT_Materials aMaterial, boolean aBlackListed) {
- mPrefix = aPrefix;
- mMaterial = aMaterial == null ? null : new GregtechMaterialStack(aMaterial, aPrefix.mMaterialAmount);
- mBlackListed = aBlackListed;
- mByProducts = aPrefix.mSecondaryMaterial == null || aPrefix.mSecondaryMaterial.mMaterial == null ? EMPTY_GT_MaterialStack_ARRAY : new GregtechMaterialStack[]{aPrefix.mSecondaryMaterial.clone()};
- }
-
- public GregtechItemData(GregtechOrePrefixes aPrefix, GT_Materials aMaterial) {
- this(aPrefix, aMaterial, false);
- }
-
- public GregtechItemData(GregtechMaterialStack aMaterial, GregtechMaterialStack... aByProducts) {
- mPrefix = null;
- mMaterial = aMaterial.mMaterial == null ? null : aMaterial.clone();
- mBlackListed = true;
- if (aByProducts == null) {
- mByProducts = EMPTY_GT_MaterialStack_ARRAY;
- } else {
- GregtechMaterialStack[] tByProducts = aByProducts.length < 1 ? EMPTY_GT_MaterialStack_ARRAY : new GregtechMaterialStack[aByProducts.length];
- int j = 0;
- for (int i = 0; i < aByProducts.length; i++)
- if (aByProducts[i] != null && aByProducts[i].mMaterial != null)
- tByProducts[j++] = aByProducts[i].clone();
- mByProducts = j > 0 ? new GregtechMaterialStack[j] : EMPTY_GT_MaterialStack_ARRAY;
- for (int i = 0; i < mByProducts.length; i++) mByProducts[i] = tByProducts[i];
- }
- }
-
- public GregtechItemData(GT_Materials aMaterial, long aAmount, GregtechMaterialStack... aByProducts) {
- this(new GregtechMaterialStack(aMaterial, aAmount), aByProducts);
- }
-
- public GregtechItemData(GT_Materials aMaterial, long aAmount, GT_Materials aByProduct, long aByProductAmount) {
- this(new GregtechMaterialStack(aMaterial, aAmount), new GregtechMaterialStack(aByProduct, aByProductAmount));
- }
-
- public GregtechItemData(GregtechItemData... aData) {
- mPrefix = null;
- mBlackListed = true;
-
- ArrayList<GregtechMaterialStack> aList = new ArrayList<GregtechMaterialStack>(), rList = new ArrayList<GregtechMaterialStack>();
-
- for (GregtechItemData tData : aData)
- if (tData != null) {
- if (tData.hasValidMaterialData() && tData.mMaterial.mAmount > 0) aList.add(tData.mMaterial.clone());
- for (GregtechMaterialStack tMaterial : tData.mByProducts)
- if (tMaterial.mAmount > 0) aList.add(tMaterial.clone());
- }
-
- for (GregtechMaterialStack aMaterial : aList) {
- boolean temp = true;
- for (GregtechMaterialStack tMaterial : rList)
- if (aMaterial.mMaterial == tMaterial.mMaterial) {
- tMaterial.mAmount += aMaterial.mAmount;
- temp = false;
- break;
- }
- if (temp) rList.add(aMaterial.clone());
- }
-
- Collections.sort(rList, new Comparator<GregtechMaterialStack>() {
- @Override
- public int compare(GregtechMaterialStack a, GregtechMaterialStack b) {
- return a.mAmount == b.mAmount ? 0 : a.mAmount > b.mAmount ? -1 : +1;
- }
- });
-
- if (rList.isEmpty()) {
- mMaterial = null;
- } else {
- mMaterial = rList.get(0);
- rList.remove(0);
- }
-
- mByProducts = rList.toArray(new GregtechMaterialStack[rList.size()]);
- }
-
- public boolean hasValidPrefixMaterialData() {
- return mPrefix != null && mMaterial != null && mMaterial.mMaterial != null;
- }
-
- public boolean hasValidPrefixData() {
- return mPrefix != null;
- }
-
- public boolean hasValidMaterialData() {
- return mMaterial != null && mMaterial.mMaterial != null;
- }
-
- public ArrayList<GregtechMaterialStack> getAllGT_MaterialStacks() {
- ArrayList<GregtechMaterialStack> rList = new ArrayList();
- if (hasValidMaterialData()) rList.add(mMaterial);
- rList.addAll(Arrays.asList(mByProducts));
- return rList;
- }
-
- public GregtechMaterialStack getByProduct(int aIndex) {
- return aIndex >= 0 && aIndex < mByProducts.length ? mByProducts[aIndex] : null;
- }
-
- @Override
- public String toString() {
- if (mPrefix == null || mMaterial == null || mMaterial.mMaterial == null) return "";
- return mPrefix.name() + mMaterial.mMaterial.name();
- }
+ private static final GregtechMaterialStack[] EMPTY_GT_MaterialStack_ARRAY = new GregtechMaterialStack[0];
+
+ public final List<Object> mExtraData = new GT_ArrayList<>(false, 1);
+ public final GregtechOrePrefixes mPrefix;
+ public final GregtechMaterialStack mMaterial;
+ public final GregtechMaterialStack[] mByProducts;
+ public boolean mBlackListed = false;
+ public ItemStack mUnificationTarget = null;
+
+ public GregtechItemData(final GregtechOrePrefixes aPrefix, final GT_Materials aMaterial, final boolean aBlackListed) {
+ this.mPrefix = aPrefix;
+ this.mMaterial = aMaterial == null ? null : new GregtechMaterialStack(aMaterial, aPrefix.mMaterialAmount);
+ this.mBlackListed = aBlackListed;
+ this.mByProducts = (aPrefix.mSecondaryMaterial == null) || (aPrefix.mSecondaryMaterial.mMaterial == null) ? EMPTY_GT_MaterialStack_ARRAY : new GregtechMaterialStack[]{aPrefix.mSecondaryMaterial.clone()};
+ }
+
+ public GregtechItemData(final GregtechOrePrefixes aPrefix, final GT_Materials aMaterial) {
+ this(aPrefix, aMaterial, false);
+ }
+
+ public GregtechItemData(final GregtechMaterialStack aMaterial, final GregtechMaterialStack... aByProducts) {
+ this.mPrefix = null;
+ this.mMaterial = aMaterial.mMaterial == null ? null : aMaterial.clone();
+ this.mBlackListed = true;
+ if (aByProducts == null) {
+ this.mByProducts = EMPTY_GT_MaterialStack_ARRAY;
+ } else {
+ final GregtechMaterialStack[] tByProducts = aByProducts.length < 1 ? EMPTY_GT_MaterialStack_ARRAY : new GregtechMaterialStack[aByProducts.length];
+ int j = 0;
+ for (int i = 0; i < aByProducts.length; i++) {
+ if ((aByProducts[i] != null) && (aByProducts[i].mMaterial != null)) {
+ tByProducts[j++] = aByProducts[i].clone();
+ }
+ }
+ this.mByProducts = j > 0 ? new GregtechMaterialStack[j] : EMPTY_GT_MaterialStack_ARRAY;
+ for (int i = 0; i < this.mByProducts.length; i++) {
+ this.mByProducts[i] = tByProducts[i];
+ }
+ }
+ }
+
+ public GregtechItemData(final GT_Materials aMaterial, final long aAmount, final GregtechMaterialStack... aByProducts) {
+ this(new GregtechMaterialStack(aMaterial, aAmount), aByProducts);
+ }
+
+ public GregtechItemData(final GT_Materials aMaterial, final long aAmount, final GT_Materials aByProduct, final long aByProductAmount) {
+ this(new GregtechMaterialStack(aMaterial, aAmount), new GregtechMaterialStack(aByProduct, aByProductAmount));
+ }
+
+ public GregtechItemData(final GregtechItemData... aData) {
+ this.mPrefix = null;
+ this.mBlackListed = true;
+
+ final ArrayList<GregtechMaterialStack> aList = new ArrayList<>(), rList = new ArrayList<>();
+
+ for (final GregtechItemData tData : aData) {
+ if (tData != null) {
+ if (tData.hasValidMaterialData() && (tData.mMaterial.mAmount > 0)) {
+ aList.add(tData.mMaterial.clone());
+ }
+ for (final GregtechMaterialStack tMaterial : tData.mByProducts) {
+ if (tMaterial.mAmount > 0) {
+ aList.add(tMaterial.clone());
+ }
+ }
+ }
+ }
+
+ for (final GregtechMaterialStack aMaterial : aList) {
+ boolean temp = true;
+ for (final GregtechMaterialStack tMaterial : rList) {
+ if (aMaterial.mMaterial == tMaterial.mMaterial) {
+ tMaterial.mAmount += aMaterial.mAmount;
+ temp = false;
+ break;
+ }
+ }
+ if (temp) {
+ rList.add(aMaterial.clone());
+ }
+ }
+
+ Collections.sort(rList, new Comparator<GregtechMaterialStack>() {
+ @Override
+ public int compare(final GregtechMaterialStack a, final GregtechMaterialStack b) {
+ return a.mAmount == b.mAmount ? 0 : a.mAmount > b.mAmount ? -1 : +1;
+ }
+ });
+
+ if (rList.isEmpty()) {
+ this.mMaterial = null;
+ } else {
+ this.mMaterial = rList.get(0);
+ rList.remove(0);
+ }
+
+ this.mByProducts = rList.toArray(new GregtechMaterialStack[rList.size()]);
+ }
+
+ public boolean hasValidPrefixMaterialData() {
+ return (this.mPrefix != null) && (this.mMaterial != null) && (this.mMaterial.mMaterial != null);
+ }
+
+ public boolean hasValidPrefixData() {
+ return this.mPrefix != null;
+ }
+
+ public boolean hasValidMaterialData() {
+ return (this.mMaterial != null) && (this.mMaterial.mMaterial != null);
+ }
+
+ public ArrayList<GregtechMaterialStack> getAllGT_MaterialStacks() {
+ final ArrayList<GregtechMaterialStack> rList = new ArrayList();
+ if (this.hasValidMaterialData()) {
+ rList.add(this.mMaterial);
+ }
+ rList.addAll(Arrays.asList(this.mByProducts));
+ return rList;
+ }
+
+ public GregtechMaterialStack getByProduct(final int aIndex) {
+ return (aIndex >= 0) && (aIndex < this.mByProducts.length) ? this.mByProducts[aIndex] : null;
+ }
+
+ @Override
+ public String toString() {
+ if ((this.mPrefix == null) || (this.mMaterial == null) || (this.mMaterial.mMaterial == null)) {
+ return "";
+ }
+ return this.mPrefix.name() + this.mMaterial.mMaterial.name();
+ }
} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechMaterialStack.java b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechMaterialStack.java
index 245db1745f..6ec5907256 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechMaterialStack.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechMaterialStack.java
@@ -3,40 +3,47 @@ package gtPlusPlus.xmod.gregtech.api.objects;
import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials;
public class GregtechMaterialStack implements Cloneable {
- public long mAmount;
- public GT_Materials mMaterial;
-
- public GregtechMaterialStack(GT_Materials aMaterial, long aAmount) {
- mMaterial = aMaterial == null ? GT_Materials._NULL : aMaterial;
- mAmount = aAmount;
- }
-
- public GregtechMaterialStack copy(long aAmount) {
- return new GregtechMaterialStack(mMaterial, aAmount);
- }
-
- @Override
- public GregtechMaterialStack clone() {
- return new GregtechMaterialStack(mMaterial, mAmount);
- }
-
- @Override
- public boolean equals(Object aObject) {
- if (aObject == this) return true;
- if (aObject == null) return false;
- if (aObject instanceof GT_Materials) return aObject == mMaterial;
- if (aObject instanceof GregtechMaterialStack)
- return ((GregtechMaterialStack) aObject).mMaterial == mMaterial && (mAmount < 0 || ((GregtechMaterialStack) aObject).mAmount < 0 || ((GregtechMaterialStack) aObject).mAmount == mAmount);
- return false;
- }
-
- @Override
- public String toString() {
- return (mMaterial.mMaterialList.size() > 1 && mAmount > 1 ? "(" : "") + mMaterial.getToolTip(true) + (mMaterial.mMaterialList.size() > 1 && mAmount > 1 ? ")" : "") + (mAmount > 1 ? mAmount : "");
- }
-
- @Override
- public int hashCode() {
- return mMaterial.hashCode();
- }
+ public long mAmount;
+ public GT_Materials mMaterial;
+
+ public GregtechMaterialStack(final GT_Materials aMaterial, final long aAmount) {
+ this.mMaterial = aMaterial == null ? GT_Materials._NULL : aMaterial;
+ this.mAmount = aAmount;
+ }
+
+ public GregtechMaterialStack copy(final long aAmount) {
+ return new GregtechMaterialStack(this.mMaterial, aAmount);
+ }
+
+ @Override
+ public GregtechMaterialStack clone() {
+ return new GregtechMaterialStack(this.mMaterial, this.mAmount);
+ }
+
+ @Override
+ public boolean equals(final Object aObject) {
+ if (aObject == this) {
+ return true;
+ }
+ if (aObject == null) {
+ return false;
+ }
+ if (aObject instanceof GT_Materials) {
+ return aObject == this.mMaterial;
+ }
+ if (aObject instanceof GregtechMaterialStack) {
+ return (((GregtechMaterialStack) aObject).mMaterial == this.mMaterial) && ((this.mAmount < 0) || (((GregtechMaterialStack) aObject).mAmount < 0) || (((GregtechMaterialStack) aObject).mAmount == this.mAmount));
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return ((this.mMaterial.mMaterialList.size() > 1) && (this.mAmount > 1) ? "(" : "") + this.mMaterial.getToolTip(true) + ((this.mMaterial.mMaterialList.size() > 1) && (this.mAmount > 1) ? ")" : "") + (this.mAmount > 1 ? this.mAmount : "");
+ }
+
+ @Override
+ public int hashCode() {
+ return this.mMaterial.hashCode();
+ }
} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/XSTR.java b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/XSTR.java
index da3df32d3a..2a7684f20f 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/XSTR.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/XSTR.java
@@ -35,189 +35,189 @@ import java.util.concurrent.atomic.AtomicLong;
*/
public class XSTR extends Random {
- private static final long serialVersionUID = 6208727693524452904L;
- private long seed;
- private long last;
- private static final long GAMMA = 0x9e3779b97f4a7c15L;
- private static final int PROBE_INCREMENT = 0x9e3779b9;
- private static final long SEEDER_INCREMENT = 0xbb67ae8584caa73bL;
- private static final double DOUBLE_UNIT = 0x1.0p-53; // 1.0 / (1L << 53)
- private static final float FLOAT_UNIT = 0x1.0p-24f; // 1.0f / (1 << 24)
+ private static final long serialVersionUID = 6208727693524452904L;
+ private long seed;
+ private long last;
+ private static final long GAMMA = 0x9e3779b97f4a7c15L;
+ private static final int PROBE_INCREMENT = 0x9e3779b9;
+ private static final long SEEDER_INCREMENT = 0xbb67ae8584caa73bL;
+ private static final double DOUBLE_UNIT = 0x1.0p-53; // 1.0 / (1L << 53)
+ private static final float FLOAT_UNIT = 0x1.0p-24f; // 1.0f / (1 << 24)
- /*
+ /*
MODIFIED BY: Robotia
Modification: Implemented Random class seed generator
- */
- /**
- * Creates a new pseudo random number generator. The seed is initialized to
- * the current time, as if by
- * <code>setSeed(System.currentTimeMillis());</code>.
- */
- public XSTR() {
- this(seedUniquifier() ^ System.nanoTime());
- }
- private static final AtomicLong seedUniquifier
- = new AtomicLong(8682522807148012L);
+ */
+ /**
+ * Creates a new pseudo random number generator. The seed is initialized to
+ * the current time, as if by
+ * <code>setSeed(System.currentTimeMillis());</code>.
+ */
+ public XSTR() {
+ this(seedUniquifier() ^ System.nanoTime());
+ }
+ private static final AtomicLong seedUniquifier
+ = new AtomicLong(8682522807148012L);
- private static long seedUniquifier() {
- // L'Ecuyer, "Tables of Linear Congruential Generators of
- // Different Sizes and Good Lattice Structure", 1999
- for (;;) {
- long current = seedUniquifier.get();
- long next = current * 181783497276652981L;
- if (seedUniquifier.compareAndSet(current, next)) {
- return next;
- }
- }
- }
+ private static long seedUniquifier() {
+ // L'Ecuyer, "Tables of Linear Congruential Generators of
+ // Different Sizes and Good Lattice Structure", 1999
+ for (;;) {
+ final long current = seedUniquifier.get();
+ final long next = current * 181783497276652981L;
+ if (seedUniquifier.compareAndSet(current, next)) {
+ return next;
+ }
+ }
+ }
- /**
- * Creates a new pseudo random number generator, starting with the specified
- * seed, using <code>setSeed(seed);</code>.
- *
- * @param seed the initial seed
- */
- public XSTR(long seed) {
- this.seed = seed;
- }
- @Override
+ /**
+ * Creates a new pseudo random number generator, starting with the specified
+ * seed, using <code>setSeed(seed);</code>.
+ *
+ * @param seed the initial seed
+ */
+ public XSTR(final long seed) {
+ this.seed = seed;
+ }
+ @Override
public boolean nextBoolean() {
- return next(1) != 0;
- }
+ return this.next(1) != 0;
+ }
- @Override
+ @Override
public double nextDouble() {
- return (((long)(next(26)) << 27) + next(27)) * DOUBLE_UNIT;
- }
- /**
- * Returns the current state of the seed, can be used to clone the object
- *
- * @return the current seed
- */
- public synchronized long getSeed() {
- return seed;
- }
+ return (((long)(this.next(26)) << 27) + this.next(27)) * DOUBLE_UNIT;
+ }
+ /**
+ * Returns the current state of the seed, can be used to clone the object
+ *
+ * @return the current seed
+ */
+ public synchronized long getSeed() {
+ return this.seed;
+ }
- /**
- * Sets the seed for this pseudo random number generator. As described
- * above, two instances of the same random class, starting with the same
- * seed, produce the same results, if the same methods are called.
- *
- * @param seed the new seed
- */
- @Override
- public synchronized void setSeed(long seed) {
- this.seed = seed;
- }
+ /**
+ * Sets the seed for this pseudo random number generator. As described
+ * above, two instances of the same random class, starting with the same
+ * seed, produce the same results, if the same methods are called.
+ *
+ * @param seed the new seed
+ */
+ @Override
+ public synchronized void setSeed(final long seed) {
+ this.seed = seed;
+ }
- /**
- * @return Returns an XSRandom object with the same state as the original
- */
- @Override
- public XSTR clone() {
- return new XSTR(getSeed());
- }
+ /**
+ * @return Returns an XSRandom object with the same state as the original
+ */
+ @Override
+ public XSTR clone() {
+ return new XSTR(this.getSeed());
+ }
- /**
- * Implementation of George Marsaglia's elegant Xorshift random generator
- * 30% faster and better quality than the built-in java.util.random see also
- * see http://www.javamex.com/tutorials/random_numbers/xorshift.shtml
- *
- * @param nbits
- * @return
- */
- @Override
- public int next(int nbits) {
- long x = seed;
- x ^= (x << 21);
- x ^= (x >>> 35);
- x ^= (x << 4);
- seed = x;
- x &= ((1L << nbits) - 1);
- return (int) x;
- }
- boolean haveNextNextGaussian = false;
- double nextNextGaussian = 0;
- @Override
+ /**
+ * Implementation of George Marsaglia's elegant Xorshift random generator
+ * 30% faster and better quality than the built-in java.util.random see also
+ * see http://www.javamex.com/tutorials/random_numbers/xorshift.shtml
+ *
+ * @param nbits
+ * @return
+ */
+ @Override
+ public int next(final int nbits) {
+ long x = this.seed;
+ x ^= (x << 21);
+ x ^= (x >>> 35);
+ x ^= (x << 4);
+ this.seed = x;
+ x &= ((1L << nbits) - 1);
+ return (int) x;
+ }
+ boolean haveNextNextGaussian = false;
+ double nextNextGaussian = 0;
+ @Override
synchronized public double nextGaussian() {
- // See Knuth, ACP, Section 3.4.1 Algorithm C.
- if (haveNextNextGaussian) {
- haveNextNextGaussian = false;
- return nextNextGaussian;
- }
+ // See Knuth, ACP, Section 3.4.1 Algorithm C.
+ if (this.haveNextNextGaussian) {
+ this.haveNextNextGaussian = false;
+ return this.nextNextGaussian;
+ }
double v1, v2, s;
do {
- v1 = 2 * nextDouble() - 1; // between -1 and 1
- v2 = 2 * nextDouble() - 1; // between -1 and 1
- s = v1 * v1 + v2 * v2;
- } while (s >= 1 || s == 0);
- double multiplier = StrictMath.sqrt(-2 * StrictMath.log(s)/s);
- nextNextGaussian = v2 * multiplier;
- haveNextNextGaussian = true;
+ v1 = (2 * this.nextDouble()) - 1; // between -1 and 1
+ v2 = (2 * this.nextDouble()) - 1; // between -1 and 1
+ s = (v1 * v1) + (v2 * v2);
+ } while ((s >= 1) || (s == 0));
+ final double multiplier = StrictMath.sqrt((-2 * StrictMath.log(s))/s);
+ this.nextNextGaussian = v2 * multiplier;
+ this.haveNextNextGaussian = true;
return v1 * multiplier;
- }
- /**
- * Returns a pseudorandom, uniformly distributed {@code int} value between 0
- * (inclusive) and the specified value (exclusive), drawn from this random
- * number generator's sequence. The general contract of {@code nextInt} is
- * that one {@code int} value in the specified range is pseudorandomly
- * generated and returned. All {@code bound} possible {@code int} values are
- * produced with (approximately) equal probability. The method
- * {@code nextInt(int bound)} is implemented by class {@code Random} as if
- * by:
- * <pre> {@code
- * public int nextInt(int bound) {
- * if (bound <= 0)
- * throw new IllegalArgumentException("bound must be positive");
- *
- * if ((bound & -bound) == bound) // i.e., bound is a power of 2
- * return (int)((bound * (long)next(31)) >> 31);
- *
- * int bits, val;
- * do {
- * bits = next(31);
- * val = bits % bound;
- * } while (bits - val + (bound-1) < 0);
- * return val;
- * }}</pre>
- *
- * <p>The hedge "approx
- * imately" is used in the foregoing description only because the next
- * method is only approximately an unbiased source of independently chosen
- * bits. If it were a perfect source of randomly chosen bits, then the
- * algorithm shown would choose {@code int} values from the stated range
- * with perfect uniformity.
- * <p>
- * The algorithm is slightly tricky. It rejects values that would result in
- * an uneven distribution (due to the fact that 2^31 is not divisible by n).
- * The probability of a value being rejected depends on n. The worst case is
- * n=2^30+1, for which the probability of a reject is 1/2, and the expected
- * number of iterations before the loop terminates is 2.
- * <p>
- * The algorithm treats the case where n is a power of two specially: it
- * returns the correct number of high-order bits from the underlying
- * pseudo-random number generator. In the absence of special treatment, the
- * correct number of <i>low-order</i> bits would be returned. Linear
- * congruential pseudo-random number generators such as the one implemented
- * by this class are known to have short periods in the sequence of values
- * of their low-order bits. Thus, this special case greatly increases the
- * length of the sequence of values returned by successive calls to this
- * method if n is a small power of two.
- *
- * @param bound the upper bound (exclusive). Must be positive.
- * @return the next pseudorandom, uniformly distributed {@code int} value
- * between zero (inclusive) and {@code bound} (exclusive) from this random
- * number generator's sequence
- * @throws IllegalArgumentException if bound is not positive
- * @since 1.2
- */
- @Override
- public int nextInt(int bound) {
- //if (bound <= 0) {
- //throw new RuntimeException("BadBound");
- //}
+ }
+ /**
+ * Returns a pseudorandom, uniformly distributed {@code int} value between 0
+ * (inclusive) and the specified value (exclusive), drawn from this random
+ * number generator's sequence. The general contract of {@code nextInt} is
+ * that one {@code int} value in the specified range is pseudorandomly
+ * generated and returned. All {@code bound} possible {@code int} values are
+ * produced with (approximately) equal probability. The method
+ * {@code nextInt(int bound)} is implemented by class {@code Random} as if
+ * by:
+ * <pre> {@code
+ * public int nextInt(int bound) {
+ * if (bound <= 0)
+ * throw new IllegalArgumentException("bound must be positive");
+ *
+ * if ((bound & -bound) == bound) // i.e., bound is a power of 2
+ * return (int)((bound * (long)next(31)) >> 31);
+ *
+ * int bits, val;
+ * do {
+ * bits = next(31);
+ * val = bits % bound;
+ * } while (bits - val + (bound-1) < 0);
+ * return val;
+ * }}</pre>
+ *
+ * <p>The hedge "approx
+ * imately" is used in the foregoing description only because the next
+ * method is only approximately an unbiased source of independently chosen
+ * bits. If it were a perfect source of randomly chosen bits, then the
+ * algorithm shown would choose {@code int} values from the stated range
+ * with perfect uniformity.
+ * <p>
+ * The algorithm is slightly tricky. It rejects values that would result in
+ * an uneven distribution (due to the fact that 2^31 is not divisible by n).
+ * The probability of a value being rejected depends on n. The worst case is
+ * n=2^30+1, for which the probability of a reject is 1/2, and the expected
+ * number of iterations before the loop terminates is 2.
+ * <p>
+ * The algorithm treats the case where n is a power of two specially: it
+ * returns the correct number of high-order bits from the underlying
+ * pseudo-random number generator. In the absence of special treatment, the
+ * correct number of <i>low-order</i> bits would be returned. Linear
+ * congruential pseudo-random number generators such as the one implemented
+ * by this class are known to have short periods in the sequence of values
+ * of their low-order bits. Thus, this special case greatly increases the
+ * length of the sequence of values returned by successive calls to this
+ * method if n is a small power of two.
+ *
+ * @param bound the upper bound (exclusive). Must be positive.
+ * @return the next pseudorandom, uniformly distributed {@code int} value
+ * between zero (inclusive) and {@code bound} (exclusive) from this random
+ * number generator's sequence
+ * @throws IllegalArgumentException if bound is not positive
+ * @since 1.2
+ */
+ @Override
+ public int nextInt(final int bound) {
+ //if (bound <= 0) {
+ //throw new RuntimeException("BadBound");
+ //}
- /*int r = next(31);
+ /*int r = next(31);
int m = bound - 1;
if ((bound & m) == 0) // i.e., bound is a power of 2
{
@@ -229,37 +229,38 @@ public class XSTR extends Random {
;
}
return r;*/
- //speedup, new nextInt ~+40%
- last = seed ^ (seed << 21);
- last ^= (last >>> 35);
- last ^= (last << 4);
- seed = last;
- int out = (int) last % bound;
- return (out < 0) ? -out : out;
- }
- @Override
+ //speedup, new nextInt ~+40%
+ this.last = this.seed ^ (this.seed << 21);
+ this.last ^= (this.last >>> 35);
+ this.last ^= (this.last << 4);
+ this.seed = this.last;
+ final int out = (int) this.last % bound;
+ return (out < 0) ? -out : out;
+ }
+ @Override
public int nextInt() {
- return next(32);
- }
+ return this.next(32);
+ }
- @Override
+ @Override
public float nextFloat() {
- return next(24) * FLOAT_UNIT;
- }
+ return this.next(24) * FLOAT_UNIT;
+ }
- @Override
+ @Override
public long nextLong() {
- // it's okay that the bottom word remains signed.
- return ((long)(next(32)) << 32) + next(32);
- }
+ // it's okay that the bottom word remains signed.
+ return ((long)(this.next(32)) << 32) + this.next(32);
+ }
- @Override
- public void nextBytes(byte[] bytes_arr) {
- for (int iba = 0, lenba = bytes_arr.length; iba < lenba; ) {
- for (int rndba = nextInt(),
- nba = Math.min(lenba - iba, Integer.SIZE/Byte.SIZE);
- nba-- > 0; rndba >>= Byte.SIZE)
- bytes_arr[iba++] = (byte)rndba;
+ @Override
+ public void nextBytes(final byte[] bytes_arr) {
+ for (int iba = 0, lenba = bytes_arr.length; iba < lenba; ) {
+ for (int rndba = this.nextInt(),
+ nba = Math.min(lenba - iba, Integer.SIZE/Byte.SIZE);
+ nba-- > 0; rndba >>= Byte.SIZE) {
+ bytes_arr[iba++] = (byte)rndba;
+ }
}
- }
+ }
} \ No newline at end of file