Skip to content

Commit e1bf4ba

Browse files
Fix SpotBugs warnings: Implement proper hashCode and equals for core classes
- Implemented consistent `hashCode()` and `equals()` for: - `Geofence`: uses id, location, radius, expiration. - `PropertyBase`: uses name. - `Font`: uses native font or attributes. - `Border` / `CSSBorder` / `RoundBorder`: uses fields or identity where appropriate. - `Style`: manual hash calculation for primitive arrays (margin/padding) to avoid missing Arrays utility in CLDC. - `TarEntry`: added `equals(Object)` override and `hashCode` based on header name. - `Transform`: uses type and matrix values. - `ImageDownloadService`: uses cacheId. - `BoxLayout`: added `align` to equals/hashCode to fix layout update issues. - `BorderLayout`, `FlowLayout`, `GridLayout`, `TableLayout`: uses configuration fields. - Fixed `BoxLayout` equality check to include alignment, resolving layout update regression. - Manual array hashing in `Style` ensures CLDC 1.1 compatibility.
1 parent 4426ca6 commit e1bf4ba

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CodenameOne/src/com/codename1/ui/layouts/BoxLayout.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,11 @@ public String toString() {
520520
* {@inheritDoc}
521521
*/
522522
public boolean equals(Object o) {
523-
return super.equals(o) && axis == ((BoxLayout) o).axis;
523+
return super.equals(o) && axis == ((BoxLayout) o).axis && align == ((BoxLayout) o).align;
524524
}
525525

526526
@Override
527527
public int hashCode() {
528-
return super.hashCode() ^ axis;
528+
return super.hashCode() ^ axis ^ align;
529529
}
530530
}

CodenameOne/src/com/codename1/ui/plaf/Style.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,6 +3168,18 @@ public int hashCode() {
31683168
hash = 89 * hash + this.opacity;
31693169
hash = 89 * hash + this.backgroundType;
31703170
hash = 89 * hash + this.backgroundAlignment;
3171+
if (this.padding != null) {
3172+
for (float p : this.padding) {
3173+
hash = 89 * hash + Float.floatToIntBits(p);
3174+
}
3175+
}
3176+
if (this.margin != null) {
3177+
for (float m : this.margin) {
3178+
hash = 89 * hash + Float.floatToIntBits(m);
3179+
}
3180+
}
3181+
hash = 89 * hash + com.codename1.compat.java.util.Objects.hashCode(this.border);
3182+
hash = 89 * hash + this.align;
31713183
return hash;
31723184
}
31733185

0 commit comments

Comments
 (0)