From 1809a3323090e6741ef0781d0532d636d9615e18 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Wed, 4 Jan 2023 22:57:25 +0800 Subject: [PATCH] merge two toString Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../java/gregtech/api/enums/Materials.java | 2 +- .../gregtech/api/objects/MaterialStack.java | 18 +++++------------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/main/java/gregtech/api/enums/Materials.java b/src/main/java/gregtech/api/enums/Materials.java index 365618ae1ca..08611d55145 100644 --- a/src/main/java/gregtech/api/enums/Materials.java +++ b/src/main/java/gregtech/api/enums/Materials.java @@ -1467,7 +1467,7 @@ public Materials( aColor); mExtraData = aExtraData; mMaterialList.addAll(aMaterialList); - if (mMaterialList.size() == 1) mChemicalFormula = mMaterialList.get(0).toStringSingle(); + if (mMaterialList.size() == 1) mChemicalFormula = mMaterialList.get(0).toString(true); else mChemicalFormula = mMaterialList.stream() .map(MaterialStack::toString) diff --git a/src/main/java/gregtech/api/objects/MaterialStack.java b/src/main/java/gregtech/api/objects/MaterialStack.java index e5ebbee3689..21fee36b170 100644 --- a/src/main/java/gregtech/api/objects/MaterialStack.java +++ b/src/main/java/gregtech/api/objects/MaterialStack.java @@ -40,29 +40,21 @@ public boolean equals(Object aObject) { @Override public String toString() { + return toString(false); + } + + public String toString(boolean single) { String temp1 = "", temp2 = mMaterial.getToolTip(true), temp3 = "", temp4 = ""; if (mAmount > 1) { temp4 = GT_Utility.toSubscript(mAmount); } - if (mMaterial.mMaterialList.size() > 1 || isMaterialListComplex(this)) { + if ((!single || mAmount > 1) && isMaterialListComplex(this)) { temp1 = "("; temp3 = ")"; } return temp1 + temp2 + temp3 + temp4; } - public String toStringSingle() { - String temp1 = "", temp2 = mMaterial.getToolTip(true), temp3 = "", temp4 = ""; - if (mAmount > 1) { - temp4 = GT_Utility.toSubscript(mAmount); - if (mMaterial.mMaterialList.size() > 1 || isMaterialListComplex(this)) { - temp1 = "("; - temp3 = ")"; - } - } - return temp1 + temp2 + temp3 + temp4; - } - private boolean isMaterialListComplex(MaterialStack materialStack) { if (materialStack.mMaterial.mMaterialList.size() > 1) { return true;