Exemplo n.º 1
1
 /**
  * src全てをこのグループに追加します。 結合しているかについて調べないので注意。
  *
  * @param src NOT NULL
  */
 void add(StoneGroupImpl src) {
   ArgumentChecker.throwIfNull(src);
   stones_.addAll(src.stones_);
   neighbors_.addAll(src.neighbors_);
   lifePoints_.addAll(src.lifePoints_);
   lifePoints_.removeAll(stones_);
 }
Exemplo n.º 2
0
 /** @param src NOT NULL */
 StoneGroupImpl(final StoneGroupImpl src) {
   ArgumentChecker.throwIfNull(src);
   size_ = src.size_;
   stones_ = new HashSet<SgfPoint>(src.stones_);
   neighbors_ = new HashSet<SgfPoint>(src.neighbors_);
   lifePoints_ = new HashSet<SgfPoint>(src.lifePoints_);
 }
Exemplo n.º 3
0
  /**
   * prefValueを (CODECのFQCN) + '@' + ({@link org.unitarou.linecodec.LineCodec#encode(Object)})
   * とみなして、CODECからObjectをデコードして返します。<br>
   * CODECのクラス名が取得できなかったり、 取得できてもそのインスタンスが取得できない場合は<code>null</code>を返します。
   *
   * @param prefValue
   * @return デコードされた結果。デコードに失敗した場合は<code>null</code>
   * @throws org.unitarou.lang.NullArgumentException
   */
  @Logging(level = WARN, stackTrace = false, contents = "CODECのロードに失敗した場合")
  public Object decode(String prefValue) {
    ArgumentChecker.throwIfNull(prefValue);

    int pos = prefValue.indexOf(SEPARATOR);
    if (pos == -1) {
      log_s_.log(DEBUG, "[IGNORE] Unknown type value: {0}", prefValue); // $NON-NLS-1$
      return null;
    }
    String className = prefValue.substring(0, pos);
    pos = pos + 1;
    String value = (pos < prefValue.length()) ? prefValue.substring(pos) : Strings.EMPTY;

    try {
      Class<?> clazz = getClass(className);
      LineCodec codec = codecMap_.get(clazz);
      if (codec == null) {
        codec = (LineCodec) clazz.newInstance();
      }
      return codec.decode(value);

    } catch (Exception e) {
      log_s_.log(WARN, "[IGNORE] {0}@{1}", prefValue, e.getLocalizedMessage()); // $NON-NLS-1$
    }
    return null;
  }
Exemplo n.º 4
0
  /**
   * pointがこのグループに接続可能 (上下左右の何れかに近接している)な場合のみ、 pointを追加してtrueを返します。<br>
   * lifePointsはpointの活点でpointの隣接点で他に石が存在しない集合です。
   *
   * @param point
   * @param lifePoints
   * @return 隣接している場合にtrue
   */
  boolean add(SgfPoint point, Collection<SgfPoint> lifePoints) {
    ArgumentChecker.throwIfNull(point, lifePoints);

    if (!size_.equals(point.size())) {
      throw new IllegalArgumentException(
          "Bad size " + size_ + "!=" + point.size()); // $NON-NLS-1$//$NON-NLS-2$
    }

    if (!lifePoints_.contains(point) && !lifePoints_.isEmpty()) {
      return false;
    }
    stones_.add(point);

    // 同じグループの石が無ければ、隣接点として登録する。
    for (SgfPoint neighbor : point.neighbors()) {
      if (!stones_.contains(neighbor)) {
        neighbors_.add(neighbor);
      }
    }

    // 活点を更新する。
    // 石が置かれるところの活点は削除し、
    // その石の活点をこのグループに追加する。
    lifePoints_.remove(point);
    for (SgfPoint lifePoint : lifePoints) {
      if (stones_.contains(lifePoint)) {
        throw new IllegalArgumentException(
            lifePoint
                + " does not touch this group" //$NON-NLS-1$
                + BasicFormatter.format(stones_));
      }
      lifePoints_.add(lifePoint);
    }
    return true;
  }
