Converted to kotlin

This commit is contained in:
nathan 2020-08-15 13:22:43 +02:00
parent 8d9bef0ccc
commit 4d0a1c9259
3 changed files with 16 additions and 16 deletions

View File

@ -13,24 +13,24 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package dorkbox.network.ipFilter; package dorkbox.network.ipFilter
import java.net.InetSocketAddress; import java.net.InetSocketAddress
/** /**
* Implement this interface to create new rules. * Implement this interface to create new rules.
*/ */
public interface IpFilterRule { interface IpFilterRule {
/** /**
* @return This method should return true if remoteAddress is valid according to your criteria. False otherwise. * @return This method should return true if remoteAddress is valid according to your criteria. False otherwise.
*/ */
boolean matches(InetSocketAddress remoteAddress); fun matches(remoteAddress: InetSocketAddress): Boolean
/** /**
* @return This method should return {@link IpFilterRuleType#ACCEPT} if all * @return This method should return [IpFilterRuleType.ACCEPT] if all
* {@link IpFilterRule#matches(InetSocketAddress)} for which {@link #matches(InetSocketAddress)} * [IpFilterRule.matches] for which [.matches]
* returns true should the accepted. If you want to exclude all of those IP addresses then * returns true should the accepted. If you want to exclude all of those IP addresses then
* {@link IpFilterRuleType#REJECT} should be returned. * [IpFilterRuleType.REJECT] should be returned.
*/ */
IpFilterRuleType ruleType(); fun ruleType(): IpFilterRuleType
} }

View File

@ -13,12 +13,11 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package dorkbox.network.ipFilter; package dorkbox.network.ipFilter
/** /**
* Used in {@link IpFilterRule} to decide if a matching IP Address should be allowed or denied to connect. * Used in [IpFilterRule] to decide if a matching IP Address should be allowed or denied to connect.
*/ */
public enum IpFilterRuleType { enum class IpFilterRuleType {
ACCEPT, ACCEPT, REJECT
REJECT
} }

View File

@ -21,8 +21,9 @@ import java.math.BigInteger
import java.net.* import java.net.*
/** /**
* Use this class to create rules for [RuleBasedIpFilter] that group IP addresses into subnets. * Use this class to create rules that group IP addresses into subnets.
* Supports both, IPv4 and IPv6. *
* Supports both IPv4 and IPv6.
*/ */
class IpSubnetFilterRule : IpFilterRule { class IpSubnetFilterRule : IpFilterRule {
companion object { companion object {
@ -70,7 +71,7 @@ class IpSubnetFilterRule : IpFilterRule {
} }
private class FakeSubnetFilterRule() : IpFilterRule { private class FakeSubnetFilterRule() : IpFilterRule {
override fun matches(remoteAddress: InetSocketAddress?): Boolean { override fun matches(remoteAddress: InetSocketAddress): Boolean {
return true return true
} }