package Ġcom . bk ahl ert . kom mon s . net Ċ Ċ import Ġcom . bk ahl ert . kom mon s . math . BigInteger Ċ import Ġcom . bk ahl ert . kom mon s . math . dec Ċ import Ġcom . bk ahl ert . kom mon s . math . inc Ċ Ċ public Ġclass ĠIPv 4 Subnet Ġprivate Ġconstructor ( override Ġval Ġvalue : ĠBigInteger , Ġoverride Ġval Ġprefix Length : ĠInt ) Ġ: ĠIP Subnet < IPv 4 Address > Ġ{ ĊĠĠĠ Ġoverride Ġval ĠmaxLength : ĠInt Ġ= ĠIPv 4 Address . bit Count ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġrequire Valid () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġval Ġusable : ĠIPv 4 Range Ġget () Ġ= ĠIPv 4 Range ( network . inc (). coerce At Most ( broadcast ), Ġbroadcast . dec (). coerce At Least ( network )) ĊĠĠĠ Ġoverride Ġfun Ġaddress ( value : ĠBigInteger ): ĠIPv 4 Address Ġ= ĠIPv 4 Address ( value ) ĊĠĠĠ Ġoverride Ġfun ĠtoString (): ĠString Ġ= Ġrepresentation ĊĠĠĠ Ġoverride Ġfun Ġequals ( other : ĠAny ?): ĠBoolean Ġ= Ġis Equal ( other ) ĊĠĠĠ Ġoverride Ġfun ĠhashCode (): ĠInt Ġ= Ġhash ĊĊĠĠĠ Ġpublic Ġcompanion Ġobject Ġ: ĠIP Subnet . Factory < IPv 4 Address > Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġaddress ( value : ĠBigInteger ): ĠIPv 4 Address Ġ= ĠIPv 4 Address ( value ) ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġfrom ( value : ĠBigInteger , Ġprefix Length : ĠInt ): ĠIPv 4 Subnet Ġ= ĠIPv 4 Subnet ( value , Ġprefix Length ) ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġfrom ( ip : ĠIPv 4 Address , Ġprefix Length : ĠInt ): ĠIPv 4 Subnet Ġ= Ġfrom ( ip . value , Ġprefix Length ) ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget Sm allest Common Subnet ( range : ĠClosed Range < IPv 4 Address >): ĠIPv 4 Subnet Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsuper . get Sm allest Common Subnet ( range ). run Ġ{ ĠIPv 4 Subnet ( start . value , Ġprefix Length ) Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġparse ( ip Subnet : ĠString ): ĠIPv 4 Subnet Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsuper . parse ( ip Subnet ). run Ġ{ ĠIPv 4 Subnet ( start . value , Ġprefix Length ) Ġ} ĊĠĠĠ Ġ} Ċ } Ċ Ċ public Ġoperator Ġfun ĠIPv 4 Address . div ( prefix Length : ĠInt ): ĠIPv 4 Subnet Ġ= ĠIPv 4 Subnet . from ( this , Ġprefix Length ) Ċ public Ġval ĠClosed Range < IPv 4 Address >. sm allest Common Subnet : ĠIPv 4 Subnet Ġget () Ġ= ĠIPv 4 Subnet . get Sm allest Common Subnet ( this ) Ċ Ċ public Ġfun ĠString . to IPv 4 Subnet (): ĠIPv 4 Subnet Ġ= ĠIPv 4 Subnet . parse ( this ) Ċ public Ġfun Ġip 4 Subnet Of ( value : ĠString ): ĠIPv 4 Subnet Ġ= Ġvalue . to IPv 4 Subnet () Ċ