Exemplo n.º 5
0
 /**
  * pointのダメを詰めます。ダメが0になった場合 (つまり、死んだ場合)はtrueを返します。 自殺手などで既に死んでいた場合はfalseを返します。
  *
  * @param point
  * @return 死んだ場合にtrue
  */
 boolean removeLifePoint(SgfPoint point) {
   ArgumentChecker.throwIfNull(point);
   assert (point != null);
   if (lifePoints_.remove(point)) {
     return lifePoints_.isEmpty();
   }
   return false;
 }
  /* (non-Javadoc)
   * @see org.unitarou.yukinoshita.view.jface.board.BlockPainter#getTransientPaintings(org.unitarou.yukinoshita.model.NodeView)
   */
  public Set<SgfPoint> getTransientPaintings(NodeView nodeView) {
    ArgumentChecker.throwIfNull(nodeView);

    Set<SgfPoint> ret = new TreeSet<SgfPoint>();
    ret.addAll(nodeView.getIgoBoard().position(SgfColor.BLACK));
    ret.addAll(nodeView.getIgoBoard().position(SgfColor.WHITE));
    return ret;
  }
Exemplo n.º 7
0
  /**
   * {@link GameType}を指定せず、 アプリケーション情報と、碁盤のサイズを指定して、 インスタンスを作成して返します。
   *
   * @param application
   * @param size
   * @return 作成した棋譜。NOT NULL
   */
  public static RootGameTree createNoGameType(SgfApplication application, SgfSize size) {
    ArgumentChecker.throwIfNull(application, size);

    RootGameTree ret = new RootGameTree();
    ret.setApplication(application);
    ret.setSize(size);
    return ret;
  }
Exemplo n.º 8
0
 /**
  * valueを単に前半の座標部分と後半のメッセージ部分に分けた配列を返します。 {@link SgfSize}が取得せずに生値を取得したい場合に利用します。
  *
  * @param value NOT NULL
  * @return 要素2のString配列、第一要素[0]は座標部分、第二要素[1]はラベル部分
  * @throws TypeParseException valueがパースできなかった場合
  */
 public static String[] parseString(String value) throws TypeParseException {
   ArgumentChecker.throwIfNull(value);
   Matcher matched = condition_s_.matcher(value);
   if (!matched.matches()) {
     throw new TypeParseException("Bad argument value=\'" + value + '\''); // $NON-NLS-1$
   }
   return new String[] {matched.group(POSITION_POS), matched.group(LABEL_POS)};
 }
Exemplo n.º 9
0
 /**
  * stringにCODECクラスが記載されていない場合のデコーダーです。<br>
  * lastAttrが{@link LineCodec#isEncodable(Object)}で trueを返すCODESでデコードします。
  *
  * @param lastAttr
  * @param string
  * @return デコードされた結果。デコードに失敗した場合は<code>null</code>
  */
 public Object decode(Object lastAttr, String string) {
   ArgumentChecker.throwIfNull(lastAttr, string);
   for (LineCodec codec : codecMap_.values()) {
     if (codec.isEncodable(lastAttr)) {
       return codec.decode(string);
     }
   }
   return null;
 }
Exemplo n.º 10
0
 /** @param giEnum */
 public void addEnum(GiEnum giEnum) {
   ArgumentChecker.throwIfNull(giEnum);
   List<GiEnum> list = enumMap_.get(giEnum.getSgfId());
   if (list == null) {
     list = new ArrayList<GiEnum>();
     enumMap_.put(giEnum.getSgfId(), list);
   }
   list.add(giEnum);
 }
Exemplo n.º 11
0
 /** @param size NOT NULL */
 StoneGroupImpl(final SgfSize size) {
   super();
   ArgumentChecker.throwIfNull(size);
   assert (size != null);
   size_ = size;
   stones_ = new HashSet<SgfPoint>();
   neighbors_ = new HashSet<SgfPoint>();
   lifePoints_ = new HashSet<SgfPoint>();
 }
Exemplo n.º 12
0
 /**
  * {@link #setLabel(String)}と{@link #setExpression(String)}を 同時に設定するコンストラクタです。
  *
  * @param label NOT NULL
  * @param expression NOT NULL
  */
 public GiItem(String label, String expression) {
   super();
   ArgumentChecker.throwIfNull(label, expression);
   emptyMap_ = new TreeMap<SgfId, String>();
   enumMap_ = new TreeMap<SgfId, List<GiEnum>>();
   giFormulae_ = new GiFormula[0];
   labelText_ = label;
   expression_ = expression;
 }
Exemplo n.º 13
0
 /**
  * アノテーションの場所を指定します。<br>
  * {@link #createContents(Composite)}より前に呼び出さないと効果がありません。
  *
  * @param alignment アノテーションの場所。NOT NULL
  * @throws org.unitarou.lang.NullArgumentException 引数(alignment)に<code>null</code>がある場合。
  */
 @Logging(level = LogLevel.WARN, contents = "createContents()後に呼ばれた場合")
 public final void setAlignment(Alignment alignment) {
   ArgumentChecker.throwIfNull(alignment);
   if (frame_ != null) {
     log_s_.log(WARN, "Widgit has already created(BUG)."); // $NON-NLS-1$
     return;
   }
   alignment_ = alignment;
 }
