com.mike.angry.dm.DataModel.java Source code

Java tutorial

Introduction

Here is the source code for com.mike.angry.dm.DataModel.java

Source

/**
 * Project: ShuduSolver
 * 
 * File Created at 2013-5-10
 * $Id$
 * 
 * Copyright 1999-2100 Alibaba.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package com.mike.angry.dm;

import java.util.ArrayList;
import java.util.List;

import org.springframework.util.Assert;

/**
 * @author haiquan.guhq
 */
public class DataModel {

    // 3*39?
    private Digital bigSquare[][] = new Digital[9][9];

    // 
    private List<List<RuleResolveResultDO>> fixedProcess = new ArrayList<List<RuleResolveResultDO>>();

    // ?
    private int initValued = 0;
    //
    private String path = null;

    public List<Digital> getBySquareNum(int num) {
        List<Digital> result = new ArrayList<Digital>();
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (bigSquare[i][j].getSquareNum() == num) {
                    result.add(bigSquare[i][j]);
                }
            }
        }

        Assert.isTrue(result.size() == 9,
                "one square num should be 9! num " + num + "result.size()" + result.size());

        return result;
    }

    public List<Digital> getByXPosition(int x) {
        List<Digital> result = new ArrayList<Digital>();
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (bigSquare[i][j].getX() == x) {
                    result.add(bigSquare[i][j]);
                }
            }
        }

        Assert.isTrue(result.size() == 9, "one square num should be 9! x " + x + "result.size()" + result.size());

        return result;

    }

    public List<Digital> getByYPosition(int y) {
        List<Digital> result = new ArrayList<Digital>();
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (bigSquare[i][j].getY() == y) {
                    result.add(bigSquare[i][j]);
                }
            }
        }
        Assert.isTrue(result.size() == 9, "one square num should be 9! y " + y + "result.size()" + result.size());

        return result;
    }

    /**
     * ?
     */
    public List<Digital> getNotDetermined() {
        List<Digital> result = new ArrayList<Digital>();
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (!bigSquare[i][j].isDetermined()) {
                    result.add(bigSquare[i][j]);
                }
            }
        }
        return result;
    }

    public Digital[][] getBigSquare() {
        return bigSquare;
    }

    @Override
    public DataModel clone() throws CloneNotSupportedException {
        // ??
        DataModel copiedDataModel = new DataModel();
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                Digital clone = bigSquare[i][j].clone();
                copiedDataModel.getBigSquare()[i][j] = clone;
            }
        }
        // ????
        copiedDataModel.initValued = this.initValued;
        copiedDataModel.path = this.path;

        // ?
        List<List<RuleResolveResultDO>> copiedProcess = new ArrayList<List<RuleResolveResultDO>>();

        for (int i = 0; i < fixedProcess.size(); i++) {
            List<RuleResolveResultDO> copiedDigs = new ArrayList<RuleResolveResultDO>();
            List<RuleResolveResultDO> dList = fixedProcess.get(i);

            for (RuleResolveResultDO oneDigital : dList) {
                copiedDigs.add(oneDigital.clone());
            }
            copiedProcess.add(copiedDigs);
        }
        copiedDataModel.fixedProcess = copiedProcess;

        return copiedDataModel;
    }

    public void setInitValued(int initValued) {
        this.initValued = initValued;
    }

    public int getInitValued() {
        return initValued;
    }

    public List<List<RuleResolveResultDO>> getFixedProcess() {
        return fixedProcess;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

}