Skip to content

Commit

Permalink
refactored val numberOfDocumentsOrDocumentCount to function
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuth committed Sep 9, 2024
1 parent 3a181bb commit 0ee0081
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/main/kotlin/de/gmuth/ipp/client/CupsClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ class CupsClient(
job.getOriginatingUserNameOrAppleJobOwnerOrNull()?.let { jobOwners.add(it) }
}
.onEach { job -> // keep stats and save documents
if (job.numberOfDocumentsOrDocumentCount == 0) numberOfJobsWithoutDocuments.incrementAndGet()
if (job.getNumberOfDocumentsOrDocumentCount() == 0)
numberOfJobsWithoutDocuments.incrementAndGet()
else getAndSaveDocuments(job, optionalCommandToHandleFile = commandToHandleSavedFile)
.apply { numberOfSavedDocuments.addAndGet(size) }
}
Expand Down
15 changes: 7 additions & 8 deletions src/main/kotlin/de/gmuth/ipp/client/IppJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,11 @@ class IppJob(
else -> null
}

val numberOfDocumentsOrDocumentCount: Int
get() = when {
attributes.containsKey("number-of-documents") -> numberOfDocuments
attributes.containsKey("document-count") -> attributes.getValue<Int>("document-count")
else -> throw IppException("number-of-documents or document-count not found")
}
fun getNumberOfDocumentsOrDocumentCount(): Int = when {
attributes.containsKey("number-of-documents") -> numberOfDocuments
attributes.containsKey("document-count") -> attributes.getValue("document-count")
else -> throw IppException("number-of-documents or document-count not found")
}

//-------------------
// Get-Job-Attributes
Expand Down Expand Up @@ -326,7 +325,7 @@ class IppJob(
save: Boolean = false,
optionalCommandToHandleFile: String? = null
) =
(1..numberOfDocumentsOrDocumentCount)
(1..getNumberOfDocumentsOrDocumentCount())
.map { cupsGetDocument(it) }
.onEach { document ->
if (save) with(document) {
Expand Down Expand Up @@ -377,7 +376,7 @@ class IppJob(
if (containsKey("job-originating-host-name")) append(", originating-host-name=$originatingHostName")
if (containsKey("job-originating-user-name")) append(", originating-user-name=$originatingUserName")
if (containsKey("com.apple.print.JobInfo.PMJobOwner")) append(", appleJobOwner=$appleJobOwner")
if (containsKey("number-of-documents") || containsKey("document-count")) append(", $numberOfDocumentsOrDocumentCount documents")
if (containsKey("number-of-documents") || containsKey("document-count")) append(", ${getNumberOfDocumentsOrDocumentCount()} documents")
if (containsKey("job-printer-uri")) append(", printer-uri=$printerUri")
if (containsKey("job-uri")) append(", uri=$uri")
toString()
Expand Down

0 comments on commit 0ee0081

Please sign in to comment.