Example usage for org.apache.commons.lang ArrayUtils indexOf

List of usage examples for org.apache.commons.lang ArrayUtils indexOf

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils indexOf.

Prototype

public static int indexOf(boolean[] array, boolean valueToFind) 

Source Link

Document

Finds the index of the given value in the array.

Usage

From source file:org.exoplatform.webui.utils.TimeConvertUtils.java

/**
 * Convert date to display string with format X time ago
 * /*from w  ww  .j a v  a2  s .  c om*/
 * @param myDate The object date input for convert, it must has ZoneTime is GMT+0
 * @param format The date/time format
 * @param locale The Local of current location(language/country).
 * @param limit The value set for limit convert x time ago. It must is: TimeConvertUtils.YEAR, MONTH, WEEK, DAY.
 * @return String 
 */
public static String convertXTimeAgo(Date myDate, String format, Locale locale, int limit) {
    String[] values = convertXTimeAgo(myDate).split(SPACE);
    if (values[0].equals(JUSTNOW))
        return getResourceBundle(RESOURCE_KEY + JUSTNOW, locale);
    int i = ArrayUtils.indexOf(strs, values[1].replace(STR_S, STR_EMPTY));
    if (limit == 0 || i < limit) {
        return getMessage(getResourceBundle(RESOURCE_KEY + values[1].replace(UNDERSCORE, STR_EMPTY), locale),
                new String[] { values[0] });
    }

    if (locale != null) {
        return getFormatDate(myDate, format, locale);
    } else {
        return getFormatDate(myDate, format);
    }
}

From source file:org.flinkspector.core.quantify.TupleMap.java

/**
 * Returns the value of a key./*from   w ww . j av a2  s  . c  o m*/
 *
 * @param key  string.
 * @param <IN> return type.
 * @return value
 */
public <IN> IN get(String key) {
    if (key == null) {
        throw new IllegalArgumentException("Key has to be not null!");
    }
    int index = ArrayUtils.indexOf(keys, key);
    if (index < 0) {
        throw new IllegalArgumentException("Key \"" + key + "\" not found!");
    }
    return tuple.getField(index);
}

From source file:org.geopublishing.atlasViewer.swing.AtlasViewerGUI.java

/**
 * Checks whether -t test mode switch has been passed. Will return an args
 * array with -t removed if found./*from   w ww.  ja  v a2  s. com*/
 */
static String[] checkTestModeArgument(String[] args) {
    if (ArrayUtils.contains(args, "-t")) {
        setTestMode(true);
        return (String[]) ArrayUtils.remove(args, ArrayUtils.indexOf(args, "-t"));
    }
    return args;
}

From source file:org.hillview.sketches.JLProjection.java

@Override
public double getCorrelation(String s, String t) {
    int sIndex = ArrayUtils.indexOf(this.colNames, s);
    int tIndex = ArrayUtils.indexOf(this.colNames, t);
    return this.getCorrelationMatrix()[sIndex][tIndex];
}

From source file:org.hillview.sketches.JLProjection.java

@Override
public double[] getCorrelationWith(String s) {
    int sIndex = ArrayUtils.indexOf(this.colNames, s);
    return this.getCorrelationMatrix()[sIndex];
}

From source file:org.jahia.modules.newsletter.service.SubscriptionService.java

/**
 * Import the subscriber data from the specified CSV file and creates
 * subscriptions for the provided subscribable node.
 *
 * @param subscribableIdentifier the UUID of the target subscribable node
 * @param subscribersCSVFile     the subscribers file in CSV format
 * @param session//from  w  w w  .j a va  2 s  .  c  o  m
 */
