Browse Source

提升代码质量

research/10.0
alex.sung 6 years ago
parent
commit
cb32d0b3ec
  1. 23
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineHelper.java
  2. 13
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/RobotModel.java
  3. 2
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java
  4. 21
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ComplementAdviceManager.java
  5. 6
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java
  6. 18
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java

23
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineHelper.java

@ -5,12 +5,17 @@ import com.fr.design.actions.help.alphafine.AlphaFineConfigManager;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel; import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import com.fr.design.mainframe.alphafine.cell.model.NoResultModel; import com.fr.design.mainframe.alphafine.cell.model.NoResultModel;
import com.fr.design.mainframe.alphafine.cell.model.RobotModel;
import com.fr.design.mainframe.alphafine.component.AlphaFineDialog; import com.fr.design.mainframe.alphafine.component.AlphaFineDialog;
import com.fr.design.mainframe.alphafine.model.SearchResult; import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.alphafine.search.manager.impl.RecentSearchManager; import com.fr.design.mainframe.alphafine.search.manager.impl.RecentSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.RecommendSearchManager; import com.fr.design.mainframe.alphafine.search.manager.impl.RecommendSearchManager;
import com.fr.general.ProcessCanceledException; import com.fr.general.ProcessCanceledException;
import com.fr.json.JSONArray;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.json.JSONUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import java.util.List; import java.util.List;
@ -97,5 +102,23 @@ public class AlphaFineHelper {
return filterResult; return filterResult;
} }
public static SearchResult getModelListFromJSONArray(String result, String keyword) throws ClassCastException, JSONException {
SearchResult allModelList = new SearchResult();
JSONArray jsonArray = (JSONArray)JSONUtils.jsonDecode(result);
for (int i = 0; i < jsonArray.length(); i++) {
AlphaFineHelper.checkCancel();
JSONObject jsonObject = jsonArray.optJSONObject(i);
String temp = jsonObject.optString(keyword);
if (StringUtils.isNotEmpty(temp)) {
RobotModel robotModel = new RobotModel(temp, null);
if (!allModelList.contains(robotModel)) {
allModelList.add(robotModel);
}
}
}
return allModelList;
}
} }

13
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/RobotModel.java

@ -7,6 +7,7 @@ import com.fr.general.http.HttpClient;
import com.fr.json.JSONException; import com.fr.json.JSONException;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.AssistUtils;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
@ -92,4 +93,16 @@ public class RobotModel extends AlphaCellModel {
FineLoggerFactory.getLogger().error(e.getMessage()); FineLoggerFactory.getLogger().error(e.getMessage());
} }
} }
@Override
public final boolean equals(Object obj) {
return obj instanceof RobotModel
&& AssistUtils.equals(this.title, ((RobotModel)obj).title)
&& AssistUtils.equals(this.content, ((RobotModel) obj).content);
}
@Override
public int hashCode() {
return AssistUtils.hashCode(title, content);
}
} }

2
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java

@ -1333,7 +1333,7 @@ public class AlphaFineDialog extends UIDialog {
*/ */
private void initBackPane() { private void initBackPane() {
backPane = new JPanel(new BorderLayout()); backPane = new JPanel(new BorderLayout());
JLabel jLabel = new JLabel(com.fr.design.i18n.Toolkit.i18nText(" < " + "Fine-Design_Report_AlphaFine_Back")); JLabel jLabel = new JLabel(" < " + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Back"));
jLabel.setPreferredSize(new Dimension(680, 20)); jLabel.setPreferredSize(new Dimension(680, 20));
jLabel.setFont(AlphaFineConstants.SMALL_FONT); jLabel.setFont(AlphaFineConstants.SMALL_FONT);
jLabel.setForeground(AlphaFineConstants.DARK_GRAY); jLabel.setForeground(AlphaFineConstants.DARK_GRAY);

21
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ComplementAdviceManager.java

@ -50,25 +50,10 @@ public class ComplementAdviceManager {
try { try {
String result = HttpToolbox.get(url); String result = HttpToolbox.get(url);
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
JSONArray jsonArray = (JSONArray)JSONUtils.jsonDecode(result); allModelList = AlphaFineHelper.getModelListFromJSONArray(result,"keywords");
if(jsonArray != null){ } catch(ClassCastException | JSONException e){
for (int i = 0; i < jsonArray.length(); i++) {
AlphaFineHelper.checkCancel();
JSONObject jsonObject = jsonArray.optJSONObject(i);
String temp = jsonObject.optString("keywords");
if (StringUtils.isNotEmpty(temp)) {
RobotModel robotModel = new RobotModel(temp, null);
if (!AlphaFineHelper.getFilterResult().contains(robotModel) && !allModelList.contains(robotModel)) {
allModelList.add(robotModel);
}
}
}
}
} catch (JSONException e) {
FineLoggerFactory.getLogger().error("complement advice search error: " + e.getMessage()); FineLoggerFactory.getLogger().error("complement advice search error: " + e.getMessage());
}catch (IOException e1) { } catch (IOException e1) {
FineLoggerFactory.getLogger().error("complement advice get result error: " + e1.getMessage()); FineLoggerFactory.getLogger().error("complement advice get result error: " + e1.getMessage());
} }
} }

6
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java

@ -193,7 +193,11 @@ public class RecommendSearchManager implements AlphaFineSearchProvider {
} }
public List<AlphaCellModel> getRecommendModelList() { public List<AlphaCellModel> getRecommendModelList() {
return recommendModelList; SearchResult result = new SearchResult();
result.addAll(recommendModelList);
result.addAll(modelList);
result.addAll(moreModelList);
return result;
} }
} }

18
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java

@ -15,6 +15,8 @@ import com.fr.json.JSONObject;
import com.fr.json.JSONUtils; import com.fr.json.JSONUtils;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import java.io.IOException; import java.io.IOException;
import com.fr.stable.StringUtils;
import com.fr.third.org.apache.commons.codec.digest.DigestUtils; import com.fr.third.org.apache.commons.codec.digest.DigestUtils;
/** /**
@ -47,20 +49,8 @@ public class SimilarSearchManeger implements AlphaFineSearchProvider {
try { try {
String result = HttpToolbox.get(url); String result = HttpToolbox.get(url);
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
JSONArray jsonArray = (JSONArray)JSONUtils.jsonDecode(result); allModelList = AlphaFineHelper.getModelListFromJSONArray(result,"title");
if(jsonArray != null){ } catch (ClassCastException | JSONException e) {
if (jsonArray.length() != 0) {
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.optJSONObject(i);
String title = jsonObject.optString("title");
RobotModel robotModel = new RobotModel(title, null);
if (!AlphaFineHelper.getFilterResult().contains(robotModel) && !allModelList.contains(robotModel)) {
allModelList.add(robotModel);
}
}
}
}
} catch (JSONException e) {
FineLoggerFactory.getLogger().error("similar search error: " + e.getMessage()); FineLoggerFactory.getLogger().error("similar search error: " + e.getMessage());
} catch (IOException e) { } catch (IOException e) {
FineLoggerFactory.getLogger().error("similar search get result error: " + e.getMessage()); FineLoggerFactory.getLogger().error("similar search get result error: " + e.getMessage());

Loading…
Cancel
Save