Refactoring: split 'Utils' into multiple files; fix some stray uppercase-method names

This commit is contained in:
Pieter Vander Vennet 2025-08-01 04:02:09 +02:00
parent 81be4db044
commit 3ec89826e4
97 changed files with 884 additions and 921 deletions

View file

@ -7,8 +7,8 @@ import { TagsFilter } from "../../Tags/TagsFilter"
import { And } from "../../Tags/And"
import { Tag } from "../../Tags/Tag"
import { OsmId } from "../../../Models/OsmFeature"
import { Utils } from "../../../Utils"
import OsmObjectDownloader from "../OsmObjectDownloader"
import { Lists } from "../../../Utils/Lists"
export default class DeleteAction extends OsmChangeAction {
private readonly _softDeletionTags: TagsFilter
@ -50,12 +50,12 @@ export default class DeleteAction extends OsmChangeAction {
this._softDeletionTags = softDeletionTags
} else {
this._softDeletionTags = new And(
Utils.NoNull([
softDeletionTags,
new Tag(
"fixme",
`A mapcomplete user marked this feature to be deleted (${meta.specialMotivation})`
),
Lists.noNull([
softDeletionTags,
new Tag(
"fixme",
`A mapcomplete user marked this feature to be deleted (${meta.specialMotivation})`
),
])
)
}

View file

@ -13,6 +13,7 @@ import { Utils } from "../../../Utils"
import { OsmConnection } from "../OsmConnection"
import { Feature, Geometry, LineString, Point } from "geojson"
import FullNodeDatabaseSource from "../../FeatureSource/TiledFeatureSource/FullNodeDatabaseSource"
import { Lists } from "../../../Utils/Lists"
export default class ReplaceGeometryAction extends OsmChangeAction implements PreviewableAction {
/**
@ -164,7 +165,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr
preview.push(feature)
})
return StaticFeatureSource.fromGeojson(Utils.NoNull(preview))
return StaticFeatureSource.fromGeojson(Lists.noNull(preview))
}
/**
@ -317,7 +318,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr
candidate = undefined
moveDistance = Infinity
distances.forEach((distances, nodeId) => {
const minDist = Math.min(...Utils.NoNull(distances))
const minDist = Math.min(...(Lists.noNull(distances)))
if (moveDistance > minDist) {
// We have found a candidate to move
candidate = nodeId

View file

@ -18,6 +18,7 @@ import DeleteAction from "./Actions/DeleteAction"
import MarkdownUtils from "../../Utils/MarkdownUtils"
import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore"
import { Feature, Point } from "geojson"
import { Lists } from "../../Utils/Lists"
/**
* Handles all changes made to OSM.
@ -260,7 +261,7 @@ export class Changes {
}
public static GetNeededIds(changes: ChangeDescription[]) {
return Utils.Dedup(changes.filter((c) => c.id >= 0).map((c) => c.type + "/" + c.id))
return Lists.dedup(changes.filter((c) => c.id >= 0).map((c) => c.type + "/" + c.id))
}
/**
@ -467,8 +468,8 @@ export class Changes {
if (change.changes !== undefined) {
switch (change.type) {
case "node": {
const nlat = Utils.Round7(change.changes.lat)
const nlon = Utils.Round7(change.changes.lon)
const nlat = Utils.round7(change.changes.lat)
const nlon = Utils.round7(change.changes.lon)
const n = <OsmNode>obj
if (n.lat !== nlat || n.lon !== nlon) {
n.lat = nlat
@ -717,11 +718,9 @@ export class Changes {
* We _do not_ pass in the Changes object itself - we want the data from OSM directly in order to apply the changes
*/
const downloader = new OsmObjectDownloader(this.backend, undefined)
const osmObjects = Utils.NoNull(
await Promise.all<{ id: string; osmObj: OsmObject | "deleted" }>(
neededIds.map((id) => this.getOsmObject(id, downloader))
)
)
const osmObjects = Lists.noNull(await Promise.all<{ id: string; osmObj: OsmObject | "deleted" }>(
neededIds.map((id) => this.getOsmObject(id, downloader))
))
// Drop changes to deleted items
for (const { osmObj, id } of osmObjects) {
@ -801,7 +800,7 @@ export class Changes {
value: descr.meta.specialMotivation,
}))
const distances = Utils.NoNull(pending.map((descr) => descr.meta.distanceToObject))
const distances = Lists.noNull(pending.map((descr) => descr.meta.distanceToObject))
distances.sort((a, b) => a - b)
const perBinCount = Constants.distanceToChangeObjectBins.map(() => 0)
@ -816,23 +815,21 @@ export class Changes {
}
}
const perBinMessage = Utils.NoNull(
perBinCount.map((count, i) => {
if (count === 0) {
return undefined
}
const maxD = maxDistances[i]
let key = `change_within_${maxD}m`
if (maxD === Number.MAX_VALUE) {
key = `change_over_${maxDistances[i - 1]}m`
}
return {
key,
value: count,
aggregate: true,
}
})
)
const perBinMessage = Lists.noNull(perBinCount.map((count, i) => {
if (count === 0) {
return undefined
}
const maxD = maxDistances[i]
let key = `change_within_${maxD}m`
if (maxD === Number.MAX_VALUE) {
key = `change_over_${maxDistances[i - 1]}m`
}
return {
key,
value: count,
aggregate: true,
}
}))
// This method is only called with changedescriptions for this theme
const theme = pending[0].meta.theme

View file

@ -8,6 +8,7 @@ import { Utils } from "../../Utils"
import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore"
import { AndroidPolyfill } from "../Web/AndroidPolyfill"
import ImageUploadQueue from "../ImageProviders/ImageUploadQueue"
import { Lists } from "../../Utils/Lists"
export interface ChangesetTag {
key: string
@ -393,7 +394,7 @@ export class ChangesetHandler {
private async UpdateTags(csId: number, tags: ChangesetTag[]) {
tags = ChangesetHandler.removeDuplicateMetaTags(tags)
tags = Utils.NoNull(tags).filter(
tags = Lists.noNull(tags).filter(
(tag) =>
tag.key !== undefined &&
tag.value !== undefined &&

View file

@ -150,7 +150,7 @@ export abstract class OsmObject {
}
const v = this.tags[key]
if (v !== "" && v !== undefined) {
tags += ` <tag k="${Utils.EncodeXmlValue(key)}" v="${Utils.EncodeXmlValue(
tags += ` <tag k="${Utils.encodeXmlValue(key)}" v="${Utils.encodeXmlValue(
this.tags[key]
)}"/>
`

View file

@ -2,6 +2,7 @@ import { Store, UIEventSource } from "../UIEventSource"
import { OsmConnection } from "./OsmConnection"
import { LocalStorageSource } from "../Web/LocalStorageSource"
import { Utils } from "../../Utils"
import { Lists } from "../../Utils/Lists"
import OSMAuthInstance = OSMAuth.osmAuth
export class OsmPreferences {
@ -270,7 +271,7 @@ export class OsmPreferences {
return
}
// _All_ keys are deleted first, to avoid pending parts
const keysToDelete = Utils.Dedup(OsmPreferences.keysStartingWith(this.seenKeys, k))
const keysToDelete = Lists.dedup(OsmPreferences.keysStartingWith(this.seenKeys, k))
if (v === null || v === undefined || v === "" || v === "undefined" || v === "null") {
for (const k of keysToDelete) {
await this.deleteKeyDirectly(k)