Exemplo n.º 14
0
  /* (non-Javadoc)
   * @see org.unitarou.swt.WidgetContainer#createContents(org.eclipse.swt.widgets.Composite)
   */
  public Control createContents(Composite parent) {
    ArgumentChecker.throwIfNull(parent);

    GridLayout layout;
    frame_ = new Composite(parent, SWT.NONE);
    switch (alignment_) {
      case TOP:
        layout = new GridLayout(1, true);
        layout.marginWidth = 2;
        layout.marginHeight = 2;
        frame_.setLayout(layout);
        annotationLabel_ = new Label(frame_, SWT.WRAP);
        annotationLabel_.setLayoutData(new GridData(SWT.CENTER, SWT.BOTTOM, true, true));
        boardControl_ = digestIgoBoardPanel_.createContents(frame_);
        boardControl_.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, true));
        break;

      case BOTTOM:
        layout = new GridLayout(1, true);
        layout.marginWidth = 2;
        layout.marginHeight = 2;
        frame_.setLayout(layout);
        boardControl_ = digestIgoBoardPanel_.createContents(frame_);
        boardControl_.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
        annotationLabel_ = new Label(frame_, SWT.WRAP);
        annotationLabel_.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, true));
        break;

      case LEFT:
        layout = new GridLayout(2, false);
        layout.marginWidth = 2;
        layout.marginHeight = 2;
        frame_.setLayout(layout);
        boardControl_ = digestIgoBoardPanel_.createContents(frame_);
        boardControl_.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, true));
        annotationLabel_ = new Label(frame_, SWT.WRAP);
        annotationLabel_.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, true));
        break;

      case RIGHT:
        layout = new GridLayout(2, false);
        layout.marginWidth = 2;
        layout.marginHeight = 2;
        frame_.setLayout(layout);
        annotationLabel_ = new Label(frame_, SWT.WRAP);
        annotationLabel_.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true));
        boardControl_ = digestIgoBoardPanel_.createContents(frame_);
        boardControl_.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true));
        break;

      default:
        assert false : "Unknown alignment type :" + alignment_; // $NON-NLS-1$
    }
    return frame_;
  }
Exemplo n.º 15
0
  /**
   * 引数をコーデックのクラス名つきでエンコードします。
   *
   * @param value NOT NULL
   * @return エンコードに失敗した場合、NULL。
   */
  public String encode(Object value) {
    ArgumentChecker.throwIfNull(value);

    for (LineCodec codec : codecMap_.values()) {
      if (codec.isEncodable(value)) {
        StringBuilder sb = new StringBuilder();
        sb.append(codec.getClass().getName()).append(SEPARATOR).append(codec.encode(value));
        return sb.toString();
      }
    }
    return null;
  }
Exemplo n.º 16
0
  /** @param properties */
  public void setLocalizedLabel(Properties properties) {
    ArgumentChecker.throwIfNull(properties);

    labelText_ = convert(labelText_, properties);

    for (int i = 0; i < giFormulae_.length; ++i) {
      giFormulae_[i].setLabel(properties);
    }
    for (SgfId key : emptyMap_.keySet()) {
      String value = emptyMap_.get(key);
      emptyMap_.put(key, convert(value, properties));
    }
  }
Exemplo n.º 17
0
 /**
  * {@link #encode(Object)}と異なりcodecのクラス名をつけません。
  *
  * @param value NOT NULL
  * @return エンコードに失敗した場合、NULL。
  */
 public String encodeNoCodec(Object value) {
   ArgumentChecker.throwIfNull(value);
   for (LineCodec codec : codecMap_.values()) {
     if (codec.isEncodable(value)) {
       String ret = codec.encode(value);
       if (codec instanceof EnumCodec) {
         ret = ret.substring(ret.indexOf(SEPARATOR) + 1);
       }
       return ret;
     }
   }
   return null;
 }
