filterentry.java

来自「weblogic应用全实例」· Java 代码 · 共 47 行

JAVA
47
字号
//声明这个类所在的包
package examples.security.net;
//声明这个类引入的其他类

import java.net.InetAddress;


/**
 * 抽象类,过滤原则
 *
 */
abstract class FilterEntry
{
  //定义三种状态常量
  //允许	
  static final int ALLOW = 0;
  //拒绝
  static final int DENY = 1;
  //忽略
  static final int IGNORE = 2;
  private int protomask;
  private boolean action;
  //构造方法
  protected FilterEntry(boolean action, int protomask)
  {
    this.protomask = protomask;
    this.action = action;
  }
  //检查地址和协议
  int check(InetAddress addr, int protocol)
  {
    if (match(addr) && match(protocol))
    {
      return action ? ALLOW : DENY;
    }
    return IGNORE;
  }
  //匹配地址
  protected abstract boolean match(InetAddress addr);
  //匹配协议
  protected boolean match(int protocol)
  {
    return protomask == 0 || (protocol & protomask) != 0;
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?