每日AC-leetcode word-break-ii -与dubbo 异步回调问题
来源:互联网 发布:淘宝美工和室内设计师 编辑:程序博客网 时间:2024/06/03 15:08
每日AC-leetcode word-break-ii -与dubbo 异步回调问题
题目描述
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.
Return all such possible sentences.
For example, given
s ="catsanddog",
dict =["cat", "cats", "and", "sand", "dog"].
A solution is["cats and dog", "cat sand dog"].
未AC代码:相对来说比较诡异,总之AC不了, 等待解决
import java.util.ArrayList;import java.util.HashMap;import java.util.HashSet;import java.util.Map;import java.util.Set;/** * 类说明 * * <pre> * Modify Information: * Author Date Description * ============ =========== ============================ * DELL 2017年7月20日 Create this file * </pre> * */public class WordBreak { /** * @param args */ public static void main(String[] args) { String s = "catsanddog"; // String dict ="cat, cats, and, sand, dog"; Set<String> set = new HashSet<String>(); set.add("cat"); set.add("cats"); set.add("and"); set.add("sand"); set.add("dog"); ArrayList<String> list = wordBreak(s, set); for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } } public static ArrayList<String> wordBreak(String s, Set<String> dict) { // ArrayList<String> list = new ArrayList<String>(); Map<String, ArrayList> map = new HashMap<String, ArrayList>(); ArrayList<String> pos = dp(s, dict, map); /* * for(int i = 0; i < s.length();i++){ ArrayList<String> pos = dp(i, * s.length(),s, dict); String str = s.substring(i,pos); list.add(str); * if(pos != s.length()-1){ * * } } */ return pos; } /** * @param i * @param length * @param s * @param dict * @return */ public static ArrayList<String> dp(String s, Set<String> dict, Map<String, ArrayList> map) { ArrayList<String> list = new ArrayList<String>(); int len = s.length(); if (null != map.get(s)) { return map.get(s); } if ("".equals(s) || null == s) { list.add(""); } else { for (int k = 1; k <= len; ++k) { String str = s.substring(0, k); if (dict.contains(str)) { ArrayList<String> sublist = dp(s.substring(k, len), dict, map); if (sublist.size() != 0) { for (int j = 0; j < sublist.size(); j++) { String strbuilder = new String(); String subStr = sublist.get(j); strbuilder += str + " " + subStr + " "; list.add(strbuilder.trim()); } } else { continue; } } } } map.put(s, list); return list; }}
关于Dubbo 异步回调这个问题, 暂时不详细说:
配置文件:
<dubbo:reference id="statExternalService" interface="cpcn.payment.statement.api.rpc.statexternal.StatExternalService" version="1.0.1" cluster="failfast" connections="1" > <dubbo:method name="tx1001" async="true" onreturn = "statementExternalServiceImpl.onReturn" onthrow="statementExternalServiceImpl.onThrow" /> </dubbo:reference> <!-- <dubbo:reference id="statExternalService1" interface="cpcn.payment.statement.api.rpc.statexternal.StatExternalService" version="1.0.1"> <dubbo:method name="tx1001" async="true" /> </dubbo:reference> -->
定义回调接口:
import cpcn.payment.statement.api.rpc.statexternal.Stat1001Request;import cpcn.payment.statement.api.rpc.statexternal.Stat1001Response;/** * 类说明 * * <pre> * Modify Information: * Author Date Description * ============ =========== ============================ * wangming 2017年7月6日 Create this file * </pre> * */public interface StatementExternalService { /** * 服务端正常返回异步返回 返回 onReturn * * @param stat1001Request * @return * @throws Exception */ Stat1001Response onReturn(Stat1001Response stat1001Response,Stat1001Request stat1001Request) throws Exception; /** * 服务端出现异常,调用onThrow * * @param stat1001Request * @return * @throws Exception */ void onThrow(Throwable ex, Stat1001Request stat1001Request) throws Exception;}
实现回调接口函数:
import org.springframework.stereotype.Service;import cpcn.payment.settlement.async.StatementExternalService;import cpcn.payment.statement.api.rpc.statexternal.Stat1001Request;import cpcn.payment.statement.api.rpc.statexternal.Stat1001Response;/** * * <pre> * * 类说明: 异步回调方法 * Modify Information: * Author Date Description * ============ =========== ============================ * xiaoming 2017年7月6日 Create this file * * </pre> */@Service("statementExternalServiceImpl")public class StatementExternalServiceImpl implements StatementExternalService { @Override public Stat1001Response onReturn(Stat1001Response stat1001Response, Stat1001Request stat1001Request) throws Exception { System.out.println(stat1001Response); return stat1001Response; } @Override public void onThrow(Throwable ex, Stat1001Request stat1001Request) throws Exception { System.out.println(ex.getMessage()); System.out.println(stat1001Request); } }
代码调用:
Stat1001Response response = statExternalService.tx1001(request); Future<Stat1001Response> responseFuture = RpcContext.getContext().getFuture(); response = responseFuture.get();
阅读全文
0 0
- 每日AC-leetcode word-break-ii -与dubbo 异步回调问题
- [leetcode]Word Break II
- LeetCode:Word Break II
- Leetcode: Word Break II
- [LeetCode] Word Break II
- [LeetCode]Word Break II
- LeetCode | Word Break II
- [LeetCode] - Word Break II
- LeetCode - Word Break II
- Leetcode Word Break II
- [LeetCode] Word Break II
- Word Break II -- LeetCode
- LeetCode (Word Break II )
- Leetcode--Word Break II
- Leetcode: Word Break II
- LeetCode Word Break II
- Word Break II leetcode
- [leetcode]Word Break II
- hdu5934(tarjan缩点)
- volley请求框架的添加头信息/头信息解析
- String, StringBuffer,StringBuilder的区别
- ScrollView嵌套LinearLayout布局不能撑满全屏的问题
- centos7下的FastDFS5.09的安装与使用
- 每日AC-leetcode word-break-ii -与dubbo 异步回调问题
- 佳能图像处理软件(Canon Utilities ZoomBrowser EX)下载 v62.0官方版
- HDU 5361(最短路+并查集优化)
- 导入一个AndroidStudio工程作为一个Library Module
- 【LeetCode】500. Keyboard Row
- 洛谷 P3369 【模板】普通平衡树(Treap/SBT)
- Win10 系统时间错误
- Spring AOP实例
- 分配并注册主次设备号