List of usage examples for org.apache.commons.lang3 StringUtils substringAfter
public static String substringAfter(final String str, final String separator)
Gets the substring after the first occurrence of a separator.
From source file:org.phenotips.vocabulary.internal.solr.MendelianInheritanceInMan.java
@Override public VocabularyTerm getTerm(String id) { VocabularyTerm result = super.getTerm(id); if (result == null) { String optionalPrefix = STANDARD_NAME + ":"; if (StringUtils.startsWith(id, optionalPrefix)) { result = getTerm(StringUtils.substringAfter(id, optionalPrefix)); }/* ww w.jav a 2s. co m*/ } return result; }
From source file:org.phenotips.vocabulary.internal.solr.MendelianInheritanceInMan.java
private void parseOmimData(URL sourceUrl) { try {/*from ww w . jav a2 s . c o m*/ Reader in = new InputStreamReader(sourceUrl.openConnection().getInputStream(), Charset.forName(ENCODING)); for (CSVRecord row : CSVFormat.TDF.withCommentMarker('#').parse(in)) { // Ignore moved or removed entries if ("Caret".equals(row.get(0))) { continue; } SolrInputDocument crtTerm = new SolrInputDocument(); // set id addFieldValue(ID_FIELD, row.get(1), crtTerm); // set symbol addFieldValue(SYMBOL_FIELD, SYMBOLS.get(row.get(0)), crtTerm); // set type (multivalued) for (String type : TYPES.get(row.get(0))) { addFieldValue(TYPE_FIELD, type, crtTerm); } // set name String name = StringUtils.substringBefore(row.get(2), TITLE_SEPARATOR).trim(); addFieldValue(NAME_FIELD, name, crtTerm); // set short name String shortNameString = StringUtils.substringAfter(row.get(2), TITLE_SEPARATOR).trim(); String[] shortNames = StringUtils.split(shortNameString, TITLE_SEPARATOR); for (String shortName : shortNames) { addFieldValue(SHORT_NAME_FIELD, shortName.trim(), crtTerm); } // set synonyms setListFieldValue(SYNONYM_FIELD, row.get(3), crtTerm); // set included name setListFieldValue(INCLUDED_NAME_FIELD, row.get(4), crtTerm); this.data.put(String.valueOf(crtTerm.get(ID_FIELD).getFirstValue()), crtTerm); } } catch (IOException ex) { this.logger.warn("Failed to read/parse the OMIM source: {}", ex.getMessage()); } }
From source file:org.phenotips.vocabulary.internal.solr.OmimSourceParser.java
private void loadField(String name, String value) { if (StringUtils.isAnyBlank(name, value)) { return;/*from w w w . j a v a 2 s . co m*/ } switch (name) { case FIELD_MIM_NUMBER: this.crtTerm.setField(ID_FIELD, value); break; case FIELD_TITLE: String title = StringUtils.substringBefore(value, TITLE_SEPARATOR).trim(); String[] synonyms = StringUtils.split(StringUtils.substringAfter(value, TITLE_SEPARATOR), TITLE_SEPARATOR); this.crtTerm.setField(NAME_FIELD, title); for (String synonym : synonyms) { this.crtTerm.addField(SYNONYM_FIELD, synonym.trim()); } break; case FIELD_TEXT: this.crtTerm.addField("def", value); break; default: return; } }
From source file:org.phenotips.vocabulary.internal.solr.OrphanetRareDiseaseOntology.java
/** * Extracts property hasDbXref from an {@link RDFNode} and adds it to the {@link SolrInputDocument}. * * @param doc the Solr input document for an {@link OntClass} of interest * @param object the {@link RDFNode} object contained within the {@link OntClass} of interest *//*from w w w . j a v a 2 s . c o m*/ private void extractDbxRef(@Nonnull final SolrInputDocument doc, @Nonnull final RDFNode object) { // If the node is not a literal, will throw a {@link LiteralRequiredException}. For ORDO, this is always a // literal. if (object.isLiteral()) { final String externalRef = object.asLiteral().getLexicalForm(); final String ontology = StringUtils.substringBefore(externalRef, SEPARATOR); final String externalId = StringUtils.substringAfter(externalRef, SEPARATOR); addMultivaluedField(doc, ontology.toLowerCase() + "_id", externalId); } }
From source file:org.polymap.rhei.fulltext.BoundsFilterQueryDecorator.java
@Override public Iterable<JSONObject> search(String query, int maxResults) throws Exception { String boundsJson = null;/*from w w w . j a v a2 s . c o m*/ String searchQuery = query; // extract bounds:{...} param from query Matcher matcher = boundsPattern.matcher(query); if (matcher.find()) { String boundsParam = query.substring(matcher.start(), matcher.end()); boundsJson = StringUtils.substringAfter(boundsParam, "bounds:"); searchQuery = StringUtils.remove(searchQuery, boundsParam); } // next Iterable<JSONObject> results = next.search(searchQuery, maxResults); // filter bounds if (boundsJson != null) { final Geometry bounds = jsonDecoder.read(new StringReader(boundsJson)); return Iterables.filter(results, new Predicate<JSONObject>() { public boolean apply(JSONObject feature) { try { Geometry geom = (Geometry) feature.opt(FIELD_GEOM); return geom != null ? bounds.contains(geom) : true; } catch (Exception e) { throw new RuntimeException(e); } } }); } else { return results; } }
From source file:org.rippleosi.common.util.DateFormatter.java
public static String combineDateTime(Date date, Date time) { String dateAsString = toString(date); String timeAsString = toString(time); if (dateAsString == null || timeAsString == null) { return null; }/*from w ww .j a v a 2 s . c om*/ return StringUtils.substringBefore(dateAsString, "T") + "T" + StringUtils.substringAfter(timeAsString, "T"); }
From source file:org.simplesite.commons.utils.excel.ImportExcel.java
/** * ??/*from ww w. ja v a 2 s . c o m*/ * @param cls * @param groups */ public <E> List<E> getDataList(Class<E> cls, int... groups) throws InstantiationException, IllegalAccessException { List<Object[]> annotationList = Lists.newArrayList(); // Get annotation field Field[] fs = cls.getDeclaredFields(); for (Field f : fs) { ExcelField ef = f.getAnnotation(ExcelField.class); if (ef != null && (ef.type() == 0 || ef.type() == 2)) { if (groups != null && groups.length > 0) { boolean inGroup = false; for (int g : groups) { if (inGroup) { break; } for (int efg : ef.groups()) { if (g == efg) { inGroup = true; annotationList.add(new Object[] { ef, f }); break; } } } } else { annotationList.add(new Object[] { ef, f }); } } } // Get annotation method Method[] ms = cls.getDeclaredMethods(); for (Method m : ms) { ExcelField ef = m.getAnnotation(ExcelField.class); if (ef != null && (ef.type() == 0 || ef.type() == 2)) { if (groups != null && groups.length > 0) { boolean inGroup = false; for (int g : groups) { if (inGroup) { break; } for (int efg : ef.groups()) { if (g == efg) { inGroup = true; annotationList.add(new Object[] { ef, m }); break; } } } } else { annotationList.add(new Object[] { ef, m }); } } } // Field sorting Collections.sort(annotationList, new Comparator<Object[]>() { public int compare(Object[] o1, Object[] o2) { return new Integer(((ExcelField) o1[0]).sort()).compareTo(new Integer(((ExcelField) o2[0]).sort())); }; }); //log.debug("Import column count:"+annotationList.size()); // Get excel data List<E> dataList = Lists.newArrayList(); for (int i = this.getDataRowNum(); i < this.getLastDataRowNum(); i++) { E e = (E) cls.newInstance(); int column = 0; Row row = this.getRow(i); StringBuilder sb = new StringBuilder(); for (Object[] os : annotationList) { Object val = this.getCellValue(row, column++); if (val != null) { ExcelField ef = (ExcelField) os[0]; // If is dict type, get dict value if (StringUtils.isNotBlank(ef.dictType())) { //val = DictUtils.getDictValue(val.toString(), ef.dictType(), ""); val = val == null ? "" : val.toString(); //log.debug("Dictionary type value: ["+i+","+colunm+"] " + val); } // Get param type and type cast Class<?> valType = Class.class; if (os[1] instanceof Field) { valType = ((Field) os[1]).getType(); } else if (os[1] instanceof Method) { Method method = ((Method) os[1]); if ("get".equals(method.getName().substring(0, 3))) { valType = method.getReturnType(); } else if ("set".equals(method.getName().substring(0, 3))) { valType = ((Method) os[1]).getParameterTypes()[0]; } } //log.debug("Import value type: ["+i+","+column+"] " + valType); try { if (valType == String.class) { val = String.valueOf(val.toString()); } else if (valType == Integer.class) { val = Double.valueOf(val.toString()).intValue(); } else if (valType == Long.class) { val = Double.valueOf(val.toString()).longValue(); } else if (valType == Double.class) { val = Double.valueOf(val.toString()); } else if (valType == Float.class) { val = Float.valueOf(val.toString()); } else if (valType == Date.class) { val = DateUtil.getJavaDate((Double) val); } else { if (ef.fieldType() != Class.class) { val = ef.fieldType().getMethod("getValue", String.class).invoke(null, val.toString()); } else { val = Class .forName(this.getClass().getName().replaceAll( this.getClass().getSimpleName(), "fieldtype." + valType.getSimpleName() + "Type")) .getMethod("getValue", String.class).invoke(null, val.toString()); } } } catch (Exception ex) { log.info("Get cell value [" + i + "," + column + "] error: " + ex.toString()); val = null; } // set entity value if (os[1] instanceof Field) { Reflections.invokeSetter(e, ((Field) os[1]).getName(), val); } else if (os[1] instanceof Method) { String mthodName = ((Method) os[1]).getName(); if ("get".equals(mthodName.substring(0, 3))) { mthodName = "set" + StringUtils.substringAfter(mthodName, "get"); } Reflections.invokeMethod(e, mthodName, new Class[] { valType }, new Object[] { val }); } } sb.append(val + ", "); } dataList.add(e); log.debug("Read success: [" + i + "] " + sb.toString()); } return dataList; }
From source file:org.sleuthkit.autopsy.timeline.ui.detailview.AggregateEventNode.java
/** @param descrVis the level of description that should be displayed */ final void setDescriptionVisibility(DescriptionVisibility descrVis) { this.descrVis = descrVis; final int size = event.getEventIDs().size(); switch (descrVis) { case COUNT_ONLY: descrLabel.setText(""); countLabel.setText(String.valueOf(size)); break;//w ww .ja v a 2s . c om case HIDDEN: countLabel.setText(""); descrLabel.setText(""); break; default: case SHOWN: String description = event.getDescription(); description = parentEventNode != null ? " ..." + StringUtils.substringAfter(description, parentEventNode.getEvent().getDescription()) : description; descrLabel.setText(description); countLabel.setText(((size == 1) ? "" : " (" + size + ")")); // NON-NLS break; } }
From source file:org.sleuthkit.autopsy.timeline.ui.detailview.EventNodeBase.java
void showFullDescription(final int size) { countLabel.setText((size == 1) ? "" : " (" + size + ")"); // NON-NLS String description = getParentNode() .map(pNode -> " ..." + StringUtils.substringAfter(getEvent().getDescription(), parentNode.getDescription())) .orElseGet(getEvent()::getDescription); descrLabel.setText(description);// w ww . j a va 2 s . c o m }
From source file:org.sleuthkit.autopsy.timeline.ui.detailview.EventStripeNode.java
@Override void setDescriptionVisibiltiyImpl(DescriptionVisibility descrVis) { final int size = getEventStripe().getEventIDs().size(); switch (descrVis) { case HIDDEN:// w w w . ja v a 2 s .c o m countLabel.setText(""); descrLabel.setText(""); break; case COUNT_ONLY: descrLabel.setText(""); countLabel.setText(String.valueOf(size)); break; default: case SHOWN: String description = getEventStripe().getDescription(); description = parentNode != null ? " ..." + StringUtils.substringAfter(description, parentNode.getDescription()) : description; descrLabel.setText(description); countLabel.setText(((size == 1) ? "" : " (" + size + ")")); // NON-NLS break; } }