Skip to content

XySequence edits and combiner

Want a method that will combine XySequences, adding the y-values of identical x-values. Found some other little things to fix/clean first and then helper methods that will help with the combine method.

  • Refactor ArrayXySequence.hashCode() to return Objects.has(Arrays.hashCode(xs), Arrays.hashCode(ys)); should yield same result
  • Refactor ArrayXySequence.validateSequence() to use only Arrays.equals(this.xs, that.xs); the first test in Arrays.equals() does the redundant first comparison
  • Add package-private Sequences.areSimilar(Collection<XySequence>), return boolean; checkState(!coll.isEmpty()); if size == 1, return true; multiple ways to do this; at this point in time, we have total control over the creation of XySequences so any XySequence in the supplied collection can safely be cast to ArrayXySequence; could create a Predicate that stores the first xs array, then stream the collection and use allMatch
  • Add Sequences.combine(Collection<XySequence>), returns XySequence; if the sequences areSimilar() combine using MutableXySequence.add(XySequence); else use a stream, flatMap and a toMap collector that will yield a sorted Map<Double, Double> that can then be used to populate a new XySequence.
Edited by Altekruse, Jason Morgan