자체 디자인 모델 - 문제 풀이 카드 모델

11009 단어
이 모델 은 트리거 조건 과 트리거 결과 의 디 결합 을 해결 하 는 동시에 트리거 조건 자원 의 방출 가능성 을 동시에 고려 합 니 다.촉발 결 과 를 얻 기 위해 서다.
/**
 * 
 */
package com.baidu.coolapp.answer;

import java.util.Hashtable;

import com.baidu.coolapp.composite.IComposite;

/**
 * @author liweigao
 *
 */
public interface IJury extends IComposite> {
	void check();
	Hashtable> getResults();
	Hashtable> getQuestions();
}
/**
 * 
 */
package com.baidu.coolapp.answer;

/**
 * @author liweigao
 *
 */
public interface IResult {
	void setResult(T result);
	T getResult();
	void setTag(String tag);
	String getTag();
}
/**
 * 
 */
package com.baidu.coolapp.answer;

/**
 * @author liweigao
 *
 */
public interface IQuestion {
	T answer();
	IResult createResult(Object... args);
	String getTag();
}
/**
 * 
 */
package com.baidu.coolapp.answer;

/**
 * @author liweigao 2014 11 20 
 * @param 
 */
public abstract class AResult implements IResult {
	private T mResult;
	private String mTag;

