DecisionInternal.java
上传用户:qing5858
上传日期:2015-10-27
资源大小:6056k
文件大小:2k
源码类别:

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.core.model;
  2. import net.javacoding.jspider.api.model.Decision;
  3. import net.javacoding.jspider.api.model.DecisionStep;
  4. import java.util.ArrayList;
  5. /**
  6.  *
  7.  * $Id: DecisionInternal.java,v 1.1 2003/03/09 09:25:22 vanrogu Exp $
  8.  *
  9.  * @author G黱ther Van Roey
  10.  */
  11. public class DecisionInternal implements Decision {
  12.     protected int type;
  13.     protected String comment;
  14.     protected ArrayList history;
  15.     public DecisionInternal() {
  16.         this(Decision.RULE_DONTCARE);
  17.     }
  18.     public DecisionInternal(int type) {
  19.         this(type, "(no comment given)");
  20.     }
  21.     public DecisionInternal(int type, String comment) {
  22.         this.type = type;
  23.         this.comment = comment;
  24.         this.history = new ArrayList();
  25.     }
  26.     public int getDecision() {
  27.         return type;
  28.     }
  29.     public String getComment() {
  30.         return comment;
  31.     }
  32.     public boolean isVetoable() {
  33.         if (type == Decision.RULE_ACCEPT || type == Decision.RULE_DONTCARE) {
  34.             return true;
  35.         } else {
  36.             return false;
  37.         }
  38.     }
  39.     public void change ( Decision other ) {
  40.         this.type = other.getDecision();
  41.         this.comment = other.getComment();
  42.     }
  43.     public void merge(Decision other) {
  44.         if (other.getDecision() > this.getDecision()) {
  45.             this.change(other);
  46.         }
  47.     }
  48.     public void addStep(String rule, int ruleType, int type, String comment) {
  49.         history.add(new DecisionStepInternal(rule, ruleType, type, comment));
  50.     }
  51.     public DecisionStep[] getSteps() {
  52.         return (DecisionStep[])history.toArray(new DecisionStep[history.size()]);
  53.     }
  54.     public String toString() {
  55.         return "decision : " + translate ( type ) + " - " + getComment();
  56.     }
  57.     public static String translate ( int type ) {
  58.         switch ( type ) {
  59.             case Decision.RULE_ACCEPT:
  60.                 return "ACCEPT";
  61.             case Decision.RULE_FORBIDDEN:
  62.                 return "FORBIDDEN";
  63.             case Decision.RULE_IGNORE:
  64.                 return "IGNORE";
  65.             case Decision.RULE_DONTCARE:
  66.                 return "DON'T CARE";
  67.         }
  68.         return "ERROR!!!";
  69.     }
  70. }