public void importSubscriptions(String subscribableIdentifier, MultipartFile subscribersCSVFile,
        JCRSessionWrapper session, char separator) {
    long timer = System.currentTimeMillis();

    if (logger.isDebugEnabled()) {
        logger.debug("Start importing subscriptions for source node {}", subscribableIdentifier);
    }

    int importedCount = 0;

    InputStream is = null;
    CSVReader reader = null;
    try {
        is = new BufferedInputStream(subscribersCSVFile.getInputStream());
        reader = new CSVReader(new InputStreamReader(is, "UTF-8"), separator);
        String[] columns = reader.readNext();
        int usernamePosition = ArrayUtils.indexOf(columns, "j:nodename");
        int emailPosition = ArrayUtils.indexOf(columns, J_EMAIL);
        if (usernamePosition == -1 && emailPosition == -1) {
            logger.warn("No data for importing subscriptions is found" + " or the file is not well-formed");
            return;
        }
        Map<String, Map<String, Object>> subscribers = new HashMap<String, Map<String, Object>>();
        String[] nextLine;
        while ((nextLine = reader.readNext()) != null) {
            String userKey = usernamePosition != -1 ? nextLine[usernamePosition] : null;
            String email = emailPosition != -1 ? nextLine[emailPosition] : null;
            boolean registered = true;
            if (StringUtils.isNotEmpty(userKey)) {
                // registered Jahia user is provided
                JCRUserNode user = userKey.charAt(0) == '/' ? userManagerService.lookupUserByPath(userKey)
                        : userManagerService.lookupUser(userKey);
                if (user != null) {
                    userKey = user.getPath();
                } else {
                    logger.warn("No user can be found for the specified username '" + userKey
                            + "'. Skipping subscription: " + StringUtils.join(nextLine, separator));
                    continue;
                }
            } else if (StringUtils.isNotEmpty(email)) {
                userKey = email;
                registered = false;
            } else {
                logger.warn("Neither a j:nodename nor j:email is provided." + "Skipping subscription: "
                        + StringUtils.join(nextLine, separator));
                continue;
            }
            Map<String, Object> props = new HashMap<String, Object>(columns.length);
            for (int i = 0; i < columns.length; i++) {
                String column = columns[i];
                if ("j:nodename".equals(column) || !registered && J_EMAIL.equals(column)) {
                    continue;
                }
                props.put(column, nextLine[i]);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Subscribing '" + userKey + "' with properties: " + props);
            }

            subscribers.put(userKey, props);
            if (subscribers.size() > 1000) {
                // flush
                subscribe(subscribableIdentifier, subscribers, session);
                importedCount += subscribers.size();
                subscribers = new HashMap<String, Map<String, Object>>();
            }
        }
        if (!subscribers.isEmpty()) {
            // subscribe the rest
            importedCount += subscribers.size();
            subscribe(subscribableIdentifier, subscribers, session);
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception e) {
                // ignore
            }
        }
        IOUtils.closeQuietly(is);
    }

    if (logger.isInfoEnabled()) {
        logger.info("Importing {} subscriptions for source node {} took {} ms",
                new Object[] { importedCount, subscribableIdentifier, System.currentTimeMillis() - timer });
    }
}

From source file:org.jahia.pipelines.impl.GenericPipeline.java

/**
 * @since Jahia 6.6.0.0
 */
public int indexOf(Valve valve) {
    return ArrayUtils.indexOf(valves, valve);
}

From source file:org.jahia.services.notification.SubscriptionService.java

/**
 * Import the subscriber data from the specified CSV file and creates
 * subscriptions for the provided subscribable node.
 *
 * @param subscribableIdentifier the UUID of the target subscribable node
 * @param subscribersCSVFile     the subscribers file in CSV format
 * @param session//from  w w w.  ja va 2s.c o m
 */
