Example usage for org.apache.commons.lang StringUtils splitByWholeSeparator

List of usage examples for org.apache.commons.lang StringUtils splitByWholeSeparator

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils splitByWholeSeparator.

Prototype

public static String[] splitByWholeSeparator(String str, String separator) 

Source Link

Document

Splits the provided text into an array, separator string specified.

Usage

From source file:com.opengamma.bbg.loader.SecurityLoader.java

/**
 * Parses the expiry field./* w  w w  .jav  a 2s.  com*/
 * @param expiryDate  the expiry string
 * @param futureTradingHours the future trading hours
 * @return the parsed expiry object, null if cannot parse
 */
protected Expiry decodeExpiry(final String expiryDate, final String futureTradingHours) {
    _logger.debug("decodeExpiry expiryDate={} futureTradingHours={}", expiryDate, futureTradingHours);
    if (expiryDate == null || futureTradingHours == null) {
        _logger.warn("expirydate/futureTradingHours is null, cannot construct expiry");
        return null;
    }
    LocalDate expiryInLocalDate = null;
    try {
        expiryInLocalDate = LocalDate.parse(expiryDate);
    } catch (DateTimeParseException ex) {
        _logger.warn("expiry not in mm/dd/yyyy format - {}", expiryDate);
        return null;
    }
    //expects future trading hours in 07:00-21:00 OR 00:00-19:15 & 15:30-19:15 format
    String splitTradingHours = null;
    if (futureTradingHours.contains("&")) {
        String[] tokens = StringUtils.splitByWholeSeparator(futureTradingHours, "&");
        if (tokens.length != 2) {
            _logger.warn("futureTradingHours not in (hh:mm-hh:mm OR hh:mm-hh:mm & hh:mm-hh:mm) format - {}",
                    futureTradingHours);
            return null;
        }
        splitTradingHours = tokens[1];
    } else {
        splitTradingHours = futureTradingHours;
    }
    int closeHr = 23;
    int closeMins = 59;
    String[] tradingHrsToken = StringUtils.splitByWholeSeparator(splitTradingHours, "-");
    if (tradingHrsToken.length != 2) {
        _logger.warn("futureTradingHours not in (hh:mm-hh:mm OR hh:mm-hh:mm & hh:mm-hh:mm) format - {}",
                futureTradingHours);
        return null;
    } else {
        String closeTime = tradingHrsToken[1];
        String[] closeTimeTokens = closeTime.split(":");
        if (closeTimeTokens.length != 2) {
            closeTimeTokens = closeTime.split("\\.");
            if (closeTimeTokens.length != 2) {
                _logger.warn("exchange close time not in hh:mm format - {}", futureTradingHours);
                return null;
            }
        }

        try {
            closeHr = Integer.parseInt(closeTimeTokens[0]);
            closeMins = Integer.parseInt(closeTimeTokens[1]);
        } catch (NumberFormatException ex) {
            _logger.warn("Cannot parse futureTrading hours - {}", futureTradingHours);
        }
    }
    ZonedDateTime utcDate = DateUtils.getUTCDate(expiryInLocalDate.getYear(), expiryInLocalDate.getMonthValue(),
            expiryInLocalDate.getDayOfMonth(), closeHr, closeMins);
    return new Expiry(utcDate, ExpiryAccuracy.MIN_HOUR_DAY_MONTH_YEAR);
}

From source file:com.glluch.profilesparser.ProfileHtmlReader.java

private ArrayList<ECFMap> getLevel(String allTxt, String posterior, String f) {
    //throws java.lang.ArrayIndexOutOfBoundsException
    ArrayList<ECFMap> res = new ArrayList<>();
    String chunk;/*  w  ww  .  jav  a  2  s  .  co  m*/
    if (f != null) {
        chunk = StringUtils.substringBetween(allTxt, posterior, f).trim();
    } else {
        chunk = StringUtils.substringAfter(allTxt, posterior).trim();
    }
    String prelevels = StringUtils.substringAfter(chunk, "Proficiency Levels");
    String[] levels = StringUtils.splitByWholeSeparator(prelevels, "Proficiency Level");
    //System.out.println("levels:\n"+levels.toString());
    int i = 0;
    while (i < levels.length) {
        if (levels[i].length() > 1) {
            String c3 = levels[i].substring(1, 2);
            HashMap<Integer, String> c0;
            c0 = parseCompName(posterior);

            String c1 = c0.get(0);
            String c2 = c0.get(1);
            //System.out.println(c1+" "+c2+", level "+c3);
            ECFMap em = new ECFMap(c1, c2, c3);
            res.add(em);
            //System.out.println(levels[i] + "\n-->" + levels[i].substring(1, 2));
        }
        i++;
    }
    return res;
}

