cactoos icon indicating copy to clipboard operation
cactoos copied to clipboard

All concrete classes implementing Scalar/Func/BiFunc should override equals and hashCode

Open krzyk opened this issue 7 years ago • 6 comments

To make classes like IoCheckedScalar more useful we should implement equals and hashCode methods in them. Currently one has to use value() to get the underlying object and call equals/hashCode there, it shouldn't be required.

krzyk avatar Jul 04 '18 07:07 krzyk

@llorllale/z please, pay attention to this issue

0crat avatar Jul 04 '18 07:07 0crat

@krzyk if we do that, then we may trigger any side effects or use up resources excessively. There may be a scenario where a resource is available only once, after which successive invocations may fail or produce a different output.

Make sense?

llorllale avatar Sep 21 '18 20:09 llorllale

@llorllale But that will be up to the user if he will use those methods, without those one can't use e.g. Scalars as map keys or using any find method. So maybe create another class that will implement Scalar/Function/BiFunction that will override equals/hashcode.

krzyk avatar Sep 22 '18 04:09 krzyk

@krzyk I can't think of a name for this new class

llorllale avatar Sep 24 '18 20:09 llorllale

@llorllale maybe Keyable (because it can be used as a key in map), or Hashable?

krzyk avatar Sep 26 '18 11:09 krzyk

@krzyk I strongly believe that equals() is independent of hashcode(), although not the other way around, and I think they should be separate interfaces.

Looking through what we currently have:

  • Scalar Equals looks ok, I'm just thinking the "s" should be dropped from the name.
  • Scalar Equality makes no sense to me. I think it should be scrapped.

I think we would need a new Equals class of type Scalar<Boolean> that would decorate other scalars and implement Object.equals(). A warning should be present saying that if the resource is expensive then users should decorate the target scalar with StickyScalar.

WDYT?

llorllale avatar Sep 26 '18 15:09 llorllale