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 returnObjects.has(Arrays.hashCode(xs), Arrays.hashCode(ys))
; should yield same result -
Refactor
ArrayXySequence.validateSequence()
to use onlyArrays.equals(this.xs, that.xs)
; the first test inArrays.equals()
does the redundant first comparison -
Add package-private
Sequences.areSimilar(Collection<XySequence>)
, returnboolean
;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 firstxs
array, then stream the collection and useallMatch
-
Add
Sequences.combine(Collection<XySequence>)
, returnsXySequence
; if the sequencesareSimilar()
combine using MutableXySequence.add(XySequence); else use a stream, flatMap and a toMap collector that will yield a sortedMap<Double, Double>
that can then be used to populate a new XySequence.