Exemplo n.º 18
0
  /**
   * @inheritDoc このクラスではパネルを正方形に使います。
   * @see IgoOutlinePanel#setSizeHint(Point)
   */
  public void setSizeHint(Point boardSize) {
    ArgumentChecker.throwIfNull(boardSize);

    GridData gridData;
    gridData = (GridData) frame_.getLayoutData();
    gridData.widthHint = boardSize.x;

    int margin = ((GridLayout) frame_.getLayout()).marginWidth;
    gridData = (GridData) boardControl_.getLayoutData();
    gridData.widthHint = boardSize.x - frame_.getBorderWidth() * 2 - margin * 2;
    gridData.heightHint = boardSize.y - frame_.getBorderWidth() * 2 - margin * 2;

    gridData = (GridData) annotationLabel_.getLayoutData();
    gridData.widthHint = boardSize.x - frame_.getBorderWidth() * 2 - margin * 2;
  }
Exemplo n.º 19
0
  /**
   * 指定したサイズ、手番で詰碁の{@link RootGameTree}を作成します。
   *
   * @param sgfSize 碁盤の大きさ
   * @param playerToPlay 次の手番
   * @return 作成した詰碁。NOT NULL
   * @throws org.unitarou.lang.NullArgumentException 引数が <code>null</code>の場合
   */
  public static RootGameTree createProblem(SgfSize sgfSize, SgfColor playerToPlay) {
    ArgumentChecker.throwIfNull(sgfSize, playerToPlay);

    RootGameTree rgt = new RootGameTree();
    rgt.setSize(sgfSize);
    rgt.setFileFormat(FileFormat.VERSION_4);
    rgt.setCharset(new SgfCharset(Charset.defaultCharset()));
    rgt.setGameMode(GameMode.IGO);
    rgt.setGameType(GameType.PROBLEM);
    rgt.setStyle(Style.SIBLINGS_SHOW_VAL);

    Node node = rgt.getSequence().getFirst();
    node.addProperty(SgfId.PLAYER_TO_PLAY.makeProperty(playerToPlay));
    return rgt;
  }
Exemplo n.º 20
0
  /* (non-Javadoc)
   * @see IgoOutlinePanel#setRootGameTree(RootGameTree)
   */
  public void setRootGameTree(RootGameTree rootGameTree) {
    ArgumentChecker.throwIfNull(rootGameTree);
    if (rootGameTree_ == rootGameTree) {
      return;
    }

    rootGameTree_ = rootGameTree;
    Result result = Result.parse(BasicFinder.findDatum(rootGameTree_.getSequence(), SgfId.RESULT));
    // 描画
    annotationLabel_.setText(
        FMT_ANNOTATION.get(
            rootGameTree.getGameType().displayName(),
            result.displayName(),
            new OutlineRgtLabelProvider().getLabel(rootGameTree_)));
    digestIgoBoardPanel_.updateImage(rootGameTree_);
  }
Exemplo n.º 21
0
  /**
   * このクラスのプライムコンストラクタです。
   *
   * @param collection
   * @param setChangedFlag
   * @throws org.unitarou.lang.NullArgumentException collectionがnullの場合。
   */
  public CollectionProxy(Collection collection, boolean setChangedFlag) {
    super();
    ArgumentChecker.throwIfNull(collection);
    collection_ = collection;
    listener_ = new CollectionListenerImpl();
    collection_.addListener(listener_);
    games_ = new ArrayList<RgtProxy>(collection_.size());
    for (int i = 0; i < collection_.size(); ++i) {
      games_.add(null);
    }
    activeRgtIndex_ = 0;

    if (setChangedFlag) { // 最初から編集済み扱いにする時のみ、全てを読み出す。
      for (int i = 0; i < collection_.size(); ++i) {
        initializeGame(i, true);
      }
    }
    isRgtEdited_ = false;
  }
Exemplo n.º 22
0
 /**
  * idsに含まれるプロパティのみをSGF形式にして返します。
  *
  * @param sequence
  * @param ids
  * @return NOT NULL
  */
 public static CharSequence pickOutToSgf(Sequence sequence, SgfId... ids) {
   ArgumentChecker.throwIfNull(sequence, ids);
   StringBuilder sb = new StringBuilder();
   for (Node node : sequence) {
     boolean hasProperty = false;
     int start = sb.length();
     for (SgfId sgfId : ids) {
       Property property = node.getProperty(sgfId);
       if (property != null) {
         sb.append(property.toSgf());
         hasProperty = true;
       }
     }
     if (hasProperty) {
       sb.insert(start, Sgfs.NODE_START_MARK);
     }
   }
   if (sb.length() != 0) {
     sb.insert(0, Sgfs.GAME_TREE_START_MARK).append(Sgfs.GAME_TREE_END_MARK);
   }
   return sb;
 }