public void importSubscriptions(String subscribableIdentifier, File subscribersCSVFile,
        JCRSessionWrapper session) {
    long timer = System.currentTimeMillis();

    if (logger.isDebugEnabled()) {
        logger.debug("Start importing subscriptions for source node {}", subscribableIdentifier);
    }

    int importedCount = 0;

    InputStream is = null;
    CSVReader reader = null;
    try {
        is = new BufferedInputStream(new FileInputStream(subscribersCSVFile));
        char separator = ',';
        reader = new CSVReader(new InputStreamReader(is, "UTF-8"), separator);
        String[] columns = reader.readNext();
        if (columns == null) {
            logger.warn("No data for importing subscriptions is found" + " or the file is not well-formed");
            return;
        }
        if (columns.length == 1 && columns[0].contains(";")) {
            // semicolon is used as a separator
            reader.close();
            IOUtils.closeQuietly(is);
            is = new BufferedInputStream(new FileInputStream(subscribersCSVFile));
            separator = ';';
            reader = new CSVReader(new InputStreamReader(is, "UTF-8"), separator);
            columns = reader.readNext();
        }
        int usernamePosition = ArrayUtils.indexOf(columns, "j:nodename");
        int emailPosition = ArrayUtils.indexOf(columns, J_EMAIL);
        if (usernamePosition == -1 && emailPosition == -1) {
            logger.warn("No data for importing subscriptions is found" + " or the file is not well-formed");
            return;
        }
        Map<String, Map<String, Object>> subscribers = new HashMap<String, Map<String, Object>>();
        String[] nextLine;
        while ((nextLine = reader.readNext()) != null) {
            String username = usernamePosition != -1 ? nextLine[usernamePosition] : null;
            String email = emailPosition != -1 ? nextLine[emailPosition] : null;
            boolean registered = true;
            if (StringUtils.isNotEmpty(username)) {
                // registered Jahia user is provided
                JahiaUser user = username.charAt(0) == '{' ? userManagerService.lookupUserByKey(username)
                        : userManagerService.lookupUser(username);
                if (user != null) {
                    if (username.charAt(0) != '{') {
                        username = "{" + user.getProviderName() + "}" + username;
                    }
                } else {
                    logger.warn("No user can be found for the specified username '" + username
                            + "'. Skipping subscription: " + StringUtils.join(nextLine, separator));
                    continue;
                }
            } else if (StringUtils.isNotEmpty(email)) {
                username = email;
                registered = false;
            } else {
                logger.warn("Neither a j:nodename nor j:email is provided." + "Skipping subscription: "
                        + StringUtils.join(nextLine, separator));
                continue;
            }
            Map<String, Object> props = new HashMap<String, Object>(columns.length);
            for (int i = 0; i < columns.length; i++) {
                String column = columns[i];
                if ("j:nodename".equals(column) || !registered && J_EMAIL.equals(column)) {
                    continue;
                }
                props.put(column, nextLine[i]);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Subscribing '" + username + "' with properties: " + props);
            }

            subscribers.put(username, props);
            if (subscribers.size() > 1000) {
                // flush
                subscribe(subscribableIdentifier, subscribers, session);
                importedCount += subscribers.size();
                subscribers = new HashMap<String, Map<String, Object>>();
            }
        }
        if (!subscribers.isEmpty()) {
            // subscribe the rest
            importedCount += subscribers.size();
            subscribe(subscribableIdentifier, subscribers, session);
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception e) {
                // ignore
            }
        }
        IOUtils.closeQuietly(is);
    }

    if (logger.isInfoEnabled()) {
        logger.info("Importing {} subscriptions for source node {} took {} ms",
                new Object[] { importedCount, subscribableIdentifier, System.currentTimeMillis() - timer });
    }
}

From source file:org.jopac2.jbal.iso2709.Unimarc.java

