List of usage examples for org.apache.commons.lang3 StringUtils remove
public static String remove(final String str, final char remove)
Removes all occurrences of a character from within the source string.
A null source string will return null .
From source file:syncthing.android.ui.sessionsettings.EditDevicePresenter.java
boolean validateDeviceId(CharSequence text, boolean strict) { int e = 0;/*from ww w . j av a 2s. c o m*/ if (StringUtils.isEmpty(text)) { e = R.string.the_device_id_cannot_be_blank; } else if (strict && !StringUtils.remove(text.toString(), ' ').matches(("^[- \\w\\s]{50,64}$"))) { e = R.string.the_entered_device_id_does_not_look_valid_it_should_be_a_52_or_56_character_string_consisting_of_letters_and_numbers_with_spaces_and_dashes_being_optional; } if (hasView()) { setDeviceIDError(e != 0 ? getView().getContext().getString(e) : null); } return e == 0; }
From source file:tut.pori.javadocer.JavadocerParameters.java
/** * Strips the given value of surrounding "" and resolves all constant references marked with [] * /* w w w .j av a 2 s . c om*/ * @param value * @return the value as its cleaned form * @throws IllegalArgumentException */ private static String resolveValue(String value) throws IllegalArgumentException { String retValue = StringUtils.remove(value, "\""); if (StringUtils.isBlank(retValue)) { LOGGER.debug("Blank value."); return null; } int valueLength = retValue.length(); StringBuilder valueBuilder = new StringBuilder(valueLength); StringBuilder resolveBuilder = new StringBuilder(valueLength); boolean inBrackets = false; for (int i = 0; i < valueLength; ++i) { char c = retValue.charAt(i); if (c == '[') { inBrackets = true; } else if (c == ']') { if (!inBrackets) { throw new IllegalArgumentException("Invalid value: " + value); } inBrackets = false; valueBuilder.append(lookupVariable(resolveBuilder.toString())); resolveBuilder.setLength(0); } else if (inBrackets) { resolveBuilder.append(c); } else { // not in brackets valueBuilder.append(c); } } if (inBrackets) { throw new IllegalArgumentException("Invalid value: " + value); } return valueBuilder.toString(); }
From source file:ubic.basecode.ontology.search.OntologySearch.java
/** * Will remove characters that jena is unable to parse. Will also escape and remove leading and trailing white space * (which also causes jena to die)/*from w ww .j ava 2 s. c om*/ * * @param toStrip the string to clean * @return */ public static String stripInvalidCharacters(String toStrip) { String result = StringUtils.strip(toStrip); for (char badChar : INVALID_CHARS) { result = StringUtils.remove(result, badChar); } /* * Queries cannot start with '*' or ? */ result = result.replaceAll("^\\**", ""); result = result.replaceAll("^\\?*", ""); return StringEscapeUtils.escapeJava(result).trim(); }
From source file:ubic.gemma.core.analysis.expression.diff.GeneDifferentialExpressionServiceImpl.java
@Override public ExperimentalFactorValueObject configExperimentalFactorValueObject(ExperimentalFactor ef) { ExperimentalFactorValueObject efvo = new ExperimentalFactorValueObject(ef.getId()); efvo.setName(ef.getName());//from w w w .ja v a 2 s .c o m efvo.setDescription(ef.getDescription()); Characteristic category = ef.getCategory(); if (category != null) { efvo.setCategory(category.getCategory()); efvo.setCategoryUri(category.getCategoryUri()); } Collection<FactorValue> fvs = ef.getFactorValues(); StringBuilder factorValuesAsString = new StringBuilder(StringUtils.EMPTY); for (FactorValue fv : fvs) { String fvName = fv.toString(); if (StringUtils.isNotBlank(fvName)) { factorValuesAsString.append(fvName).append(GeneDifferentialExpressionServiceImpl.FV_SEP); } } /* clean up the start and end of the string */ factorValuesAsString = new StringBuilder( StringUtils.remove(factorValuesAsString.toString(), ef.getName() + ":")); factorValuesAsString = new StringBuilder(StringUtils.removeEnd(factorValuesAsString.toString(), GeneDifferentialExpressionServiceImpl.FV_SEP)); /* * Preformat the factor name; due to Ext PropertyGrid limitations we can't do this on the client. */ efvo.setName(ef.getName() + " (" + StringUtils.abbreviate(factorValuesAsString.toString(), 50) + ")"); efvo.setFactorValues(factorValuesAsString.toString()); return efvo; }
From source file:ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject.java
public ExperimentalFactorValueObject(ExperimentalFactor factor) { super(factor.getId()); this.setName(factor.getName()); this.setDescription(factor.getDescription()); if (factor.getCategory() != null) this.setCategory(factor.getCategory().getCategory()); this.setCategoryUri(this.getCategoryUri(factor.getCategory())); /*//from w w w. ja va 2 s.c o m * Note: this code copied from the ExperimentalDesignController. */ Collection<FactorValueValueObject> vals = new HashSet<>(); if (factor.getType() != null) { this.type = factor.getType().equals(FactorType.CATEGORICAL) ? "categorical" : "continuous"; } else { // Backwards compatibility: for old entries created prior to introduction of 'type' field in // ExperimentalFactor entity. // We have to take a guess. if (factor.getFactorValues().isEmpty()) { this.type = "categorical"; } else { // Just use first factor value to make our guess. if (factor.getFactorValues().iterator().next().getMeasurement() != null) { this.type = "continuous"; } else { this.type = "categorical"; } } } if (factor.getFactorValues() == null || factor.getFactorValues().isEmpty()) { return; } Collection<FactorValue> fvs = factor.getFactorValues(); StringBuilder factorValuesAsString = new StringBuilder(StringUtils.EMPTY); for (FactorValue fv : fvs) { String fvName = fv.toString(); if (StringUtils.isNotBlank(fvName)) { factorValuesAsString.append(fvName).append(", "); } } /* clean up the start and end of the string */ factorValuesAsString = new StringBuilder( StringUtils.remove(factorValuesAsString.toString(), factor.getName() + ":")); factorValuesAsString = new StringBuilder(StringUtils.removeEnd(factorValuesAsString.toString(), ", ")); this.setFactorValues(factorValuesAsString.toString()); this.numValues = factor.getFactorValues().size(); Characteristic c = factor.getCategory(); /* * NOTE this replaces code that previously made no sense. PP */ for (FactorValue value : factor.getFactorValues()) { vals.add(new FactorValueValueObject(value, c)); } this.setValues(vals); }
From source file:uk.co.inetria.gce.GceUsageParser.java
public void parse() throws FileNotFoundException, IOException { for (String file : files) { try (BufferedReader reader = new BufferedReader(new FileReader(file), BUF_SIZE);) { Iterable<CSVRecord> records = CSVFormat.DEFAULT.withHeader().withSkipHeaderRecord().parse(reader); for (CSVRecord record : records) { String measurement = StringUtils.remove(record.get(1), MEASURE_PREFIX); this.measurementIds.add(measurement); if (measurement.contains(VM) || measurement.contains(CONTAINER_ENGINE_VM)) { this.numberOfVms++; this.vms.add(record.get(4)); }//from www . j a v a 2 s . c om Usage usage = this.usages.get(measurement); if (usage == null) { usage = new Usage(); this.usages.put(measurement, usage); } long value = Long.parseLong(record.get(2)); usage.raw += value; if (measurement.contains(VM) || measurement.contains(CONTAINER_ENGINE_VM)) { // hourly based billing long adjusted = value; if (adjusted < HOUR) { adjusted = HOUR; } else if (adjusted % HOUR > 0) { adjusted = (long) (HOUR * Math.ceil(adjusted / (double) HOUR)); } usage.adjusted += adjusted; } } } } System.out.println("Unique measurements"); for (String measureId : this.measurementIds) { System.out.println(measureId); } System.out.println("Total number of started VMs: " + this.numberOfVms); System.out.println("Total number of unique VMs: " + this.vms.size()); for (String vmId : this.vms) { System.out.println(vmId); } System.out.println("Aggregated usage"); System.out.println("MeasurementId,Quantity,Per-hour Quantity"); for (Entry<String, Usage> entry : this.usages.entrySet()) { Usage usage = entry.getValue(); System.out.println(entry.getKey() + ',' + usage.raw + ',' + usage.adjusted); } }
From source file:wo.trade.SearchPageScraper.java
public List<TradeItem> parse() { List<TradeItem> tradeItems = new LinkedList<>(); Document doc = Jsoup.parse(page, "UTF-8"); Element content = doc.getElementById("content"); Elements items = null;//from ww w. jav a 2s . co m if (content == null) { items = doc.getElementsByClass("item"); } else { items = content.getElementsByClass("item"); } for (Element element : items) { TradeItem item = new TradeItem(); item.id = element.attr("id"); item.id = StringUtils.remove(item.id, "item-container-"); item.seller = element.attr("data-seller"); item.thread = element.attr("data-thread"); item.sellerid = element.attr("data-sellerid"); item.buyout = element.attr("data-buyout"); item.ign = element.attr("data-ign"); item.league = element.attr("data-league"); item.name = element.attr("data-name"); item.corrupted = element.getElementsByClass("corrupted").size() > 0; item.identified = element.getElementsByClass("item-unid").size() == 0; // System.out.println(String.format("Now parsing item id %s name %s", item.id, item.name)); Element sockElem = element.getElementsByClass("sockets-raw").get(0); item.socketsRaw = sockElem.text(); Elements accntAgeElement = element.getElementsByAttributeValue("title", "account age and highest level"); if (accntAgeElement != null && !accntAgeElement.isEmpty()) { item.ageAndHighLvl = accntAgeElement.get(0).text(); } // ----- Requirements ----- // Element reqElem = element.getElementsByClass("requirements").get(0); List<TextNode> reqNodes = reqElem.textNodes(); for (TextNode reqNode : reqNodes) { // sample [ Level: 37 , Strength: 42 , Intelligence: 42 ] String req = StringUtils.trimToEmpty(reqNode.getWholeText()); req = req.replaceAll(regex_horizontal_whitespace, ""); req = Util.removeThoseDamnWhiteSpace(req); String separator = ":"; String reqType = trim(substringBefore(req, separator)); switch (reqType) { case "Level": item.reqLvl = trim(substringAfter(req, separator)); break; case "Strength": item.reqStr = trim(substringAfter(req, separator)); break; case "Intelligence": item.reqInt = trim(substringAfter(req, separator)); break; case "Dexterity": item.reqDex = trim(substringAfter(req, separator)); break; } } item.mapQuantity = element.getElementsByAttributeValue("data-name", "mapq").stream().findFirst() .map(n -> n.text()).map(s -> substringAfter(s, "Item quantity:")) .map(s -> StringUtils.removePattern(s, "[^\\d]")).orElse("") .replaceAll(regex_horizontal_whitespace, "").trim(); // ----- Rarity by checking the item name link class ----- // // itemframe0 - normal // itemframe1 - magic // itemframe2 - rare // itemframe3 - unique // itemframe4 - gems // itemframe5 - currency // itemframe6 - divination card String itemframeStr = element.getElementsByClass("title").stream().findFirst().map(n -> n.attr("class")) .orElse(null); itemframeStr = Util.regexMatch("itemframe(\\d)", itemframeStr, 1); if (itemframeStr != null) { int frame = Integer.parseInt(itemframeStr); item.rarity = Rarity.valueOf(frame); } else { item.rarity = Rarity.unknown; } // ----- Verify ----- // item.dataHash = element.getElementsByAttributeValue("onclick", "verify_modern(this)").stream() .findFirst().map(n -> n.attr("data-hash")).orElse("").trim(); // ----- Mods ----- // Elements itemModsElements = element.getElementsByClass("item-mods"); if (itemModsElements != null && itemModsElements.size() > 0) { Element itemMods = itemModsElements.get(0); if (itemMods.getElementsByClass("bullet-item").size() != 0) { Element bulletItem = itemMods.getElementsByClass("bullet-item").get(0); Elements ulMods = bulletItem.getElementsByTag("ul"); if (ulMods.size() == 2) { // implicit mod Elements implicitLIs = ulMods.get(0).getElementsByTag("li"); Element implicitLi = implicitLIs.last(); Mod impMod = new Mod(implicitLi.attr("data-name"), implicitLi.attr("data-value")); item.implicitMod = impMod; } int indexOfExplicitMods = ulMods.size() - 1; Elements modsLi = ulMods.get(indexOfExplicitMods).getElementsByTag("li"); for (Element modLi : modsLi) { // explicit mods Mod mod = new Mod(modLi.attr("data-name"), modLi.attr("data-value")); item.explicitMods.add(mod); } } } // ----- Properties ----- // // this is the third column data (the first col is the image, second is the mods, reqs) item.quality = element.getElementsByAttributeValue("data-name", "q").get(0).text() .replaceAll(regex_horizontal_whitespace, "").trim(); item.physDmgRangeAtMaxQuality = element.getElementsByAttributeValue("data-name", "quality_pd").get(0) .text().replaceAll(regex_horizontal_whitespace, "").trim(); item.eleDmgRange = element.getElementsByAttributeValue("data-name", "ed").get(0).text() .replaceAll(regex_horizontal_whitespace, "").trim(); item.attackSpeed = element.getElementsByAttributeValue("data-name", "aps").get(0).text() .replaceAll(regex_horizontal_whitespace, "").trim(); item.dmgAtMaxQuality = element.getElementsByAttributeValue("data-name", "quality_dps").get(0).text() .replaceAll(regex_horizontal_whitespace, "").trim(); item.physDmgAtMaxQuality = element.getElementsByAttributeValue("data-name", "quality_pdps").get(0) .text().replaceAll(regex_horizontal_whitespace, "").trim(); item.eleDmg = element.getElementsByAttributeValue("data-name", "edps").get(0).text() .replaceAll(regex_horizontal_whitespace, "").trim(); item.armourAtMaxQuality = element.getElementsByAttributeValue("data-name", "quality_armour").get(0) .text().replaceAll(regex_horizontal_whitespace, "").trim(); item.evasionAtMaxQuality = element.getElementsByAttributeValue("data-name", "quality_evasion").get(0) .text().replaceAll(regex_horizontal_whitespace, "").trim(); item.energyShieldAtMaxQuality = element.getElementsByAttributeValue("data-name", "quality_shield") .get(0).text().replaceAll(regex_horizontal_whitespace, "").trim(); item.block = element.getElementsByAttributeValue("data-name", "block").get(0).text() .replaceAll(regex_horizontal_whitespace, "").trim(); item.crit = element.getElementsByAttributeValue("data-name", "crit").get(0).text() .replaceAll(regex_horizontal_whitespace, "").trim(); item.level = element.getElementsByAttributeValue("data-name", "level").get(0).text() .replaceAll(regex_horizontal_whitespace, "").trim(); item.imageUrl = element.getElementsByAttributeValue("alt", "Item icon").get(0).attr("src"); item.stackSize = asList(split(trimToEmpty(item.imageUrl), '&')).stream() .filter(t -> t.startsWith("stackSize=")).findFirst().map(s -> substringAfter(s, "=")) .orElse(null); Elements onlineSpans = element.getElementsMatchingText("online"); if (!onlineSpans.isEmpty()) { item.online = "Online"; } else { item.online = ""; } tradeItems.add(item); } // System.out.println("DONE --- Items"); return tradeItems; }