List of usage examples for org.apache.commons.lang3 StringUtils substringBeforeLast
public static String substringBeforeLast(final String str, final String separator)
Gets the substring before the last occurrence of a separator.
From source file:org.blockartistry.mod.ThermalRecycling.util.ItemStackHelper.java
public static ItemStack getItemStack(final String name, final int quantity) { if (name == null || name.isEmpty()) return null; // Check our preferred list first. If we have a hit, use it. ItemStack result = preferred.get(name); if (result != null) { result = result.copy();/* w ww . j ava2s .c om*/ result.stackSize = quantity; } else { // Parse out the possible subtype from the end of the string String workingName = name; int subType = -1; if (StringUtils.countMatches(name, ":") == 2) { workingName = StringUtils.substringBeforeLast(name, ":"); final String num = StringUtils.substringAfterLast(name, ":"); if (num != null && !num.isEmpty()) { if ("*".compareTo(num) == 0) subType = OreDictionary.WILDCARD_VALUE; else { try { subType = Integer.parseInt(num); } catch (Exception e) { // It appears malformed - assume the incoming name // is // the real name and continue. ; } } } } // Check the OreDictionary first for any alias matches. Otherwise // go to the game registry to find a match. final ArrayList<ItemStack> ores = OreDictionary.getOres(workingName); if (!ores.isEmpty()) { result = ores.get(0).copy(); result.stackSize = quantity; } else { final Item i = GameData.getItemRegistry().getObject(workingName); if (i != null) { result = new ItemStack(i, quantity); } } // If we did have a hit on a base item, set the sub-type // as needed. if (result != null && subType != -1) { if (subType == OreDictionary.WILDCARD_VALUE && !result.getHasSubtypes()) { ModLog.warn("[%s] GENERIC requested but Item does not support sub-types", name); } else { result.setItemDamage(subType); } } } return result; }
From source file:org.blocks4j.commons.classpath.RegExp.java
public static String withoutSchemeAndParameters(URI uri) { Pattern pattern = Pattern.compile(URI_WITHOUT_PARAMETERS); Matcher match = pattern.matcher(uri.toString()); if (!match.matches()) { return uri.toString(); }/*ww w.j a va 2 s . c o m*/ String target = match.group(2); if (target.endsWith("/")) { return StringUtils.substringBeforeLast(match.group(2), "/"); } return target; }
From source file:org.boundbox.processor.BoundBoxProcessor.java
@Override public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnvironment) { // Get all classes that has the annotation Set<? extends Element> classElements = roundEnvironment.getElementsAnnotatedWith(BoundBox.class); // For each class that has the annotation for (final Element classElement : classElements) { // Get the annotation information TypeElement boundClass = null; String maxSuperClass = null; String[] prefixes = null; String boundBoxPackageName = null; List<? extends AnnotationValue> extraBoundFields = null; List<? extends AnnotationMirror> listAnnotationMirrors = classElement.getAnnotationMirrors(); if (listAnnotationMirrors == null) { messager.printMessage(Kind.WARNING, "listAnnotationMirrors is null", classElement); return true; }/*from w w w . j a v a 2s . c om*/ StringBuilder message = new StringBuilder(); for (AnnotationMirror annotationMirror : listAnnotationMirrors) { log.info("mirror " + annotationMirror.getAnnotationType()); Map<? extends ExecutableElement, ? extends AnnotationValue> map = annotationMirror .getElementValues(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : map.entrySet()) { message.append(entry.getKey().getSimpleName().toString()); message.append("\n"); message.append(entry.getValue().toString()); if (BOUNDBOX_ANNOTATION_PARAMETER_BOUND_CLASS .equals(entry.getKey().getSimpleName().toString())) { boundClass = getAnnotationValueAsTypeElement(entry.getValue()); } if (BOUNDBOX_ANNOTATION_PARAMETER_MAX_SUPER_CLASS .equals(entry.getKey().getSimpleName().toString())) { maxSuperClass = getAnnotationValueAsTypeElement(entry.getValue()).asType().toString(); } if (BOUNDBOX_ANNOTATION_PARAMETER_EXTRA_BOUND_FIELDS .equals(entry.getKey().getSimpleName().toString())) { extraBoundFields = getAnnotationValueAsAnnotationValueList(entry.getValue()); } if (BOUNDBOX_ANNOTATION_PARAMETER_PREFIXES.equals(entry.getKey().getSimpleName().toString())) { List<? extends AnnotationValue> listPrefixes = getAnnotationValueAsAnnotationValueList( entry.getValue()); prefixes = new String[listPrefixes.size()]; for (int indexAnnotation = 0; indexAnnotation < listPrefixes.size(); indexAnnotation++) { prefixes[indexAnnotation] = getAnnotationValueAsString( listPrefixes.get(indexAnnotation)); } } if (BOUNDBOX_ANNOTATION_PARAMETER_PACKAGE.equals(entry.getKey().getSimpleName().toString())) { boundBoxPackageName = getAnnotationValueAsString(entry.getValue()); } } } if (boundClass == null) { messager.printMessage(Kind.WARNING, "BoundClass is null : " + message, classElement); return true; } if (maxSuperClass != null) { boundClassVisitor.setMaxSuperClassName(maxSuperClass); } if (prefixes != null && prefixes.length != 2 && prefixes.length != 1) { error(classElement, "You must provide 1 or 2 prefixes. The first one for class names, the second one for methods."); return true; } if (prefixes != null && prefixes.length == 1) { String[] newPrefixes = new String[] { prefixes[0], prefixes[0].toLowerCase(Locale.US) }; prefixes = newPrefixes; } boundboxWriter.setPrefixes(prefixes); if (boundBoxPackageName == null) { String boundClassFQN = boundClass.getQualifiedName().toString(); if (boundClassFQN.contains(PACKAGE_SEPARATOR)) { boundBoxPackageName = StringUtils.substringBeforeLast(boundClassFQN, PACKAGE_SEPARATOR); } else { boundBoxPackageName = StringUtils.EMPTY; } } boundClassVisitor.setBoundBoxPackageName(boundBoxPackageName); boundboxWriter.setBoundBoxPackageName(boundBoxPackageName); ClassInfo classInfo = boundClassVisitor.scan(boundClass); injectExtraBoundFields(extraBoundFields, classInfo); listClassInfo.add(classInfo); // perform some computations on meta model inheritanceComputer.computeInheritanceAndHidingFields(classInfo.getListFieldInfos()); inheritanceComputer.computeInheritanceAndOverridingMethods(classInfo.getListMethodInfos(), boundClass, elements); inheritanceComputer.computeInheritanceAndHidingInnerClasses(classInfo.getListInnerClassInfo()); inheritanceComputer.computeInheritanceInInnerClasses(classInfo, elements); // write meta model to java class file Writer sourceWriter = null; try { String boundBoxClassName = boundboxWriter.getNamingGenerator().createBoundBoxName(classInfo); String boundBoxClassFQN = boundBoxPackageName.isEmpty() ? boundBoxClassName : boundBoxPackageName + PACKAGE_SEPARATOR + boundBoxClassName; JavaFileObject sourceFile = filer.createSourceFile(boundBoxClassFQN, (Element[]) null); sourceWriter = sourceFile.openWriter(); boundboxWriter.writeBoundBox(classInfo, sourceWriter); } catch (IOException e) { e.printStackTrace(); error(classElement, e.getMessage()); } finally { if (sourceWriter != null) { IOUtils.closeQuietly(sourceWriter); } } } return true; }
From source file:org.cleverbus.core.common.dao.MessageDaoJpaImpl.java
@Override public int getCountProcessingMessagesForFunnel(Collection<String> funnelValues, int idleInterval, String funnelCompId) {/* w w w . java2s. c o m*/ Assert.notEmpty(funnelValues, "funnelValues must not be empty"); Assert.hasText(funnelCompId, "funnelCompId must not be empty"); String jSql = "SELECT COUNT(m) " + "FROM " + Message.class.getName() + " m " + "INNER JOIN m.funnels f " + "WHERE (m.state = '" + MsgStateEnum.PROCESSING + "' " + " OR m.state = '" + MsgStateEnum.WAITING + "'" + " OR m.state = '" + MsgStateEnum.WAITING_FOR_RES + "')" + " AND m.startProcessTimestamp >= :startTime" + " AND m.funnelComponentId = '" + funnelCompId + "'" + " AND ("; for (String funnelValue : funnelValues) { jSql += "f.funnelValue = '" + funnelValue + "' OR "; } //remove last or jSql = StringUtils.substringBeforeLast(jSql, " OR "); jSql += ")"; TypedQuery<Number> q = em.createQuery(jSql, Number.class); q.setParameter("startTime", new Timestamp(DateUtils.addSeconds(new Date(), -idleInterval).getTime())); return q.getSingleResult().intValue(); }
From source file:org.cleverbus.core.common.dao.MessageDaoJpaImpl.java
@Override public List<Message> getMessagesForGuaranteedOrderForRoute(Collection<String> funnelValues, boolean excludeFailedState) { Assert.notNull(funnelValues, "funnelValues must not be null"); if (funnelValues.isEmpty()) { return Collections.emptyList(); } else {/* w ww. j a v a 2s. co m*/ //TODO (juza) limit select to specific number of items + add msgId DESC to sorting (parent vs. child) String jSql = "SELECT m " + "FROM " + Message.class.getName() + " m " + "INNER JOIN m.funnels f " + "WHERE (m.state = '" + MsgStateEnum.PROCESSING + "' " + " OR m.state = '" + MsgStateEnum.WAITING + "'" + " OR m.state = '" + MsgStateEnum.PARTLY_FAILED + "'" + " OR m.state = '" + MsgStateEnum.POSTPONED + "'"; if (!excludeFailedState) { jSql += " OR m.state = '" + MsgStateEnum.FAILED + "'"; } jSql += " OR m.state = '" + MsgStateEnum.WAITING_FOR_RES + "')" + " AND m.guaranteedOrder is true" + " AND ("; for (String funnelValue : funnelValues) { jSql += "f.funnelValue = '" + funnelValue + "' OR "; } //remove last or jSql = StringUtils.substringBeforeLast(jSql, " OR "); jSql += ") ORDER BY m.msgTimestamp"; TypedQuery<Message> q = em.createQuery(jSql, Message.class); return q.getResultList(); } }
From source file:org.cleverbus.core.common.dao.MessageDaoJpaImpl.java
@Override public List<Message> getMessagesForGuaranteedOrderForFunnel(Collection<String> funnelValues, int idleInterval, boolean excludeFailedState, String funnelCompId) { Assert.notNull(funnelValues, "funnelValues must not be null"); Assert.hasText(funnelCompId, "funnelCompId must not be empty"); if (funnelValues.isEmpty()) { return Collections.emptyList(); } else {//ww w .j a va 2s . co m String jSql = "SELECT m " + "FROM " + Message.class.getName() + " m " + "INNER JOIN m.funnels f " + "WHERE (m.state = '" + MsgStateEnum.PROCESSING + "' " + " OR m.state = '" + MsgStateEnum.WAITING + "'" + " OR m.state = '" + MsgStateEnum.PARTLY_FAILED + "'" + " OR m.state = '" + MsgStateEnum.POSTPONED + "'"; if (!excludeFailedState) { jSql += " OR m.state = '" + MsgStateEnum.FAILED + "'"; } jSql += " OR m.state = '" + MsgStateEnum.WAITING_FOR_RES + "')" + " AND m.funnelComponentId = '" + funnelCompId + "'" + " AND m.startProcessTimestamp >= :startTime" + " AND ("; for (String funnelValue : funnelValues) { jSql += "f.funnelValue = '" + funnelValue + "' OR "; } //remove last or jSql = StringUtils.substringBeforeLast(jSql, " OR "); jSql += ") ORDER BY m.msgTimestamp"; //TODO (juza) limit select to specific number of items + add msgId DESC to sorting (parent vs. child) TypedQuery<Message> q = em.createQuery(jSql, Message.class); q.setParameter("startTime", new Timestamp(DateUtils.addSeconds(new Date(), -idleInterval).getTime())); return q.getResultList(); } }
From source file:org.codice.ddf.branding.BrandingRegistryImpl.java
@Override public String getProductName() { return getBrandingPlugins().stream() .map(plugin -> StringUtils.substringBeforeLast(plugin.getProductName(), " ")) .filter(Objects::nonNull).findFirst().orElse("DDF"); }
From source file:org.codice.ddf.configuration.PlatformUiConfiguration.java
private void setTitle() { if (StringUtils.isNotBlank(version)) { title = StringUtils.substringBeforeLast(version, " "); } else {/*w w w.j a va 2s .c o m*/ title = "DDF"; } }
From source file:org.craftercms.engine.navigation.impl.NavBreadcrumbBuilderImpl.java
protected String extractBreadcrumbUrl(String url, String root) { String indexFileName = SiteProperties.getIndexFileName(); String breadcrumbUrl = StringUtils.substringBeforeLast(StringUtils.substringAfter(url, root), indexFileName);/*from w ww.j av a 2s . c o m*/ if (!breadcrumbUrl.startsWith("/")) { breadcrumbUrl = "/" + breadcrumbUrl; } return breadcrumbUrl; }
From source file:org.craftercms.engine.util.breadcrumb.BreadcrumbBuilder.java
public List<BreadcrumbItem> buildBreadcrumb(final String url) { final Context context = SiteContext.getCurrent().getContext(); return cacheTemplate.getObject(context, new Callback<List<BreadcrumbItem>>() { @Override/*from w ww. j a v a 2s. com*/ public List<BreadcrumbItem> execute() { String indexFileName = SiteProperties.getIndexFileName(); CachingAwareList<BreadcrumbItem> breadcrumb = new CachingAwareList<BreadcrumbItem>(); String breadcrumbUrl = StringUtils.substringBeforeLast(StringUtils.substringAfter(url, homePath), indexFileName); String[] breadcrumbUrlComponents = breadcrumbUrl.split("/"); String currentUrl = homePath; for (String breadcrumbUrlComponent : breadcrumbUrlComponents) { if (StringUtils.isNotEmpty(breadcrumbUrlComponent)) { currentUrl += "/" + breadcrumbUrlComponent; } Item item = storeService.getItem(context, UrlUtils.concat(currentUrl, indexFileName)); if (item != null && item.getDescriptorDom() != null) { String breadcrumbName = item.queryDescriptorValue(breadcrumbNameXPathQuery); if (StringUtils.isEmpty(breadcrumbName)) { if (StringUtils.isNotEmpty(breadcrumbUrlComponent)) { breadcrumbName = StringUtils .capitalize(breadcrumbUrlComponent.replace("-", " ").replace(".xml", "")); } else { breadcrumbName = HOME_BREADCRUMB_NAME; } } breadcrumb.add(new BreadcrumbItem(currentUrl, breadcrumbName)); breadcrumb.addDependencyKey(item.getKey()); } } return breadcrumb; } }, url, BREADCRUMB_CONST_KEY_ELEM); }