@Override
public void addElectronicVersion(ElectronicResource electronicResource) {
    //      Indicatore 1: Modalit di accesso
    //       Nessuna informazione fornita
    //       0 Email
    //       1 FTP
    //       2 Login da remoto (Telnet)
    //       3 Dial-up
    //       4 HTTP
    //       7 Modalit specifica in $y
    //      $y Metodo di accesso (non ripetibile)
    Tag resource = new Tag("856", ' ', ' ');
    if (!StringUtils.isBlank(electronicResource.getAccessmethod())) {
        int i = ArrayUtils.indexOf(ElectronicResource.accessType, electronicResource.getAccessmethod());
        if (i >= 0) {
            resource.setModifier1((char) ('0' + i));
        } else {//from w w  w.  ja va 2 s. co m
            resource.setModifier1('7');
            resource.addField(new Field("y", electronicResource.getAccessmethod()));
        }
    }

    //       $a Nome Host (ripetibile)
    if (!StringUtils.isBlank(electronicResource.getHostaname()))
        resource.addField(new Field("a", electronicResource.getHostaname()));

    //       $b Numero di accesso (ripetibile)
    if (!StringUtils.isBlank(electronicResource.getAccessnumber()))
        resource.addField(new Field("b", electronicResource.getAccessnumber()));

    //      $c Compressione dell'informazione (ripetibile)
    if (!StringUtils.isBlank(electronicResource.getCompression()))
        resource.addField(new Field("c", electronicResource.getCompression()));

    //       $d Percorso (ripetibile)
    if (!StringUtils.isBlank(electronicResource.getPath()))
        resource.addField(new Field("d", electronicResource.getPath()));

    //       $e Data e orario della consultazione e dell'accesso(non ripetibile)
    if (!StringUtils.isBlank(electronicResource.getLastaccesstime()))
        resource.addField(new Field("e", electronicResource.getLastaccesstime()));

    //       $f Nome del file (ripetibile)
    if (!StringUtils.isBlank(electronicResource.getFilename()))
        resource.addField(new Field("f", electronicResource.getFilename()));

    //       $h Processore delle richieste (non ripetibile)
    if (!StringUtils.isBlank(electronicResource.getRequestprocessor()))
        resource.addField(new Field("h", electronicResource.getRequestprocessor()));

    //       $i Istruzione (ripetibile)
    if (!StringUtils.isBlank(electronicResource.getCommand()))
        resource.addField(new Field("i", electronicResource.getCommand()));

    //       $j Bits per second (non ripetibile)
    if (!StringUtils.isBlank(electronicResource.getBitpersecond()))
        resource.addField(new Field("j", electronicResource.getBitpersecond()));

    //       $k Password (Not ripetibile)
    if (!StringUtils.isBlank(electronicResource.getPassword()))
        resource.addField(new Field("k", electronicResource.getPassword()));

    //       $l Logon/login (non ripetibile)
    if (!StringUtils.isBlank(electronicResource.getLogin()))
        resource.addField(new Field("l", electronicResource.getLogin()));

    //       $m Contatto per l'assistenza nell'accesso (ripetibile)
    if (!StringUtils.isBlank(electronicResource.getContact()))
        resource.addField(new Field("m", electronicResource.getContact()));

    //       $n Nome dell'ubicazione dell'host in $a (non ripetibile)
    if (!StringUtils.isBlank(electronicResource.getLocation()))
        resource.addField(new Field("n", electronicResource.getLocation()));

    //       $o Sistema operativo (non ripetibile)
    if (!StringUtils.isBlank(electronicResource.getOperatingsystem()))
        resource.addField(new Field("o", electronicResource.getOperatingsystem()));

    //       $p Porta (non ripetibile)
    if (!StringUtils.isBlank(electronicResource.getPortnumber()))
        resource.addField(new Field("p", electronicResource.getPortnumber()));

    //       $q Tipo di formato elettronico (non ripetibile)
    if (!StringUtils.isBlank(electronicResource.getMimetype()))
        resource.addField(new Field("q", electronicResource.getMimetype()));

    //       $r Impostazioni (non ripetibile)
    if (!StringUtils.isBlank(electronicResource.getSettings()))
        resource.addField(new Field("r", electronicResource.getSettings()));

    //       $s Dimensioni del file (ripetibile)
    if (!StringUtils.isBlank(electronicResource.getSettings()))
        resource.addField(new Field("s", electronicResource.getSettings()));

    //       $t Emulazione del terminale (ripetibile)
    if (!StringUtils.isBlank(electronicResource.getTerminalemulationsettings()))
        resource.addField(new Field("t", electronicResource.getTerminalemulationsettings()));

    //       $u Uniform Resource Locator (non ripetibile)
    if (!StringUtils.isBlank(electronicResource.getUrl()))
        resource.addField(new Field("u", electronicResource.getUrl()));

    //       $v Orario in cui  possibile l'accesso alla risorsa (ripetibile)
    if (!StringUtils.isBlank(electronicResource.getAccesstime()))
        resource.addField(new Field("v", electronicResource.getAccesstime()));

    //       $w Numero di controllo della registrazione (ripetibile)
    if (!StringUtils.isBlank(electronicResource.getRecordcontrolnumber()))
        resource.addField(new Field("w", electronicResource.getRecordcontrolnumber()));

    //       $x Nota non pubblica (ripetibile)
    if (!StringUtils.isBlank(electronicResource.getNonpublicnote()))
        resource.addField(new Field("x", electronicResource.getNonpublicnote()));

    //       $z Nota pubblica (ripetibile)
    if (!StringUtils.isBlank(electronicResource.getPublicnote()))
        resource.addField(new Field("z", electronicResource.getPublicnote()));

    //       $2 Testo del link (ripetibile)
    if (!StringUtils.isBlank(electronicResource.getLinktext()))
        resource.addField(new Field("2", electronicResource.getLinktext()));

    addTag(resource);
}

