@Test public void testEquals() { Attribute att = Attribute.builder().setName("name").setNumericValue(123, true).build(); Attribute attu = Attribute.builder().setName("name").setNumericValue(123, false).build(); assertThat(att.equals(attu)).isFalse(); assertThat(att.hashCode() == attu.hashCode()).isFalse(); Attribute att2 = Attribute.builder().setName("name").setNumericValue(123, true).build(); assertThat(att.equals(att2)).isTrue(); assertThat(att.hashCode() == att2.hashCode()).isTrue(); Attribute attNoValue = Attribute.builder().setName("name").build(); assertThat(attNoValue.equals("name")).isFalse(); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Attribute)) return false; Attribute att = (Attribute) o; String name = getShortName(); if (!name.equals(att.getShortName())) return false; if (nelems != att.nelems) return false; if (dataType != att.dataType) return false; if (isString()) { return att.getStringValue().equals(getStringValue()); } if (nvalue != null) { return nvalue.equals(att.nvalue); } if (values != null) { for (int i = 0; i < getLength(); i++) { int r1 = isString() ? getStringValue(i).hashCode() : getNumericValue(i).hashCode(); int r2 = att.isString() ? att.getStringValue(i).hashCode() : att.getNumericValue(i).hashCode(); if (r1 != r2) return false; } } return true; }
Attribute { @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Attribute)) return false; Attribute att = (Attribute) o; String name = getShortName(); if (!name.equals(att.getShortName())) return false; if (nelems != att.nelems) return false; if (dataType != att.dataType) return false; if (isString()) { return att.getStringValue().equals(getStringValue()); } if (nvalue != null) { return nvalue.equals(att.nvalue); } if (values != null) { for (int i = 0; i < getLength(); i++) { int r1 = isString() ? getStringValue(i).hashCode() : getNumericValue(i).hashCode(); int r2 = att.isString() ? att.getStringValue(i).hashCode() : att.getNumericValue(i).hashCode(); if (r1 != r2) return false; } } return true; } }
Attribute { @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Attribute)) return false; Attribute att = (Attribute) o; String name = getShortName(); if (!name.equals(att.getShortName())) return false; if (nelems != att.nelems) return false; if (dataType != att.dataType) return false; if (isString()) { return att.getStringValue().equals(getStringValue()); } if (nvalue != null) { return nvalue.equals(att.nvalue); } if (values != null) { for (int i = 0; i < getLength(); i++) { int r1 = isString() ? getStringValue(i).hashCode() : getNumericValue(i).hashCode(); int r2 = att.isString() ? att.getStringValue(i).hashCode() : att.getNumericValue(i).hashCode(); if (r1 != r2) return false; } } return true; } Attribute(String name, @Nullable String val);  Attribute(String name, Number val); private  Attribute(Builder builder); }
Attribute { @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Attribute)) return false; Attribute att = (Attribute) o; String name = getShortName(); if (!name.equals(att.getShortName())) return false; if (nelems != att.nelems) return false; if (dataType != att.dataType) return false; if (isString()) { return att.getStringValue().equals(getStringValue()); } if (nvalue != null) { return nvalue.equals(att.nvalue); } if (values != null) { for (int i = 0; i < getLength(); i++) { int r1 = isString() ? getStringValue(i).hashCode() : getNumericValue(i).hashCode(); int r2 = att.isString() ? att.getStringValue(i).hashCode() : att.getNumericValue(i).hashCode(); if (r1 != r2) return false; } } return true; } Attribute(String name, @Nullable String val);  Attribute(String name, Number val); private  Attribute(Builder builder); static Attribute fromParameter(Parameter param); static Attribute fromArray(String name, ucar.ma2.Array values); static Attribute fromArray(String name, Array<?> values); static Attribute emptyValued(String name, DataType dtype); DataType getDataType(); @Nullable EnumTypedef getEnumType(); int getLength(); String getName(); @Nullable Number getNumericValue(); @Nullable Number getNumericValue(int index); String getShortName(); @Nullable String getStringValue(); @Nullable String getStringValue(int index); @Nullable Object getValue(int index); @Nullable ucar.ma2.Array getValues(); @Nullable ucar.array.Array<?> getArrayValues(); boolean isArray(); boolean isString(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); Builder toBuilder(); static Builder builder(); static Builder builder(String name); }
Attribute { @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Attribute)) return false; Attribute att = (Attribute) o; String name = getShortName(); if (!name.equals(att.getShortName())) return false; if (nelems != att.nelems) return false; if (dataType != att.dataType) return false; if (isString()) { return att.getStringValue().equals(getStringValue()); } if (nvalue != null) { return nvalue.equals(att.nvalue); } if (values != null) { for (int i = 0; i < getLength(); i++) { int r1 = isString() ? getStringValue(i).hashCode() : getNumericValue(i).hashCode(); int r2 = att.isString() ? att.getStringValue(i).hashCode() : att.getNumericValue(i).hashCode(); if (r1 != r2) return false; } } return true; } Attribute(String name, @Nullable String val);  Attribute(String name, Number val); private  Attribute(Builder builder); static Attribute fromParameter(Parameter param); static Attribute fromArray(String name, ucar.ma2.Array values); static Attribute fromArray(String name, Array<?> values); static Attribute emptyValued(String name, DataType dtype); DataType getDataType(); @Nullable EnumTypedef getEnumType(); int getLength(); String getName(); @Nullable Number getNumericValue(); @Nullable Number getNumericValue(int index); String getShortName(); @Nullable String getStringValue(); @Nullable String getStringValue(int index); @Nullable Object getValue(int index); @Nullable ucar.ma2.Array getValues(); @Nullable ucar.array.Array<?> getArrayValues(); boolean isArray(); boolean isString(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); Builder toBuilder(); static Builder builder(); static Builder builder(String name);  }