utils.SortedCollectionConverters.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of model Show documentation
Show all versions of model Show documentation
Part of the OSS Review Toolkit (ORT), a suite to automate software compliance checks.
/*
* Copyright (C) 2023 The ORT Project Authors (see )
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* License-Filename: LICENSE
*/
@file:Suppress("Filename", "MatchingDeclarationName")
package org.ossreviewtoolkit.model.utils
import com.fasterxml.jackson.databind.util.StdConverter
import java.util.SortedSet
import org.ossreviewtoolkit.model.ArtifactProvenance
import org.ossreviewtoolkit.model.CopyrightFinding
import org.ossreviewtoolkit.model.DependencyGraphEdge
import org.ossreviewtoolkit.model.DependencyReference
import org.ossreviewtoolkit.model.FileList
import org.ossreviewtoolkit.model.Identifier
import org.ossreviewtoolkit.model.LicenseFinding
import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.PackageReference
import org.ossreviewtoolkit.model.Project
import org.ossreviewtoolkit.model.Provenance
import org.ossreviewtoolkit.model.ProvenanceResolutionResult
import org.ossreviewtoolkit.model.RepositoryProvenance
import org.ossreviewtoolkit.model.ScanResult
import org.ossreviewtoolkit.model.Scope
import org.ossreviewtoolkit.model.SnippetFinding
class CopyrightFindingSortedSetConverter : StdConverter, SortedSet>() {
override fun convert(value: Set) = value.toSortedSet(CopyrightFinding.COMPARATOR)
}
class DependencyGraphEdgeSortedSetConverter : StdConverter, Set>() {
override fun convert(value: Set) = value.toSortedSet(compareBy({ it.from }, { it.to }))
}
class DependencyReferenceSortedSetConverter : StdConverter, SortedSet>() {
override fun convert(value: Set) =
value.toSortedSet(compareBy({ it.pkg.toString() }, { it.fragment }))
}
/** Do not convert to SortedSet in order to not require a comparator consistent with equals */
class FileListSortedSetConverter : StdConverter, Set>() {
override fun convert(value: Set) = value.sortedBy { it.provenance.getSortKey() }.toSet()
}
/** Do not convert to SortedSet in order to not require a comparator consistent with equals */
class FileListEntrySortedSetConverter : StdConverter, Set>() {
override fun convert(value: Set) = value.sortedBy { it.path }.toSet()
}
class LicenseFindingSortedSetConverter : StdConverter, SortedSet>() {
override fun convert(value: Set) = value.toSortedSet(LicenseFinding.COMPARATOR)
}
class PackageReferenceSortedSetConverter : StdConverter, SortedSet>() {
override fun convert(value: Set) = value.toSortedSet(compareBy { it.id })
}
class PackageSortedSetConverter : StdConverter, SortedSet>() {
override fun convert(value: Set) = value.toSortedSet(compareBy { it.id })
}
class ProjectSortedSetConverter : StdConverter, SortedSet>() {
override fun convert(value: Set) = value.toSortedSet(compareBy { it.id })
}
class ProvenanceResolutionResultSortedSetConverter :
StdConverter, SortedSet>() {
override fun convert(value: Set) = value.toSortedSet(compareBy { it.id })
}
class ScannersMapConverter : StdConverter