Giter VIP home page Giter VIP logo

Comments (3)

gmuth avatar gmuth commented on June 4, 2024

You can define attributes like this
IppAttribute("page-ranges", IppTag.RangeOfInteger, listOfIntRange)
and use it as parameter for printJob.
The template attributes are provided for convenience and ease of use.

from ipp-client-kotlin.

muhammadn avatar muhammadn commented on June 4, 2024

Hi @gmuth . Thank you and i hope you had a good holiday.

I've tried above before i opened an issue but IppTemplateAttributes.kt function arguments relies on IppTag.kt so,

    @JvmStatic
    fun pageRanges(vararg range: List<IntRange>) =
            IppAttribute("page-ranges", IppTag.RangeOfInteger, range)

the code above won't work because IppTag only validates it as IntRange and not List<IntRange>

I can also try using String as an argument with eg "1..2,2..3,10..15" like below:

    @JvmStatic
    fun pageRanges(vararg range: String) =
            IppAttribute("page-ranges", IppTag.RangeOfInteger, listOf(range))

IppTag will cause an error because it does not match IntRange

code: https://github.com/gmuth/ipp-client-kotlin/blob/master/src/main/kotlin/de/gmuth/ipp/core/IppTag.kt#L47

If i modify IppTag which is a low level interaction, it will break while trying to communicate with Ipp

from ipp-client-kotlin.

gmuth avatar gmuth commented on June 4, 2024

I understand your issue and have provided another method that supports Collection<IntRange>.

Your first try is wrong because you really want to eliminate vararg completley.
Your second try does not work because you again use vararg, but in fact really want just one String and also because you don't convert the string to the required type IntRange and therefore run into class cast exceptions (or failed checks I've implemented for better error handling).

pageRanges("1,3,4,10".toListOfIntRange())

now works together with extension

fun String.toListOfIntRange() = split(",").map { it.toInt()..it.toInt() }

from ipp-client-kotlin.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.