From 95a31d36d2320cc046d308505f478d0215998f9b Mon Sep 17 00:00:00 2001 From: George Blouin Date: Sat, 11 Mar 2023 22:04:02 -0600 Subject: [PATCH 1/2] Allows for Multiples --- sswlib/src/main/java/components/BipedLoadout.java | 2 +- .../main/java/components/EquipmentCollection.java | 6 ++---- sswlib/src/main/java/components/QuadLoadout.java | 2 +- sswlib/src/main/java/components/abPlaceable.java | 12 ++++++++++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/sswlib/src/main/java/components/BipedLoadout.java b/sswlib/src/main/java/components/BipedLoadout.java index 43e4a90b..858b2ebe 100644 --- a/sswlib/src/main/java/components/BipedLoadout.java +++ b/sswlib/src/main/java/components/BipedLoadout.java @@ -267,7 +267,7 @@ public void AddToQueue( abPlaceable p ) { } } else { if( p == Queue.get( i ) ) { return; } - if( p.LookupName().equals( ((abPlaceable) Queue.get( i )).LookupName() ) ) { + if( p.equals(Queue.get( i )) ) { // create a new equipment collection for these items. EquipmentCollection e = new EquipmentCollection( this ); e.Add( p ); diff --git a/sswlib/src/main/java/components/EquipmentCollection.java b/sswlib/src/main/java/components/EquipmentCollection.java index 6d55ecec..edfc7ed5 100644 --- a/sswlib/src/main/java/components/EquipmentCollection.java +++ b/sswlib/src/main/java/components/EquipmentCollection.java @@ -45,7 +45,7 @@ public abPlaceable GetType() { } public boolean SameType( abPlaceable p ) { - if( ((abPlaceable) equips.get( 0 )).LookupName().equals( p.LookupName() ) ) { + if( p.equals(equips.get( 0 ))) { return true; } else { return false; @@ -59,9 +59,7 @@ public boolean Add( abPlaceable p ) { return true; } else { if( SameType( p ) ) { - if( ! equips.contains( p ) ) { - equips.add( p ); - } + equips.add( p ); return true; } else { return false; diff --git a/sswlib/src/main/java/components/QuadLoadout.java b/sswlib/src/main/java/components/QuadLoadout.java index a085423b..f3d6c107 100644 --- a/sswlib/src/main/java/components/QuadLoadout.java +++ b/sswlib/src/main/java/components/QuadLoadout.java @@ -267,7 +267,7 @@ public void AddToQueue( abPlaceable p ) { } } else { if( p == Queue.get( i ) ) { return; } - if( p.LookupName().equals( ((abPlaceable) Queue.get( i )).LookupName() ) ) { + if( p.equals(Queue.get( i )) ) { // create a new equipment collection for these items. EquipmentCollection e = new EquipmentCollection( this ); e.Add( p ); diff --git a/sswlib/src/main/java/components/abPlaceable.java b/sswlib/src/main/java/components/abPlaceable.java index 3fa715aa..fa74a2e9 100644 --- a/sswlib/src/main/java/components/abPlaceable.java +++ b/sswlib/src/main/java/components/abPlaceable.java @@ -467,6 +467,18 @@ public boolean IsCritable() { public int compareTo(abPlaceable o ) { return ActualName().compareTo(o.ActualName()); } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof abPlaceable)) + return false; + + if (((abPlaceable) obj).ActualName() == ActualName()) { + return true; + } + + return false; + } @Override public String toString() { From e3ff84571e98fc832482c58faab262b7949f8345 Mon Sep 17 00:00:00 2001 From: George Blouin Date: Sat, 11 Mar 2023 22:39:36 -0600 Subject: [PATCH 2/2] Remove Contains Check As it is blocking the addition of more then 1 of the item. --- .../src/main/java/components/BipedLoadout.java | 14 ++++---------- sswlib/src/main/java/components/QuadLoadout.java | 14 ++++---------- .../src/main/java/components/TripodLoadout.java | 16 +++++----------- 3 files changed, 13 insertions(+), 31 deletions(-) diff --git a/sswlib/src/main/java/components/BipedLoadout.java b/sswlib/src/main/java/components/BipedLoadout.java index 858b2ebe..b4aafed3 100644 --- a/sswlib/src/main/java/components/BipedLoadout.java +++ b/sswlib/src/main/java/components/BipedLoadout.java @@ -286,23 +286,17 @@ public void AddToQueue( abPlaceable p ) { // check to see if this is a core component if( ! p.CoreComponent() ) { // add it to the non core list - if( ! NonCore.contains( p ) ) { - NonCore.add( p ); - } + NonCore.add( p ); // add it to the equipment list if appropriate if( ! ( p instanceof Ammunition ) ) { - if( ! Equipment.contains( p ) ) { - Equipment.add( p ); - } + Equipment.add( p ); } // add it to the TC list if appropriate. if( p instanceof ifWeapon ) { - if( ! TCList.contains( p ) ) { - if( ((ifWeapon) p).IsTCCapable() ) { - TCList.add( p ); - } + if( ((ifWeapon) p).IsTCCapable() ) { + TCList.add( p ); } } diff --git a/sswlib/src/main/java/components/QuadLoadout.java b/sswlib/src/main/java/components/QuadLoadout.java index f3d6c107..43805d1c 100644 --- a/sswlib/src/main/java/components/QuadLoadout.java +++ b/sswlib/src/main/java/components/QuadLoadout.java @@ -286,23 +286,17 @@ public void AddToQueue( abPlaceable p ) { // check to see if this is a core component if( ! p.CoreComponent() ) { // add it to the non core list - if( ! NonCore.contains( p ) ) { - NonCore.add( p ); - } + NonCore.add( p ); // add it to the equipment list if appropriate if( ! ( p instanceof Ammunition ) ) { - if( ! Equipment.contains( p ) ) { - Equipment.add( p ); - } + Equipment.add( p ); } // add it to the TC list if appropriate. if( p instanceof ifWeapon ) { - if( ! TCList.contains( p ) ) { - if( ((ifWeapon) p).IsTCCapable() ) { - TCList.add( p ); - } + if( ((ifWeapon) p).IsTCCapable() ) { + TCList.add( p ); } } diff --git a/sswlib/src/main/java/components/TripodLoadout.java b/sswlib/src/main/java/components/TripodLoadout.java index 9cf75c75..b5af181e 100644 --- a/sswlib/src/main/java/components/TripodLoadout.java +++ b/sswlib/src/main/java/components/TripodLoadout.java @@ -270,7 +270,7 @@ public void AddToQueue( abPlaceable p ) { } } else { if( p == Queue.get( i ) ) { return; } - if( p.LookupName().equals( ((abPlaceable) Queue.get( i )).LookupName() ) ) { + if( p.equals(Queue.get( i )) ) { // create a new equipment collection for these items. EquipmentCollection e = new EquipmentCollection( this ); e.Add( p ); @@ -289,23 +289,17 @@ public void AddToQueue( abPlaceable p ) { // check to see if this is a core component if( ! p.CoreComponent() ) { // add it to the non core list - if( ! NonCore.contains( p ) ) { - NonCore.add( p ); - } + NonCore.add( p ); // add it to the equipment list if appropriate if( ! ( p instanceof Ammunition ) ) { - if( ! Equipment.contains( p ) ) { - Equipment.add( p ); - } + Equipment.add( p ); } // add it to the TC list if appropriate. if( p instanceof ifWeapon ) { - if( ! TCList.contains( p ) ) { - if( ((ifWeapon) p).IsTCCapable() ) { - TCList.add( p ); - } + if( ((ifWeapon) p).IsTCCapable() ) { + TCList.add( p ); } }