ContainsTest.java 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package com.szwl.model.utils.usaEquipment;
  2. import org.apache.commons.lang.StringUtils;
  3. public class ContainsTest {
  4. public static void main(String[] args) {
  5. String addr = "日本";
  6. String country = "美国";
  7. String location = "日本,韩国";
  8. ContainsTest containsTest = new ContainsTest();
  9. String s = containsTest.cTest(addr, country, location);
  10. System.out.println(s);
  11. }
  12. public String cTest(String addr, String country, String location) {
  13. boolean containsUserInput = true;
  14. // location 为空 / 不为空
  15. // country 是中国 / 不是中国
  16. if (StringUtils.isEmpty(location)) {
  17. if (country.equals("中国")) {
  18. return "国内必须精确到省";
  19. } else {
  20. containsUserInput = addr.contains(country);
  21. }
  22. } else {
  23. if (country.equals("中国")) {
  24. containsUserInput = addr.contains(location);
  25. } else {
  26. containsUserInput = addr.contains(country) || addr.contains(location) || location.contains(addr);
  27. }
  28. }
  29. if (!containsUserInput) { // 不包含,返回设备编号
  30. return "{" + 111 + "}";
  31. }
  32. return "nih";
  33. }
  34. }