List of usage examples for org.apache.commons.lang3 StringUtils substringAfterLast
public static String substringAfterLast(final String str, final String separator)
Gets the substring after the last occurrence of a separator.
From source file:org.debux.webmotion.site.FileContent.java
public String getName() { return StringUtils.substringAfterLast(path, "/"); }
From source file:org.dkpro.core.io.rdf.internal.Rdf2Uima.java
public static FeatureStructure convertFS(OntResource aFS, JCas aJCas, Map<Resource, FeatureStructure> aFsIndex) { FeatureStructure fs = aFsIndex.get(aFS); Iterator<Statement> stmtIter = aFS.listProperties(); for (Statement stmt : new IteratorIterable<Statement>(stmtIter)) { // Skip all non-features if (!stmt.getPredicate().getURI().startsWith("uima:")) { // System.out.println("Skipping: " + stmt); continue; }/*from w w w .ja v a 2s. c o m*/ String featureName = StringUtils.substringAfterLast(stmt.getPredicate().getURI(), "-"); Feature uimaFeat = fs.getType().getFeatureByBaseName(featureName); // Cannot update start/end of document annotation because that FS is already indexed, so // we skip those if (fs == aJCas.getDocumentAnnotationFs() && (CAS.FEATURE_BASE_NAME_BEGIN.equals(featureName) || CAS.FEATURE_BASE_NAME_END.equals(featureName))) { System.out.println("Skipping: " + stmt); continue; } if (uimaFeat.getRange().isPrimitive()) { switch (uimaFeat.getRange().getName()) { case CAS.TYPE_NAME_BOOLEAN: fs.setBooleanValue(uimaFeat, stmt.getObject().asLiteral().getBoolean()); break; case CAS.TYPE_NAME_BYTE: fs.setByteValue(uimaFeat, stmt.getObject().asLiteral().getByte()); break; case CAS.TYPE_NAME_DOUBLE: fs.setDoubleValue(uimaFeat, stmt.getObject().asLiteral().getDouble()); break; case CAS.TYPE_NAME_FLOAT: fs.setFloatValue(uimaFeat, stmt.getObject().asLiteral().getFloat()); break; case CAS.TYPE_NAME_INTEGER: fs.setIntValue(uimaFeat, stmt.getObject().asLiteral().getInt()); break; case CAS.TYPE_NAME_LONG: fs.setLongValue(uimaFeat, stmt.getObject().asLiteral().getLong()); break; case CAS.TYPE_NAME_SHORT: fs.setShortValue(uimaFeat, stmt.getObject().asLiteral().getShort()); break; case CAS.TYPE_NAME_STRING: { fs.setStringValue(uimaFeat, stmt.getObject().asLiteral().getString()); break; } default: throw new IllegalArgumentException("Feature [" + uimaFeat.getName() + "] has unsupported primitive type [" + uimaFeat.getRange().getName() + "]"); } } else { FeatureStructure targetUimaFS = aFsIndex.get(stmt.getObject().asResource()); if (targetUimaFS == null) { throw new IllegalStateException( "No UIMA FS found for [" + stmt.getObject().asResource().getURI() + "]"); } fs.setFeatureValue(uimaFeat, targetUimaFS); } } return fs; }
From source file:org.eclipse.recommenders.utils.rcp.ast.ASTNodeUtils.java
private static String toSimpleName(final ITypeName crParam) { String crSimpleName = Names.vm2srcSimpleTypeName(crParam); if (crSimpleName.contains("$")) { crSimpleName = StringUtils.substringAfterLast(crSimpleName, "$"); }/*from w w w . j a v a2 s .c o m*/ return crSimpleName; }
From source file:org.eclipse.recommenders.utils.rcp.JavaElementResolver.java
private Optional<IType> resolveType(final ITypeName recType) { // TODO woah, what a hack just to find a nested/anonymous type... this // definitely needs refactoring! ensureIsNotNull(recType);/* w ww .j a v a 2 s . c o m*/ if (recType.isArrayType()) { // TODO see https://bugs.eclipse.org/bugs/show_bug.cgi?id=339806 // should throw an exception? or return an Array type? System.err.println("array type in JavaElementResolver. Decision bug 339806 pending...?"); return absent(); } if (recType.isNestedType()) { final ITypeName declaringType = recType.getDeclaringType(); final String simpleName = StringUtils.substringAfterLast(recType.getIdentifier(), "$"); final IType parent = resolveType(declaringType).orNull(); if (parent != null) { try { for (final IType nested : parent.getTypes()) { final String key = nested.getKey(); if (key.equals(recType.getIdentifier() + ";")) { return fromNullable(nested); } } // int count = 0; for (final IMethod m : parent.getMethods()) { for (final IJavaElement children : m.getChildren()) { if (children instanceof IType) { final IType nested = (IType) children; // count++; if (nested.getKey().endsWith(simpleName + ";")) { return of(nested); } // if (String.valueOf(count).equals(simpleName)) { // return of(nested); // } final String key = nested.getKey(); if (key.equals(recType.getIdentifier() + ";")) { return fromNullable(nested); } } } } } catch (final Exception x) { // final IType type = // parent.getType(recType.getClassName()); return absent(); } } return absent(); } final IType[] res = new IType[1]; final IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); final SearchEngine search = new SearchEngine(); final String srcTypeName = Names.vm2srcTypeName(recType.getIdentifier()); final SearchPattern pattern = SearchPattern.createPattern(srcTypeName, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_FULL_MATCH); try { search.search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, new SearchRequestor() { @Override public void acceptSearchMatch(final SearchMatch match) throws CoreException { IType element = (IType) match.getElement(); // with the current settings the engine matches 'Lnull' with 'Ljava/lang/ref/ReferenceQueue$Null' if (toRecType(element).equals(recType)) { res[0] = element; } } }, null); } catch (final CoreException e) { throwUnhandledException(e); } return fromNullable(res[0]); }
From source file:org.gbif.dwca.action.ValidateAction.java
private List<String> interpretRecord(List<Term> concepts, Record rec, boolean isCore, int rowSize) { List<String> row = new ArrayList<String>(); if (isCore) { row.add(rec.id());//from w ww .java2 s .co m } else { String name = StringUtils.substringAfterLast(rec.rowType(), "/"); row.add(name); } for (Term t : concepts) { row.add(rec.value(t)); } // make sure all rows have the same width while (row.size() < rowSize) { row.add(""); } return row; }
From source file:org.gbif.dwca.action.ValidateAction.java
private void setRecords() { try {/* w ww.j av a 2 s .c om*/ // prepare ordered headers Map<String, List<Term>> recordsHeaderFull = new HashMap<String, List<Term>>(); List<Term> terms = new ArrayList<Term>(); recordsHeaderFull.put(archive.getCore().getRowType(), terms); for (Term t : archive.getCore().getFields().keySet()) { terms.add(t); } int maxRecordWidth = terms.size(); for (ArchiveFile af : archive.getExtensions()) { terms = new ArrayList<Term>(); recordsHeaderFull.put(af.getRowType(), terms); for (Term t : af.getFields().keySet()) { terms.add(t); } if (terms.size() > maxRecordWidth) { maxRecordWidth = terms.size(); } } // finally loop thru data ClosableIterator<StarRecord> iter = archive.iterator(); int i = 0; while (iter.hasNext() && i < scanSize) { StarRecord rec = iter.next(); List<List<String>> interpretedRecord = new ArrayList<List<String>>(); records.add(interpretedRecord); // first the core interpretedRecord.add(interpretRecord(recordsHeaderFull.get(rec.core().rowType()), rec.core(), true, maxRecordWidth + 1)); for (Record r : rec) { interpretedRecord .add(interpretRecord(recordsHeaderFull.get(r.rowType()), r, false, maxRecordWidth)); } i++; } // finally use only simple extension names for headers: String coreName = StringUtils.substringAfterLast(archive.getCore().getRowType(), "/"); recordsHeader.put(coreName, null); List<String> extensionNames = new ArrayList<String>(); for (String rt : recordsHeaderFull.keySet()) { String name = StringUtils.substringAfterLast(rt, "/"); List<String> concepts = new ArrayList<String>(); for (Term ct : recordsHeaderFull.get(rt)) { concepts.add(ct.simpleName()); } while (concepts.size() < maxRecordWidth) { concepts.add(""); } recordsHeader.put(name, concepts); extensionNames.add(name); } extensionOrder.add(coreName); extensionNames.remove(coreName); Collections.sort(extensionNames); extensionOrder.addAll(extensionNames); } catch (Exception e) { setRecordsException(e); } }
From source file:org.gbif.ipt.action.manage.SourceAction.java
public String uploadLogo() { if (file != null) { // remove any previous logo file for (String suffix : Constants.IMAGE_TYPES) { FileUtils.deleteQuietly(dataDir.resourceLogoFile(resource.getShortname(), suffix)); }/* w w w.j a va 2 s . c o m*/ // inspect file type String type = "jpeg"; if (fileContentType != null) { type = StringUtils.substringAfterLast(fileContentType, "/"); } File logoFile = dataDir.resourceLogoFile(resource.getShortname(), type); try { FileUtils.copyFile(file, logoFile); } catch (IOException e) { LOG.warn(e.getMessage()); } // resource.getEml().setLogoUrl(cfg.getResourceLogoUrl(resource.getShortname())); } return INPUT; }
From source file:org.gradoop.benchmark.fsm.TransactionalFSMBenchmark.java
/** * Method to create and add lines to a csv-file * @throws IOException/*from w ww. ja v a 2s . c o m*/ * @param inputPath input file path * @param directed true, if directed graph * @param implementation gSpan implementation * @param threshold minimum support * @param logPath log path * @param subgraphCount subgraph count */ private static void writeCSV(String inputPath, boolean directed, String implementation, float threshold, String logPath, long subgraphCount) throws IOException { String head = String.format("%s|%s|%s|%s|%s|%s|%s%n", "Parallelism", "Implementation", "Dataset", "Directed", "Threshold", "Subgraphs", "Runtime"); String tail = String.format("%s|%s|%s|%s|%s|%s|%s%n", getExecutionEnvironment().getParallelism(), implementation, StringUtils.substringAfterLast(inputPath, "/"), directed, threshold, subgraphCount, getExecutionEnvironment().getLastJobExecutionResult().getNetRuntime(TimeUnit.SECONDS)); File f = new File(logPath); if (f.exists() && !f.isDirectory()) { FileUtils.writeStringToFile(f, tail, true); } else { PrintWriter writer = new PrintWriter(logPath, "UTF-8"); writer.print(head); writer.print(tail); writer.close(); } }
From source file:org.grible.model.Category.java
private String getNameFromPath() { if (path.contains(File.separator)) { return StringUtils.substringAfterLast(path, File.separator); }/*from w w w.jav a2 s .co m*/ return path; }
From source file:org.h819.commons.net.email.example.MailChecker.java
/** * Checks if a mail address is correct and tries to correct it if possible. * * @param mail the input mail address./*from w ww.ja v a 2s .co m*/ * @return the status of the validation with a copy of the mail address on success. */ public static MailChecker.AddressStatus validate(String mail) { String domain = StringUtils.substringAfterLast(mail, "@").trim(); if (domain == null) { // System.err.println(mail + " is no valid email address"); return AddressStatus.wrongSchema; } try { if (validateMxServer(domain)) { // System.out.println(mail + " is ok"); return AddressStatus.valid.setMailAddress(mail); } else { for (String d : domains) { if (damerauLevenshteinDistance(d, domain, 128) <= 2) { // System.out.println(mail + " did you mean " + d + "?"); return AddressStatus.typoDetected .setMailAddress(mail.substring(0, mail.indexOf("@") + 1) + d); } } if (doesDomainExists(domain)) { // System.err.println(mail + " has no mail servers"); return AddressStatus.noMxRecord; } else { // System.err.println("Domain \"" + domain + "\" does not exists"); return AddressStatus.notRegisted; } } } catch (IllegalStateException e) { return AddressStatus.unknown; } }