From source file:org.jumpmind.symmetric.io.data.reader.ExtractDataReader.java

protected CsvData enhanceWithLobsFromSourceIfNeeded(Table table, CsvData data) {
    if (this.currentSource.requiresLobsSelectedFromSource() && (data.getDataEventType() == DataEventType.UPDATE
            || data.getDataEventType() == DataEventType.INSERT)) {
        List<Column> lobColumns = platform.getLobColumns(table);
        if (lobColumns.size() > 0) {
            String[] columnNames = table.getColumnNames();
            String[] rowData = data.getParsedData(CsvData.ROW_DATA);
            Column[] orderedColumns = table.getColumns();
            Object[] objectValues = platform.getObjectValues(batch.getBinaryEncoding(), rowData,
                    orderedColumns);//  w w w  .  ja va2s  .com
            Map<String, Object> columnDataMap = CollectionUtils.toMap(columnNames, objectValues);
            Column[] pkColumns = table.getPrimaryKeyColumns();
            ISqlTemplate sqlTemplate = platform.getSqlTemplate();
            Object[] args = new Object[pkColumns.length];
            for (int i = 0; i < pkColumns.length; i++) {
                args[i] = columnDataMap.get(pkColumns[i].getName());
            }

            for (Column lobColumn : lobColumns) {
                String sql = buildSelect(table, lobColumn, pkColumns);
                String valueForCsv = null;
                if (platform.isBlob(lobColumn.getMappedTypeCode())) {
                    byte[] binaryData = sqlTemplate.queryForBlob(sql, lobColumn.getJdbcTypeCode(),
                            lobColumn.getJdbcTypeName(), args);
                    if (binaryData != null) {
                        if (batch.getBinaryEncoding() == BinaryEncoding.BASE64) {
                            valueForCsv = new String(Base64.encodeBase64(binaryData));
                        } else if (batch.getBinaryEncoding() == BinaryEncoding.HEX) {
                            valueForCsv = new String(Hex.encodeHex(binaryData));
                        } else {
                            valueForCsv = new String(binaryData);
                        }
                        binaryData = null;
                    }
                } else {
                    valueForCsv = sqlTemplate.queryForClob(sql, lobColumn.getJdbcTypeCode(),
                            lobColumn.getJdbcTypeName(), args);
                }

                int index = ArrayUtils.indexOf(columnNames, lobColumn.getName());
                rowData[index] = valueForCsv;

            }

            data.putParsedData(CsvData.ROW_DATA, rowData);
        }
    }
    return data;
}