⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wordcheckpermission.java

📁 这是高级Java里面的源代码
💻 JAVA
字号:
/**
   @version 1.00 1999-10-23
   @author Cay Horstmann
*/

import java.security.*;
import java.util.*;

/**
   A permission that checks for bad words.
*/
public class WordCheckPermission extends Permission
{ 
   /**
      Constructs a word check permission
      @param target a comma separated word list
      @param anAction "insert" or "avoid"
   */
   public WordCheckPermission(String target, String anAction)
   {  
      super(target);
      action = anAction;
   }

   public String getActions() { return action; }

   public boolean equals(Object other)
   {  
      if (other == null) return false;
      if (!getClass().equals(other.getClass())) return false;
      WordCheckPermission b = (WordCheckPermission)other;
      if (!action.equals(b.action)) return false;
      if (action.equals("insert"))
         return getName().equals(b.getName());
      else if (action.equals("avoid"))
         return badWordSet().equals(b.badWordSet());
      else return false;
   }

   public int hashCode()
   {  
      return getName().hashCode() + action.hashCode();
   }

   public boolean implies(Permission other)
   {  
      if (!(other instanceof WordCheckPermission)) return false;
      WordCheckPermission b = (WordCheckPermission)other;
      if (action.equals("insert"))
      {  
         return b.action.equals("insert") &&
            getName().indexOf(b.getName()) >= 0;
      }
      else if (action.equals("avoid"))
      {  
         if (b.action.equals("avoid"))
            return b.badWordSet().containsAll(badWordSet());
         else if (b.action.equals("insert"))
         {  
            Iterator iter = badWordSet().iterator();
            while (iter.hasNext())
            { 
               String badWord = (String)iter.next();
               if (b.getName().indexOf(badWord) >= 0)
                  return false;
            }
            return true;
         }
         else return false;
      }
      else return false;
   }

   /**
      Gets the bad words that this permission rule describes.
      @return a set of the bad words
   */
   public Set badWordSet()
   {  
      StringTokenizer tokenizer
         = new StringTokenizer(getName(), ",");
      Set set = new HashSet();
      while (tokenizer.hasMoreTokens())
         set.add(tokenizer.nextToken());
      return set;
   }

   private String action;
}



⌨️ 快捷键说明

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