From source file:com.hangum.tadpole.rdb.erd.core.dnd.TableTransferDropTargetListener.java

/**
 * painting model /*from ww w  .j  a va  2  s.c o  m*/
 * 
 * @param nextTableX
 * @param nextTableY
 * @param arryTables
 * @param mapTable
 */
private void paintingModel(int nextTableX, int nextTableY, String[] arryTables,
        Map<String, List<TableColumnDAO>> mapTable) {
    Rectangle prevRectangle = null;

    int originalX = nextTableX;
    int intCount = 1;
    for (String strTable : arryTables) {
        String[] arryTable = StringUtils.splitByWholeSeparator(strTable, PublicTadpoleDefine.DELIMITER);
        if (arryTable.length == 0)
            continue;

        String tableName = arryTable[1];
        String refTableNames = "'" + tableName + "',"; //$NON-NLS-1$ //$NON-NLS-2$

        // ? editor ?? ?  .
        Map<String, Table> mapDBTables = new HashMap<String, Table>();
        for (Table table : db.getTables()) {
            mapDBTables.put(table.getName(), table);
            refTableNames += "'" + table.getName() + "',"; //$NON-NLS-1$ //$NON-NLS-2$
        }
        refTableNames = StringUtils.chompLast(refTableNames, ","); //$NON-NLS-1$

        // ? ??  ? ?
        if (mapDBTables.get(tableName) == null) {
            // ? ? ?
            Table tableModel = tadpoleFactory.createTable();
            tableModel.setName(tableName);
            tableModel.setDb(db);

            String tableComment = StringUtils.trimToEmpty(arryTable[2]);
            tableComment = StringUtils.substring(tableComment, 0, 10);
            tableModel.setComment(tableComment);

            // ??  ?. 
            prevRectangle = new Rectangle(nextTableX, nextTableY, TadpoleModelUtils.END_TABLE_WIDTH,
                    TadpoleModelUtils.END_TABLE_HIGHT);
            tableModel.setConstraints(prevRectangle);

            // ?  .
            nextTableX = originalX + (TadpoleModelUtils.GAP_WIDTH * intCount);
            intCount++;

            try {
                //  ? ?
                for (TableColumnDAO columnDAO : mapTable.get(tableName)) {
                    Column column = tadpoleFactory.createColumn();

                    column.setDefault(columnDAO.getDefault());
                    column.setExtra(columnDAO.getExtra());
                    column.setField(columnDAO.getField());
                    column.setNull(columnDAO.getNull());
                    column.setKey(columnDAO.getKey());
                    column.setType(columnDAO.getType());

                    String strComment = columnDAO.getComment();
                    if (strComment == null)
                        strComment = "";
                    strComment = StringUtils.substring(strComment, 0, 10);
                    column.setComment(strComment);

                    column.setTable(tableModel);
                    tableModel.getColumns().add(column);
                }
                mapDBTables.put(tableName, tableModel);
                RelationUtil.calRelation(userDB, mapDBTables, db, refTableNames);//RelationUtil.getReferenceTable(userDB, refTableNames));

            } catch (Exception e) {
                logger.error("GEF Table Drag and Drop Exception", e); //$NON-NLS-1$

                Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
                ExceptionDetailsErrorDialog.openError(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.get().Error,
                        Messages.get().TadpoleModelUtils_2, errStatus); //$NON-NLS-1$
            }

            transferFactory.setTable(tableModel);
        } else {
            transferFactory.setTable(mapDBTables.get(tableName));
        }
    } //  end tables

    //      super.handleDrop();
}

From source file:com.hangum.tadpole.mongodb.erd.core.dnd.TableTransferDropTargetListener.java

/**
 * painting model /*from   w  w w  .  ja v  a 2  s .c o  m*/
 * 
 * @param nextTableX
 * @param nextTableY
 * @param arryTables
 * @param mapTable
 */
private void paintingModel(int nextTableX, int nextTableY, String[] arryTables,
        Map<String, List<CollectionFieldDAO>> mapTable) {
    Rectangle prevRectangle = null;

    int originalX = nextTableX;
    int intCount = 1;
    for (String strTable : arryTables) {
        String[] arryTable = StringUtils.splitByWholeSeparator(strTable, PublicTadpoleDefine.DELIMITER);
        if (arryTable.length == 0)
            continue;

        String tableName = arryTable[IDX_TABLE_NAME];
        String refTableNames = "'" + tableName + "',"; //$NON-NLS-1$ //$NON-NLS-2$

        // ? editor ?? ?  .
        Map<String, Table> mapDBTables = new HashMap<String, Table>();
        for (Table table : db.getTables()) {
            mapDBTables.put(table.getName(), table);
            refTableNames += "'" + table.getName() + "',"; //$NON-NLS-1$ //$NON-NLS-2$
        }
        refTableNames = StringUtils.chompLast(refTableNames, ","); //$NON-NLS-1$

        // ? ??  ? ?
        if (mapDBTables.get(tableName) == null) {
            // ? ? ?
            Table tableModel = tadpoleFactory.createTable();
            tableModel.setName(tableName);
            tableModel.setDb(db);

            if (prevRectangle == null) {
                prevRectangle = new Rectangle(nextTableX, nextTableY, TadpoleModelUtils.END_TABLE_WIDTH,
                        TadpoleModelUtils.END_TABLE_HIGHT);
            } else {
                // ??  ?. 
                prevRectangle = new Rectangle(nextTableX, nextTableY, TadpoleModelUtils.END_TABLE_WIDTH,
                        TadpoleModelUtils.END_TABLE_HIGHT);
            }
            tableModel.setConstraints(prevRectangle);
            // ?  .
            nextTableX = originalX + (TadpoleModelUtils.GAP_WIDTH * intCount);
            intCount++;

            try {
                //  ? ?
                for (CollectionFieldDAO columnDAO : mapTable.get(tableName)) {
                    Column column = tadpoleFactory.createColumn();
                    column.setField(columnDAO.getField());
                    column.setKey(columnDAO.getKey());
                    column.setType(columnDAO.getType());
                    if ("BasicDBObject".equals(columnDAO.getType())) {
                        makeSubDoc(tableModel, column, columnDAO);
                    }

                    column.setTable(tableModel);
                }
                mapDBTables.put(tableName, tableModel);
                RelationUtil.calRelation(userDB, mapDBTables, db, refTableNames);//RelationUtil.getReferenceTable(userDB, refTableNames));

            } catch (Exception e) {
                logger.error("GEF Table Drag and Drop Exception", e); //$NON-NLS-1$

                Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
                ExceptionDetailsErrorDialog.openError(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.get().Error,
                        Messages.get().TadpoleModelUtils_2, errStatus); //$NON-NLS-1$
            }

            transferFactory.setTable(tableModel);
        } else {
            transferFactory.setTable(mapDBTables.get(tableName));
        }
    }
}

From source file:com.vmware.vfabric.ide.eclipse.tcserver.internal.core.TcPublisher.java

/**
 * Check if resource delta only contains static resources
 *//*from   www  .jav  a 2s  .c  o  m*/
private boolean onlyStaticResources(IModuleResourceDelta delta, Set<IModuleFile> files) {
    if (delta.getModuleResource() instanceof IModuleFolder) {
        for (IModuleResourceDelta child : delta.getAffectedChildren()) {
            if (!onlyStaticResources(child, files)) {
                return false;
            }
        }
        return true;
    } else {
        if (delta.getModuleResource() instanceof IModuleFile) {
            files.add((IModuleFile) delta.getModuleResource());
        }
        String name = delta.getModuleResource().getName();

        // make that configurable
        if (name.endsWith(".xml")) {
            IFile file = (IFile) delta.getModuleResource().getAdapter(IFile.class);
            // check for spring context xml files first but exclude
            if (!checkIfSpringConfigurationFile(file)) {
                return false;
            }
        }
        boolean isStatic = false;
        // Check the configuration options for static resources
        AntPathMatcher matcher = new AntPathMatcher();
        TcServer tcServer = (TcServer) server.getServer().loadAdapter(TcServer.class, null);
        for (String pattern : StringUtils.splitByWholeSeparator(tcServer.getStaticFilenamePatterns(), ",")) {
            if (pattern.startsWith("!") && matcher.match(pattern.substring(1), name)) {
                isStatic = false;
            } else if (matcher.match(pattern, name)) {
                isStatic = true;
            }
        }
        return isStatic;
    }
}

From source file:com.glluch.profilesparser.ProfileHtmlReader.java

private HashMap<Integer, String> parseCompName(String comp) {
    HashMap<Integer, String> res = new HashMap<Integer, String>();
    String[] parts = StringUtils.splitByWholeSeparator(comp, ".");
    //System.out.println(comp);
    //System.out.println(parts.length);

    res.put(0, parts[0] + "." + parts[1]);
    int i = 2;//from  w  w  w . j  a va  2 s  . c o m
    String p = "";
    while (i < parts.length) {
        p += parts[i];

        i++;
    }
    res.put(1, p);

    return res;
}

From source file:com.datatorrent.stram.StramClient.java

public static LinkedHashSet<String> findJars(LogicalPlan dag, Class<?>[] defaultClasses) {
    List<Class<?>> jarClasses = new ArrayList<Class<?>>();

    for (String className : dag.getClassNames()) {
        try {/*  w  w w  . j ava  2  s  .  c om*/
            Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
            jarClasses.add(clazz);
        } catch (ClassNotFoundException e) {
            throw new IllegalArgumentException("Failed to load class " + className, e);
        }
    }

    for (Class<?> clazz : Lists.newArrayList(jarClasses)) {
        // process class and super classes (super does not require deploy annotation)
        for (Class<?> c = clazz; c != Object.class && c != null; c = c.getSuperclass()) {
            //LOG.debug("checking " + c);
            jarClasses.add(c);
            jarClasses.addAll(Arrays.asList(c.getInterfaces()));
        }
    }

    jarClasses.addAll(Arrays.asList(defaultClasses));

    if (dag.isDebug()) {
        LOG.debug("Deploy dependencies: {}", jarClasses);
    }

    LinkedHashSet<String> localJarFiles = new LinkedHashSet<String>(); // avoid duplicates
    HashMap<String, String> sourceToJar = new HashMap<String, String>();

    for (Class<?> jarClass : jarClasses) {
        if (jarClass.getProtectionDomain().getCodeSource() == null) {
            // system class
            continue;
        }
        String sourceLocation = jarClass.getProtectionDomain().getCodeSource().getLocation().toString();
        String jar = sourceToJar.get(sourceLocation);
        if (jar == null) {
            // don't create jar file from folders multiple times
            jar = JarFinder.getJar(jarClass);
            sourceToJar.put(sourceLocation, jar);
            LOG.debug("added sourceLocation {} as {}", sourceLocation, jar);
        }
        if (jar == null) {
            throw new AssertionError("Cannot resolve jar file for " + jarClass);
        }
        localJarFiles.add(jar);
    }

    String libJarsPath = dag.getValue(LogicalPlan.LIBRARY_JARS);
    if (!StringUtils.isEmpty(libJarsPath)) {
        String[] libJars = StringUtils.splitByWholeSeparator(libJarsPath, LIB_JARS_SEP);
        localJarFiles.addAll(Arrays.asList(libJars));
    }

    LOG.info("Local jar file dependencies: " + localJarFiles);

    return localJarFiles;
}

From source file:com.hangum.tadpole.engine.manager.TadpoleSQLManager.java

