src/main/kotlin/de/uapcore/lightpit/util/Issues.kt

Thu, 13 May 2021 10:16:57 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 13 May 2021 10:16:57 +0200
changeset 193
1e4044d29b1c
parent 184
e8eecee6aadf
child 228
d68b08c8f6d0
permissions
-rw-r--r--

fixes missing issue sorting

universe@167 1 /*
universe@180 2 * Copyright 2021 Mike Becker. All rights reserved.
universe@167 3 *
universe@167 4 * Redistribution and use in source and binary forms, with or without
universe@167 5 * modification, are permitted provided that the following conditions are met:
universe@167 6 *
universe@167 7 * 1. Redistributions of source code must retain the above copyright
universe@167 8 * notice, this list of conditions and the following disclaimer.
universe@167 9 *
universe@167 10 * 2. Redistributions in binary form must reproduce the above copyright
universe@167 11 * notice, this list of conditions and the following disclaimer in the
universe@167 12 * documentation and/or other materials provided with the distribution.
universe@167 13 *
universe@167 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@167 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@167 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
universe@167 17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
universe@167 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
universe@167 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
universe@167 20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
universe@167 21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
universe@167 22 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
universe@167 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
universe@167 24 */
universe@167 25
universe@184 26 package de.uapcore.lightpit.util
universe@167 27
universe@167 28 import de.uapcore.lightpit.entities.Component
universe@184 29 import de.uapcore.lightpit.entities.Issue
universe@167 30 import de.uapcore.lightpit.entities.Project
universe@167 31 import de.uapcore.lightpit.entities.Version
universe@184 32 import de.uapcore.lightpit.types.IssueStatusPhase
universe@167 33
universe@167 34 data class IssueFilter(
universe@167 35 val project: Filter<Project> = AllFilter(),
universe@167 36 val version: Filter<Version> = AllFilter(),
universe@167 37 val component: Filter<Component> = AllFilter()
universe@167 38 )
universe@184 39
universe@184 40 data class IssueSorter(val criteria: List<Criteria>) : Comparator<Issue> {
universe@184 41 enum class Field {
universe@184 42 DONE, ETA, UPDATED
universe@184 43 }
universe@184 44
universe@193 45 data class Criteria(val field: Field, val asc: Boolean = true)
universe@193 46
universe@193 47 companion object {
universe@193 48 val DEFAULT_ISSUE_SORTER = IssueSorter(listOf(
universe@193 49 Criteria(Field.DONE),
universe@193 50 Criteria(Field.UPDATED, false),
universe@193 51 Criteria(Field.ETA)
universe@193 52 ))
universe@193 53 }
universe@184 54
universe@184 55 override fun compare(left: Issue, right: Issue): Int {
universe@184 56 if (left == right) {
universe@184 57 return 0;
universe@184 58 }
universe@184 59 for (c in criteria) {
universe@184 60 val result = when (c.field) {
universe@184 61 Field.DONE -> (left.status.phase == IssueStatusPhase.Done).compareTo(right.status.phase == IssueStatusPhase.Done)
universe@184 62 Field.ETA -> {
universe@184 63 val l = left.eta
universe@184 64 val r = right.eta
universe@184 65 if (l == null && r == null) 0
universe@184 66 else if (l == null) 1
universe@184 67 else if (r == null) -1
universe@184 68 else l.compareTo(r)
universe@184 69 }
universe@184 70 Field.UPDATED -> left.updated.compareTo(right.updated)
universe@184 71 }
universe@184 72 if (result != 0) {
universe@184 73 return if (c.asc) result else -result
universe@184 74 }
universe@184 75 }
universe@184 76 return 0
universe@184 77 }
universe@184 78 }
universe@184 79

mercurial