universe@167: /* universe@180: * Copyright 2021 Mike Becker. All rights reserved. universe@167: * universe@167: * Redistribution and use in source and binary forms, with or without universe@167: * modification, are permitted provided that the following conditions are met: universe@167: * universe@167: * 1. Redistributions of source code must retain the above copyright universe@167: * notice, this list of conditions and the following disclaimer. universe@167: * universe@167: * 2. Redistributions in binary form must reproduce the above copyright universe@167: * notice, this list of conditions and the following disclaimer in the universe@167: * documentation and/or other materials provided with the distribution. universe@167: * universe@167: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" universe@167: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE universe@167: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE universe@167: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE universe@167: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL universe@167: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR universe@167: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER universe@167: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, universe@167: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE universe@167: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. universe@167: */ universe@167: universe@184: package de.uapcore.lightpit.util universe@167: universe@167: import de.uapcore.lightpit.entities.Component universe@184: import de.uapcore.lightpit.entities.Issue universe@167: import de.uapcore.lightpit.entities.Project universe@167: import de.uapcore.lightpit.entities.Version universe@184: import de.uapcore.lightpit.types.IssueStatusPhase universe@167: universe@167: data class IssueFilter( universe@167: val project: Filter = AllFilter(), universe@167: val version: Filter = AllFilter(), universe@167: val component: Filter = AllFilter() universe@167: ) universe@184: universe@184: data class IssueSorter(val criteria: List) : Comparator { universe@184: enum class Field { universe@184: DONE, ETA, UPDATED universe@184: } universe@184: universe@193: data class Criteria(val field: Field, val asc: Boolean = true) universe@193: universe@193: companion object { universe@193: val DEFAULT_ISSUE_SORTER = IssueSorter(listOf( universe@193: Criteria(Field.DONE), universe@193: Criteria(Field.UPDATED, false), universe@193: Criteria(Field.ETA) universe@193: )) universe@193: } universe@184: universe@184: override fun compare(left: Issue, right: Issue): Int { universe@184: if (left == right) { universe@184: return 0; universe@184: } universe@184: for (c in criteria) { universe@184: val result = when (c.field) { universe@184: Field.DONE -> (left.status.phase == IssueStatusPhase.Done).compareTo(right.status.phase == IssueStatusPhase.Done) universe@184: Field.ETA -> { universe@184: val l = left.eta universe@184: val r = right.eta universe@184: if (l == null && r == null) 0 universe@184: else if (l == null) 1 universe@184: else if (r == null) -1 universe@184: else l.compareTo(r) universe@184: } universe@184: Field.UPDATED -> left.updated.compareTo(right.updated) universe@184: } universe@184: if (result != 0) { universe@184: return if (c.asc) result else -result universe@184: } universe@184: } universe@184: return 0 universe@184: } universe@184: } universe@184: