자체 디자인 모델 - 문제 풀이 카드 모델
/**
*
*/
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 {
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.