/**
 * dbcp pool info//from w  ww. j  ava  2 s  .  c  om
 * 
 * @return
 */
public static List<DBCPInfoDAO> getDBCPInfo() {
    List<DBCPInfoDAO> listDbcpInfo = new ArrayList<DBCPInfoDAO>();

    Set<String> setKeys = getDbManager().keySet();
    for (String stKey : setKeys) {

        SqlMapClient sqlMap = dbManager.get(stKey);
        DataSource ds = sqlMap.getDataSource();
        BasicDataSource bds = (BasicDataSource) ds;

        String[] strArryKey = StringUtils.splitByWholeSeparator(stKey, PublicTadpoleDefine.DELIMITER);
        if (!DBDefine.TADPOLE_SYSTEM_DEFAULT.getDBToString().equals(strArryKey[1])) {

            DBCPInfoDAO dao = new DBCPInfoDAO();
            dao.setDbSeq(Integer.parseInt(strArryKey[0]));
            dao.setDbType(strArryKey[1]);
            dao.setDisplayName(strArryKey[2]);

            dao.setNumberActive(bds.getNumActive());
            dao.setMaxActive(bds.getMaxActive());
            dao.setNumberIdle(bds.getNumIdle());
            dao.setMaxWait(bds.getMaxWait());

            listDbcpInfo.add(dao);
        }
    }

    return listDbcpInfo;
}

From source file:com.longevitysoft.java.bigslice.server.SliceMarshaller.java

/**
 * Extracts a gcode output filename from a qualified path.
 * //  w  ww .  ja  v  a 2s . com
 * @param path
 * @return
 */
public String extractOutputFilenameFromPath(final String path) {
    StringBuilder ret = new StringBuilder();
    String p2 = path.replace(".ini", Constants.BLANK);
    // first parse out / identifier
    String[] pathParts = StringUtils.splitByWholeSeparator(p2, Constants.SLASH);
    if (pathParts != null && pathParts.length > 1) {
        p2 = pathParts[pathParts.length - 1];
        pathParts[pathParts.length - 1] = "";
        ret.append(StringUtils.join(pathParts, Constants.SLASH)).append(Constants.SLASH);
    }
    // next strip out the __ identifier in config filename
    String[] nameParts = StringUtils.splitByWholeSeparator(p2, Constants.DOUBLESCORE);
    if (nameParts.length > 0) {
        String lastPart = nameParts[nameParts.length - 1];
        nameParts[nameParts.length - 1] = "";
        ret.append(StringUtils.join(nameParts, Constants.SLASH)).append(Constants.TILDE_BANG_TILDE)
                .append(lastPart);
    }
    return ret.toString();
}

From source file:feedsplugin.FeedsPlugin.java

private boolean matchesTitle(final String feedTitle, final String programTitle, String quotedTitle) {
    if (programTitle.isEmpty()) {
        return false;
    }/*from ww  w. ja  v a 2  s  . com*/
    if (feedTitle.equalsIgnoreCase(programTitle)) {
        return true;
    }
    if (StringUtils.containsIgnoreCase(feedTitle, programTitle)) {
        if (quotedTitle == null) {
            quotedTitle = quoteTitle(programTitle);
        }
        if (feedTitle.matches(quotedTitle)) {
            return true;
        }
    }
    if (programTitle.contains(" - ")) {
        String[] parts = StringUtils.splitByWholeSeparator(programTitle, " - ");
        if (parts[0].length() >= MIN_MATCH_LENGTH) {
            return matchesTitle(feedTitle, parts[0], null);
        }
    } else if (programTitle.endsWith(")")) {
        int index = programTitle.lastIndexOf("(");
        if (index > 0) {
            // try without the suffix in brackets, which might be a part number or
            // the like
            return matchesTitle(feedTitle, programTitle.substring(0, index).trim(), null);
        }
    } else if (!Character.isLetterOrDigit(programTitle.charAt(programTitle.length() - 1))) {
        String shortProgramTitle = removePunctuation(programTitle);
        String shortFeedTitle = removePunctuation(feedTitle);
        return matchesTitle(shortFeedTitle, shortProgramTitle, null);
    }
    return false;
}