List of usage examples for org.apache.commons.lang3 StringUtils splitByWholeSeparator
public static String[] splitByWholeSeparator(final String str, final String separator, final int max)
Splits the provided text into an array, separator string specified.
From source file:kenh.expl.functions.SplitByWholeSeparator.java
public String[] process(String str, String separator, int max) { return StringUtils.splitByWholeSeparator(str, separator, max); }
From source file:lolth.autohome.buy.AutohomeBuyInfoListTaskFetch.java
@Override protected void parsePage(Document doc, FetchTask task) throws Exception { Elements lis = doc.select("li.price-item"); for (Element li : lis) { AutohomeBuyInfoBean bean = new AutohomeBuyInfoBean(); bean.setUrl(task.getUrl());/*w w w . j a va 2s.c o m*/ bean.setForumId(task.getExtra()); // post id Elements id = li.select("div.price-share a.share"); if (!id.isEmpty()) { String idStr = id.first().attr("data-target"); idStr = StringUtils.substringAfterLast(idStr, "_"); if (StringUtils.isBlank(idStr)) { continue; } bean.setId(idStr); } // Elements user = li.select("div.user-name a"); if (!user.isEmpty()) { String userUrl = user.first().absUrl("href"); String userId = StringUtils.substringAfterLast(userUrl, "/"); String userName = user.first().text(); bean.setUserId(userId); bean.setUserUrl(userUrl); bean.setUserName(userName); } // ? Elements postTime = li.select("div.user-name span"); if (!postTime.isEmpty()) { bean.setPostTime(StringUtils.trim(StringUtils.substringBefore(postTime.first().text(), "?"))); } Elements dataLis = li.select("div.price-item-bd li"); for (Element dataLi : dataLis) { String data = dataLi.text(); if (StringUtils.startsWith(data, "")) { bean.setCar(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { bean.setPrice(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { bean.setGuidePrice(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "?")) { bean.setTotalPrice(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { bean.setPurchaseTax(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "?")) { bean.setCommercialInsurance(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { bean.setVehicleUseTax(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { bean.setCompulsoryInsurance(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { bean.setLicenseFee(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "?")) { bean.setPromotion(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { bean.setBuyTime(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { String area = StringUtils.trim(StringUtils.substringAfter(data, "")); String[] pAndC = StringUtils.splitByWholeSeparator(area, ",", 2); if (pAndC.length == 1) { bean.setBuyProvince(pAndC[0]); bean.setBuyCity(pAndC[0]); } if (pAndC.length == 2) { bean.setBuyProvince(pAndC[0]); bean.setBuyCity(pAndC[1]); } } if (StringUtils.startsWith(data, "")) { Elements level = dataLi.select("span.level"); // if (!level.isEmpty()) { bean.setSellerComment(level.first().text()); } // ? Elements seller = dataLi.select("a.title"); if (!seller.isEmpty()) { String sellerUrl = seller.first().absUrl("href"); String sellerName = seller.first().text(); String sellerId = StringUtils.substringAfterLast(sellerUrl, "/"); bean.setSellerId(sellerId); bean.setSellerName(sellerName); bean.setSellerUrl(sellerUrl); } // ? Elements sellerPhone = dataLi.select("em.phone-num"); if (!sellerPhone.isEmpty()) { bean.setSellerPhone(sellerPhone.first().text()); } // ? // Elements sellerAddress = dataLi.select("em.phone-num"); } if (StringUtils.startsWith(data, "?")) { bean.setBuyFeeling(StringUtils.trim(StringUtils.substringAfter(data, ""))); } } log.debug("Bean : {}", bean); bean.persistOnNotExist(); } }
From source file:lolthx.autohome.buy.AutohomePriceListFetch.java
@Override public void parse(String result, Task task) throws Exception { if (StringUtils.isBlank(result)) { return;//from w ww .j a v a2 s . co m } Date start = task.getStartDate(); Date end = task.getEndDate(); Document doc = Jsoup.parse(result); Elements lis = doc.select("li.price-item"); AutohomePriceInfoBean bean = new AutohomePriceInfoBean(); for (Element li : lis) { try { Elements postTimeEl = li.select("div.user-name span"); String postTime = ""; if (!postTimeEl.isEmpty()) { postTime = StringUtils.trim( StringUtils.substringBefore(postTimeEl.first().text(), "?").replaceAll("", "")); if (!isTime(postTime, start, end)) { continue; } } bean.setPostTime(postTime); bean.setUrl(task.getUrl()); bean.setForumId(StringUtils.substringBefore(task.getExtra(), ":")); bean.setProjectName(task.getProjectName()); bean.setKeyword(StringUtils.substringAfter(task.getExtra(), ":")); // post id Elements id = li.select("div.price-share a.share"); if (!id.isEmpty()) { String idStr = id.first().attr("data-target"); idStr = StringUtils.substringAfterLast(idStr, "_"); if (StringUtils.isBlank(idStr)) { continue; } bean.setId(idStr); } // Elements user = li.select("div.user-name a"); if (!user.isEmpty()) { String userUrl = user.first().absUrl("href"); String userId = StringUtils.substringAfterLast(userUrl, "/"); String userName = user.first().text(); bean.setUserId(userId); bean.setUserUrl(userUrl); bean.setUserName(userName); } Elements dataLis = li.select("div.price-item-bd li"); for (Element dataLi : dataLis) { String data = dataLi.text(); if (StringUtils.startsWith(data, "")) { bean.setCar(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { bean.setPrice(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { bean.setGuidePrice(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "?")) { bean.setTotalPrice(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { bean.setPurchaseTax(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "?")) { bean.setCommercialInsurance(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { bean.setVehicleUseTax(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { bean.setCompulsoryInsurance(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { bean.setLicenseFee(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "?")) { bean.setPromotion(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { bean.setBuyTime(StringUtils.trim(StringUtils.substringAfter(data, ""))); } if (StringUtils.startsWith(data, "")) { String area = StringUtils.trim(StringUtils.substringAfter(data, "")); String[] pAndC = StringUtils.splitByWholeSeparator(area, ",", 2); if (pAndC.length == 1) { bean.setBuyProvince(pAndC[0]); bean.setBuyCity(pAndC[0]); } if (pAndC.length == 2) { bean.setBuyProvince(pAndC[0]); bean.setBuyCity(pAndC[1]); } } if (StringUtils.startsWith(data, "")) { Elements level = dataLi.select("span.level"); // if (!level.isEmpty()) { bean.setSellerComment(level.first().text()); } // ? Elements seller = dataLi.select("a.title"); if (!seller.isEmpty()) { String sellerUrl = seller.first().absUrl("href"); String sellerName = seller.first().text(); String sellerId = StringUtils.substringAfterLast(sellerUrl, "/"); bean.setSellerId(sellerId); bean.setSellerName(sellerName); bean.setSellerUrl(sellerUrl); } // ? Elements sellerPhone = dataLi.select("em.phone-num"); if (!sellerPhone.isEmpty()) { bean.setSellerPhone(sellerPhone.first().text()); } // ? // Elements sellerAddress = // dataLi.select("em.phone-num"); } if (StringUtils.startsWith(data, "?")) { bean.setBuyFeeling(StringUtils.trim(StringUtils.substringAfter(data, ""))); } } bean.saveOnNotExist(); } catch (Exception e) { e.printStackTrace(); continue; } } }
From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableRuntimeContext.java
private static String checkAndReturnOffsetTermValue(String term, String name, int position, String fullOffsetKey) {/*from w ww .j a v a2 s . c om*/ final String[] parts = StringUtils.splitByWholeSeparator(term, OFFSET_KEY_VALUE_SEPARATOR, 2); Utils.checkState(parts.length == 2, String.format( "Illegal offset term for %s (position %d separated by %s). Should be in form %s%s<value>. Full offset: %s", name, position, OFFSET_TERM_SEPARATOR, name, OFFSET_KEY_VALUE_SEPARATOR, fullOffsetKey)); return parts[1]; }
From source file:org.diorite.utils.math.ByteRange.java
/** * Parses given string to range, string is valid range when contains 2 numbers (second greater than first) and splt char: <br> * " - ", " : ", " ; ", ", ", " ", ",", ";", ":", "-" * * @param string string to parse./*from www.j a v a 2 s . c om*/ * * @return parsed range or null. */ public static ByteRange valueOf(String string) { if (string.isEmpty()) { return null; } String[] nums = null; int i = 0; final boolean firstMinus = string.charAt(0) == '-'; if (firstMinus) { string = string.substring(1); } while ((i < SPLITS.length) && ((nums == null) || (nums.length != 2))) { nums = StringUtils.splitByWholeSeparator(string, SPLITS[i++], 2); } if ((nums == null) || (nums.length != 2)) { return null; } final Integer min = DioriteMathUtils.asInt(firstMinus ? ("-" + nums[0]) : nums[0]); if ((min == null) || (min < Byte.MIN_VALUE)) { return null; } final Integer max = DioriteMathUtils.asInt(nums[1]); if ((max == null) || (max > Byte.MAX_VALUE) || (min > max)) { return null; } return new ByteRange(min.byteValue(), max.byteValue()); }
From source file:org.diorite.utils.math.DoubleRange.java
/** * Parses given string to range, string is valid range when contains 2 numbers (second greater than first) and splt char: <br> * " - ", " : ", " ; ", ", ", " ", ",", ";", ":", "-" * * @param string string to parse.//from w w w . ja va2s. com * * @return parsed range or null. */ public static DoubleRange valueOf(String string) { if (string.isEmpty()) { return null; } String[] nums = null; int i = 0; final boolean firstMinus = string.charAt(0) == '-'; if (firstMinus) { string = string.substring(1); } while ((i < ByteRange.SPLITS.length) && ((nums == null) || (nums.length != 2))) { nums = StringUtils.splitByWholeSeparator(string, ByteRange.SPLITS[i++], 2); } if ((nums == null) || (nums.length != 2)) { return null; } final Double min = DioriteMathUtils.asDouble(firstMinus ? ("-" + nums[0]) : nums[0]); if (min == null) { return null; } final Double max = DioriteMathUtils.asDouble(nums[1]); if ((max == null) || (min > max)) { return null; } return new DoubleRange(min, max); }
From source file:org.diorite.utils.math.FloatRange.java
/** * Parses given string to range, string is valid range when contains 2 numbers (second greater than first) and splt char: <br> * " - ", " : ", " ; ", ", ", " ", ",", ";", ":", "-" * * @param string string to parse.//from w ww. j av a 2s . com * * @return parsed range or null. */ public static FloatRange valueOf(String string) { if (string.isEmpty()) { return null; } String[] nums = null; int i = 0; final boolean firstMinus = string.charAt(0) == '-'; if (firstMinus) { string = string.substring(1); } while ((i < ByteRange.SPLITS.length) && ((nums == null) || (nums.length != 2))) { nums = StringUtils.splitByWholeSeparator(string, ByteRange.SPLITS[i++], 2); } if ((nums == null) || (nums.length != 2)) { return null; } final Float min = DioriteMathUtils.asFloat(firstMinus ? ("-" + nums[0]) : nums[0]); if (min == null) { return null; } final Float max = DioriteMathUtils.asFloat(nums[1]); if ((max == null) || (min > max)) { return null; } return new FloatRange(min, max); }
From source file:org.diorite.utils.math.IntRange.java
/** * Parses given string to range, string is valid range when contains 2 numbers (second greater than first) and splt char: <br> * " - ", " : ", " ; ", ", ", " ", ",", ";", ":", "-" * * @param string string to parse./*w w w .j av a 2 s.c o m*/ * * @return parsed range or null. */ public static IntRange valueOf(String string) { if (string.isEmpty()) { return null; } String[] nums = null; int i = 0; final boolean firstMinus = string.charAt(0) == '-'; if (firstMinus) { string = string.substring(1); } while ((i < ByteRange.SPLITS.length) && ((nums == null) || (nums.length != 2))) { nums = StringUtils.splitByWholeSeparator(string, ByteRange.SPLITS[i++], 2); } if ((nums == null) || (nums.length != 2)) { return null; } final Integer min = DioriteMathUtils.asInt(firstMinus ? ("-" + nums[0]) : nums[0]); if (min == null) { return null; } final Integer max = DioriteMathUtils.asInt(nums[1]); if ((max == null) || (min > max)) { return null; } return new IntRange(min, max); }
From source file:org.diorite.utils.math.LongRange.java
/** * Parses given string to range, string is valid range when contains 2 numbers (second greater than first) and splt char: <br> * " - ", " : ", " ; ", ", ", " ", ",", ";", ":", "-" * * @param string string to parse.//from w w w . java 2 s . co m * * @return parsed range or null. */ public static LongRange valueOf(String string) { if (string.isEmpty()) { return null; } String[] nums = null; int i = 0; final boolean firstMinus = string.charAt(0) == '-'; if (firstMinus) { string = string.substring(1); } while ((i < ByteRange.SPLITS.length) && ((nums == null) || (nums.length != 2))) { nums = StringUtils.splitByWholeSeparator(string, ByteRange.SPLITS[i++], 2); } if ((nums == null) || (nums.length != 2)) { return null; } final Long min = DioriteMathUtils.asLong(firstMinus ? ("-" + nums[0]) : nums[0]); if (min == null) { return null; } final Long max = DioriteMathUtils.asLong(nums[1]); if ((max == null) || (min > max)) { return null; } return new LongRange(min, max); }
From source file:org.diorite.utils.math.ShortRange.java
/** * Parses given string to range, string is valid range when contains 2 numbers (second greater than first) and splt char: <br> * " - ", " : ", " ; ", ", ", " ", ",", ";", ":", "-" * * @param string string to parse./* w ww . ja v a 2 s . c o m*/ * * @return parsed range or null. */ public static ShortRange valueOf(String string) { if (string.isEmpty()) { return null; } String[] nums = null; int i = 0; final boolean firstMinus = string.charAt(0) == '-'; if (firstMinus) { string = string.substring(1); } while ((i < ByteRange.SPLITS.length) && ((nums == null) || (nums.length != 2))) { nums = StringUtils.splitByWholeSeparator(string, ByteRange.SPLITS[i++], 2); } if ((nums == null) || (nums.length != 2)) { return null; } final Integer min = DioriteMathUtils.asInt(firstMinus ? ("-" + nums[0]) : nums[0]); if ((min == null) || (min < Short.MIN_VALUE)) { return null; } final Integer max = DioriteMathUtils.asInt(nums[1]); if ((max == null) || (max > Short.MAX_VALUE) || (min > max)) { return null; } return new ShortRange(min.shortValue(), max.shortValue()); }