Exemplo n.º 23
0
  /**
   * 指定したサイズ、置石で棋譜の{@link RootGameTree}を作成します。
   *
   * @param sgfSize 碁盤の大きさ
   * @param handicap 置石の数(0:互先, 1:定先、2:二子…)
   * @return 作成した棋譜。NOT NULL
   * @throws org.unitarou.lang.NullArgumentException 引数が <code>null</code>の場合
   * @throws IllegalArgumentException sgfSizeが正方形以外でnumberが2以上の場合
   */
  public static RootGameTree createGame(SgfSize sgfSize, Handicap handicap) {
    ArgumentChecker.throwIfNull(sgfSize, handicap);

    RootGameTree rgt = new RootGameTree();
    rgt.setSize(sgfSize);
    rgt.setFileFormat(FileFormat.VERSION_4);
    rgt.setCharset(new SgfCharset(Charset.defaultCharset()));
    rgt.setGameMode(GameMode.IGO);
    rgt.setGameType(GameType.GAME);
    rgt.setStyle(Style.SIBLINGS_SHOW_VAL);

    Node node = rgt.getSequence().getFirst();
    node.addProperty(SgfId.HANDICAP.makeProperty(handicap));
    node.addProperty(
        SgfId.PLAYER_TO_PLAY.makeProperty(
            (1 < handicap.getIntValue()) ? SgfColor.WHITE : SgfColor.BLACK));

    Set<SgfPoint> handicappedStones = composeHandicapStone(sgfSize, handicap);
    if (!handicappedStones.isEmpty()) {
      node.addProperty(SgfId.ADD_BLACK.makeProperty(handicappedStones));
    }
    return rgt;
  }
Exemplo n.º 24
0
  /**
   * @param size
   * @param value
   * @return NOT NULL
   * @throws TypeParseException valueがパースできなかった場合
   * @throws org.unitarou.lang.NullArgumentException 引数がnullの場合
   */
  public static Label parse(SgfSize size, String value) throws TypeParseException {
    ArgumentChecker.throwIfNull(size, value);

    String[] parsed = parseString(value);
    return new Label(SgfPoint.parseMove(size, parsed[0]), SimpleText.parse(parsed[1]));
  }
Exemplo n.º 25
0
 /**
  * labelに合わせて表示する項目を決定します。
  *
  * @param label NOT NULL
  * @throws org.unitarou.lang.NullArgumentException 引数の何れか一つでもnullの場合。
  */
 public void setLabel(String label) {
   ArgumentChecker.throwIfNull(label);
   labelText_ = label;
 }
Exemplo n.º 26
0
 /**
  * expressionに合わせて表示する項目を決定します。<br>
  * expression はプロパティのIDとフリーテキストの混成表現で、 例えば次のような形式になります:<code>WN [WR]</code>。
  * この場合、最初に白の名前が表示され、ついでスペースとカギ括弧'['が 表示され、その後ろに白の段級位が表示され、最後にカギ括弧']'が表示されます。
  *
  * @param expression NOT NULL
  * @throws org.unitarou.lang.NullArgumentException 引数の何れか一つでもnullの場合。
  */
 public void setExpression(String expression) {
   ArgumentChecker.throwIfNull(expression);
   expression_ = expression;
 }
Exemplo n.º 27
0
 /**
  * (石が取り上げられたので)ダメを増やします。
  *
  * @param point ダメの場所、NOT NULL
  */
 void addLifePoint(SgfPoint point) {
   ArgumentChecker.throwIfNull(point);
   lifePoints_.add(point);
 }
Exemplo n.º 28
0
 /** @param empty */
 public void addEmpty(GiEmpty empty) {
   ArgumentChecker.throwIfNull(empty);
   emptyMap_.put(empty.getSgfId(), empty.getValue());
 }
Exemplo n.º 29
0
 /**
  * 引数でインスタンスの表示を更新します。
  *
  * @param node
  */
 public void currentChanged(Node node) {
   ArgumentChecker.throwIfNull(node);
   for (int i = 0; i < giFormulae_.length; ++i) {
     giFormulae_[i].currentChanged(node);
   }
 }
Exemplo n.º 30
0
 /**
  * @param point NOT NULL
  * @param simpleText NOT NULL
  * @throws org.unitarou.lang.NullArgumentException 引数がnullの場合
  */
 public Label(SgfPoint point, SimpleText simpleText) {
   super();
   ArgumentChecker.throwIfNull(point, simpleText);
   point_ = point;
   label_ = simpleText;
 }