jgonian / commons-ip-math

https://github.com/jgonian/commons-ip-math
MIT License
74 stars 19 forks source link

Create Scala wrapper and release as a separate library #6

Closed agemooij closed 9 years ago

agemooij commented 9 years ago

Hi

This library should get a lot more attention since there's nothing else available in the Java/Scala space for dealing with CIDRs, ip ranges, etc. I was at RIPE about 6 years ago and it's great to see a modern OS version of the good old IP resource library.

I'm working in Scala so it would be great if there were a more idiomatic Scala version of this library. It would be totally fine if it was implemented as a simple wrapper around the Java stuff

I wrote the following very basic Scala wrapper around Ipv4 to make things a bit more idiomatic (and immutable):

package object ip {
  type Ipv4 = net.ripe.commons.ip.Ipv4
  object Ipv4 {
    def apply(address: String): Ipv4 = net.ripe.commons.ip.Ipv4.parse(address)
  }

  type Ipv4Range = net.ripe.commons.ip.Ipv4Range
  object Ipv4Range {
    def apply(range: String): Ipv4Range = net.ripe.commons.ip.Ipv4Range.parse(range)
  }
}

package ip {
  case class Ipv4Ranges private (set: net.ripe.commons.ip.SortedResourceSet[Ipv4, Ipv4Range]) {
    def contains(ip: Ipv4): Boolean = set.contains(ip)
  }

  object Ipv4Ranges {
    def apply(ranges: Ipv4Range*): Ipv4Ranges = apply(ranges.toSet)
    def apply(ranges: Set[Ipv4Range]): Ipv4Ranges = {
      val set = new net.ripe.commons.ip.SortedResourceSet[Ipv4, Ipv4Range]()
      ranges.foreach(set.add(_))
      Ipv4Ranges(set)
    }
  }
}

If you like, you could create a new project (preferably an SBT one) and I could send a PR with the above code (and probably some more) to kickstart things.

Let me know what you think.

jgonian commented 9 years ago

Hi Age,

The idea of creating a Scala version of this library has been postponed for too long and I'm happy you'd like to help.

As for the project, I agree with you that SBT would be a better candidate mainly because of the cross-build support.

What I'm not sure, is whether it is good idea to keep one Git repository for both libraries (multi-module) or have a separate one for Scala.

I'm more inclined to create a separate one so that the library can have an independent release cycle but in this case we need to come up with a good repo name. Some ideas: commons-ip-math-scala commons-ip-math-4s ...

what do you think?

agemooij commented 9 years ago

I agree that a separate repository makes sense. Of the two names you mentioned I would prefer "commons-ip-math-scala".

jgonian commented 9 years ago

I've created a new project: commons-ip-math-scala. I'm closing this one, feel free to move the discussion over there.