	/*
	 * (non-Javadoc)
	 * 
	 * @see common.share.lwg.trueorfalse.IResult#setTag(java.lang.String)
	 */
	@Override
	public void setTag(String tag) {
		this.mTag = tag;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see common.share.lwg.trueorfalse.IResult#getTag()
	 */
	@Override
	public String getTag() {
		// TODO Auto-generated method stub
		return this.mTag;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see common.share.lwg.answer.IResult#setResult(java.lang.Object)
	 */
	@Override
	public void setResult(T result) {
		this.mResult = result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see common.share.lwg.answer.IResult#getResult()
	 */
	@Override
	public T getResult() {
		return this.mResult;
	}

}
/**
 * 
 */
package com.baidu.coolapp.answer;

/**
 * @author liweigao
 *
 */
public abstract class AQuestion implements IQuestion {
	private String mTag;
	
	public AQuestion(String tag) {
		this.mTag = tag;
	}

	/* (non-Javadoc)
	 * @see common.share.lwg.trueorfalse.IQuestion#getTag()
	 */
	@Override
	public String getTag() {
		// TODO Auto-generated method stub
		return this.mTag;
	}

}
/**
 * 
 */
package com.baidu.coolapp.answer;

import java.util.Enumeration;
import java.util.Hashtable;

/**
 * @author liweigao
 * 
 */
public abstract class AJury implements IJury {
	private Hashtable> mQuestions = new Hashtable>();
	private Hashtable> mResults = new Hashtable>();

	/*
	 * (non-Javadoc)
	 * 
	 * @see common.share.lwg.composite.IComposite#add(java.lang.Object)
	 */
	@Override
	public void add(IQuestion> object) {
		String addTag = object.getTag();
		this.mQuestions.put(addTag, object);
		IResult> result = object.createResult();
		result.setTag(addTag);
		this.mResults.put(addTag, result);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see common.share.lwg.composite.IComposite#remove(java.lang.Object)
	 */
	@Override
	public void remove(IQuestion> object) {
		String tag = object.getTag();
		this.mQuestions.remove(tag);
		this.mResults.remove(tag);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see common.share.lwg.trueorfalse.Ireferee#check()
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
    @Override
	public void check() {
		Enumeration> enus = mQuestions.elements();
		while (enus.hasMoreElements()) {
			IQuestion> question = enus.nextElement();
			String tag = question.getTag();
			IResult result = mResults.get(tag);
			result.setResult(question.answer());
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see common.share.lwg.answer.IJury#getResults()
	 */
	@Override
	public Hashtable> getResults() {
		return this.mResults;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see common.share.lwg.answer.IJury#getQuestions()
	 */
	@Override
	public Hashtable> getQuestions() {
		return this.mQuestions;
	}

}
/**
 * 
 */
package com.baidu.coolapp.config.answer.sweetbox;

import com.baidu.coolapp.config.mediator.IConfigColleague;

/**
 * @author liweigao
 * 2014 11 21 
 */
public class ResultBean {
	private IConfigColleague mSweetFile;
	private IConfigColleague mBoxFile;
	private boolean mNeedMerge = false;
	private boolean mNeedUpload = true;
	private boolean mNeedLoadConfig = false;
	
	/**
	 * @return the sweetFile
	 */
	public IConfigColleague getSweetFile() {
		return mSweetFile;
	}
	/**
	 * @param sweetFile the sweetFile to set
	 */
	public void setSweetFile(IConfigColleague sweetFile) {
		this.mSweetFile = sweetFile;
	}
	/**
	 * @return the boxFile
	 */
	public IConfigColleague getBoxFile() {
		return mBoxFile;
	}
	/**
	 * @param boxFile the boxFile to set
	 */
	public void setBoxFile(IConfigColleague boxFile) {
		this.mBoxFile = boxFile;
	}
	/**
	 * @return the needMerge
	 */
	public boolean isNeedMerge() {
		return mNeedMerge;
	}
	/**
	 * @param needMerge the needMerge to set
	 */
	public void setNeedMerge(boolean needMerge) {
		this.mNeedMerge = needMerge;
	}
	/**
	 * @return the needUpload
	 */
	public boolean isNeedUpload() {
		return mNeedUpload;
	}
	/**
	 * @param needUpload the needUpload to set
	 */
	public void setNeedUpload(boolean needUpload) {
		this.mNeedUpload = needUpload;
	}
	/**
	 * @return the needLoadConfig
	 */
	public boolean isNeedLoadConfig() {
		return mNeedLoadConfig;
	}
	/**
	 * @param needLoadConfig the needLoadConfig to set
	 */
	public void setNeedLoadConfig(boolean needLoadConfig) {
		this.mNeedLoadConfig = needLoadConfig;
	}
	
}
/**
 * 
 */
package com.baidu.coolapp.config.answer.sweetbox;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.Map;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.entity.StringEntity;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.baidu.java.HashMap;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.SyncHttpClient;
import com.baidu.coolapp.answer.AJury;
import com.baidu.coolapp.answer.IResult;
import com.baidu.coolapp.config.mediator.ConfigMediator;
import com.baidu.coolapp.config.mediator.IConfigColleague;
import com.baidu.coolapp.config.merge.ConfigMergeProxy;
import com.baidu.coolapp.config.merge.IMergeProxy;
import com.baidu.coolapp.enumtype.FileEnum;
import com.baidu.coolapp.enumtype.Id;
import com.baidu.coolapp.enumtype.Key;
import com.baidu.coolapp.enumtype.Tag;
import com.baidu.coolapp.tools.JsonTool;
import com.baidu.coolapp.tools.PropertyTool;
import com.baidu.coolapp.tools.ResourceTool;
import com.baidu.coolapp.tools.UserTool;

/**
 * @author liweigao 2014 11 21 
 */
public class SweetBoxJury extends AJury {
	private ConfigMediator mConfigMediator;

	public SweetBoxJury(ConfigMediator mediator) {
		this.mConfigMediator = mediator;
	}

	public void checkTwoFile(IConfigColleague left, IConfigColleague right,
			Context context) {
		this.add(new SweetBoxQuestion(Tag.SWEET_BOX_QUESTION.getName(), left,
				right));
		this.check();
		ResultBean resultBean = getSweetBoxResultBean();
		if (resultBean.isNeedMerge()) {
			IConfigColleague sweet = resultBean.getSweetFile();
			IConfigColleague box = resultBean.getBoxFile();
			if (Id.SERVER_CONFIG.getId().equals(sweet.getId())
					|| Id.SERVER_CONFIG.getId().equals(box.getId())) {
				downLoadServerFile(context);
			} else {

			}
			mergeFile(sweet, box, context);
			if (Id.SERVER_CONFIG.getId().equals(box.getId())) {
				mConfigMediator.replaceFile(sweet, box);
			} else {

			}
			if (Id.BACK_CONFIG.getId().equals(box.getId())) {
				mConfigMediator.replaceFile(sweet, box);
			} else {

			}
		} else {
			IConfigColleague boxFile = resultBean.getBoxFile();
			if (Id.SERVER_CONFIG.getId().equals(boxFile.getId())) {
				downLoadServerFile(context);
				mConfigMediator.replaceFile(resultBean.getSweetFile(),
						resultBean.getBoxFile());
			} else {

			}
		}
	}

	private void mergeFile(IConfigColleague sweet, IConfigColleague box,
			Context context) {
		
	}

	private void downLoadServerFile(final Context context) {
		
	}

	@SuppressWarnings("unchecked")
	public IResult getSweetBoxResult() {
		IResult> result = this.getResults().get(
				Tag.SWEET_BOX_QUESTION.getName());
		return (IResult) result;
	}

	public ResultBean getSweetBoxResultBean() {
		return getSweetBoxResult().getResult();
	}

}
/**
 * 
 */
package com.baidu.coolapp.config.answer.sweetbox;

import com.baidu.coolapp.answer.AQuestion;
import com.baidu.coolapp.answer.IResult;
import com.baidu.coolapp.config.mediator.IConfigColleague;
import com.baidu.coolapp.enumtype.Id;

/**
 * @author liweigao
 * 2014 11 21 
 */
public class SweetBoxQuestion extends AQuestion {
	private IConfigColleague mLeft;
	private IConfigColleague mRight;

	/**
	 * @param tag
	 */
	public SweetBoxQuestion(String tag,IConfigColleague left,IConfigColleague right) {
		super(tag);
		this.mLeft = left;
		this.mRight = right;
	}

	/* (non-Javadoc)
	 * @see common.share.lwg.answer.IQuestion#answer()
	 */
	@Override
	public ResultBean answer() {
		ResultBean resultBean = new ResultBean();
		int leftVersion = mLeft.getVersion();
		int rightVersion = mRight.getVersion();
		long leftTime = mLeft.getTime();
		long rightTime = mRight.getTime();
		if(leftVersion > rightVersion) {
			resultBean.setBoxFile(mLeft);
			resultBean.setSweetFile(mRight);
			if(leftTime > rightTime) {
				resultBean.setNeedMerge(false);
			} else if(leftTime < rightTime) {
				resultBean.setNeedMerge(true);
			} else {
				resultBean.setNeedMerge(false);
			}
		} else if(leftVersion < rightVersion) {
			resultBean.setBoxFile(mRight);
			resultBean.setSweetFile(mLeft);
			if(leftTime > rightTime) {
				resultBean.setNeedMerge(true);
			} else if(leftTime < rightTime) {
				resultBean.setNeedMerge(false);
			} else {
				resultBean.setNeedMerge(false);
			}
		} else {
			if(leftTime > rightTime) {
				resultBean.setBoxFile(mLeft);
				resultBean.setSweetFile(mRight);
				resultBean.setNeedMerge(false);
			} else if(leftTime < rightTime) {
				resultBean.setBoxFile(mRight);
				resultBean.setSweetFile(mLeft);
				resultBean.setNeedMerge(false);
			} else {
				resultBean.setNeedMerge(false);
				resultBean.setNeedUpload(false);
				String leftId = mLeft.getId();
				if(leftId.equals(Id.SDCARD_CONFIG.getId())) {
					resultBean.setBoxFile(mLeft);
					resultBean.setSweetFile(mRight);
				} else {
					resultBean.setBoxFile(mRight);
					resultBean.setSweetFile(mLeft);
				}
			}
		}
		
		return resultBean;
	}

	/* (non-Javadoc)
	 * @see common.share.lwg.answer.IQuestion#createResult(java.lang.Object[])
	 */
	@Override
	public IResult createResult(Object... args) {
		return new SweetBoxResult();
	}

}
/**
 * 
 */
package com.baidu.coolapp.config.answer.sweetbox;

import com.baidu.coolapp.answer.AResult;

/**
 * @author liweigao
 * 2014 11 21 
 */
public class SweetBoxResult extends AResult {

}

좋은 웹페이지 즐겨찾기