Example usage for java.util List set

List of usage examples for java.util List set

Introduction

In this page you can find the example usage for java.util List set.

Prototype

E set(int index, E element);

Source Link

Document

Replaces the element at the specified position in this list with the specified element (optional operation).

Usage

From source file:com.axelor.meta.service.MetaGroupMenuAssistantService.java

private List<String[]> createHeader(MetaGroupMenuAssistant groupMenuAssistant) throws IOException {

    CSVReader csvReader = null;// ww  w .  ja v  a  2  s .co m
    MetaFile metaFile = groupMenuAssistant.getMetaFile();
    List<String[]> rows = new ArrayList<String[]>();
    if (metaFile != null) {
        File csvFile = MetaFiles.getPath(metaFile).toFile();
        csvReader = new CSVReader(new FileReader(csvFile), ';');
        rows = csvReader.readAll();
        csvReader.close();
    }
    if (!rows.isEmpty()) {
        rows.set(0, getGroupRow(rows.get(0), groupMenuAssistant.getGroupSet()));
    } else {
        rows.add(getGroupRow(null, groupMenuAssistant.getGroupSet()));
    }

    return rows;

}

From source file:com.mythesis.userbehaviouranalysis.DBpediaSpotlightClient.java

/**
 * Method to count the statistics for the entities and categories
 * @param url_check the url for which we 'll find the semantic statistics
 * @param wordvector a profile's word vector
 *//*from  w ww . j  a  va  2 s  . c  om*/
public void countEntCat(String url_check, List<String> wordvector) {

    System.out.println("Calculating statistics for url = " + url_check);
    try {
        //we get the entities and categories
        extract(url_check);

        //convert each word to lower case
        for (int i = 0; i < wordvector.size(); i++)
            wordvector.set(i, wordvector.get(i).toLowerCase());

        //find the percentage of webpage's entities that include a wordvector's word
        int ent_cnt = 0;
        for (String s : entitiesString) {
            for (String word : wordvector) {
                if (s.contains(word)) {
                    ent_cnt++;
                    break;
                }
            }
        }

        if (ent_cnt != 0)
            ent_perc_dbpspot = (double) ent_cnt / entitiesString.size();

        //find the average similarity score, support and the percentage of entities that dont have 
        //a second candidate for the entities that include a wordvector's word
        int ent_count_all = 0;
        int ent_noSecondCandidate_cnt = 0;
        double ent_sim_cnt = 0.0;
        double ent_sup_cnt = 0.0;
        for (int i = 0; i < allEntities.size(); i++) {
            for (String word : wordvector) {
                if (allEntities.get(i).contains(word)) {
                    ent_count_all++;
                    ent_sim_cnt += similarityScores.get(i);
                    ent_sup_cnt += supports.get(i);
                    if (noSecondCandidate.get(i))
                        ent_noSecondCandidate_cnt++;
                    break;
                }
            }
        }

        if (ent_count_all != 0) {
            ent_avg_score = (double) ent_sim_cnt / ent_count_all;
            ent_avg_support = (double) ent_sup_cnt / ent_count_all;
            ent_perc_noSecCandidate = (double) ent_noSecondCandidate_cnt / ent_count_all;
        }

        //find the percentage of webpage's categories that include a wordvector's word
        int cat_cnt = 0;
        for (String s : typesDBspot) {
            for (String word : wordvector) {
                if (s.contains(word)) {
                    cat_cnt++;
                    break;
                }
            }
        }

        if (cat_cnt != 0)
            cat_perc_dbpspot = (double) cat_cnt / typesDBspot.size();

    } catch (Exception ex) {
        Logger.getLogger(DBpediaSpotlightClient.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.janrain.backplane.server.dao.redis.RedisBackplaneMessageDAO.java

/**
 * Fetch a list (possibly empty) of backplane messages that exist on the channel
 * and return them in order by message id
 * @param channel/*from w  w  w . ja  v  a  2  s .  c o m*/
 * @return
 */

public List<BackplaneMessage> getMessagesByChannel(String bus, String channel, String since, String sticky)
        throws SimpleDBException, BackplaneServerException {

    Jedis jedis = null;

    try {

        jedis = Redis.getInstance().getReadJedis();

        double sinceInMs = 0;
        if (StringUtils.isNotBlank(since)) {
            sinceInMs = BackplaneMessage.getDateFromId(since).getTime();
        }

        // every message has a unique timestamp - which serves as a key for indexing
        List<byte[]> messageIdBytes = jedis.lrange(getChannelKey(channel), 0, -1);
        List<BackplaneMessage> messages = new ArrayList<BackplaneMessage>();

        if (!messageIdBytes.isEmpty()) {
            int i = 0;
            for (byte[] key : messageIdBytes) {
                messageIdBytes.set(i++, getKey(new String(key)));
            }

            List<byte[]> responses = jedis.mget(messageIdBytes.toArray(new byte[messageIdBytes.size()][]));
            for (byte[] response : responses) {
                if (response != null) {
                    messages.add((BackplaneMessage) SerializationUtils.deserialize(response));
                }
            }
        }

        filterAndSort(messages, since, sticky);
        return messages;

    } catch (JedisConnectionException jce) {
        logger.warn("connection broken on bus " + bus + " and channel " + channel);
        Redis.getInstance().releaseBrokenResourceToPool(jedis);
        jedis = null;
        throw new BackplaneServerException(jce.getMessage(), jce);
    } catch (Exception e) {
        logger.error("Exception on bus " + bus + " and channel " + channel, e);
        throw new BackplaneServerException(e.getMessage(), e);
    } finally {
        Redis.getInstance().releaseToPool(jedis);
    }

}

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.SubstituteVariableVisitor.java

@Override
public Void visitAggregateOperator(AggregateOperator op, Pair<LogicalVariable, LogicalVariable> pair)
        throws AlgebricksException {
    List<LogicalVariable> variables = op.getVariables();
    int n = variables.size();
    for (int i = 0; i < n; i++) {
        if (variables.get(i).equals(pair.first)) {
            variables.set(i, pair.second);
        } else {/*ww  w.  j a va  2s. c o m*/
            op.getExpressions().get(i).getValue().substituteVar(pair.first, pair.second);
        }
    }
    substVarTypes(op, pair);
    return null;
}

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.SubstituteVariableVisitor.java

@Override
public Void visitRunningAggregateOperator(RunningAggregateOperator op,
        Pair<LogicalVariable, LogicalVariable> pair) throws AlgebricksException {
    List<LogicalVariable> variables = op.getVariables();
    int n = variables.size();
    for (int i = 0; i < n; i++) {
        if (variables.get(i).equals(pair.first)) {
            variables.set(i, pair.second);
        } else {/*from  w w  w.ja  v  a 2  s.  c o  m*/
            op.getExpressions().get(i).getValue().substituteVar(pair.first, pair.second);
        }
    }
    substVarTypes(op, pair);
    return null;
}

From source file:juicebox.data.HiCFileTools.java

/**
 * Load the list of chromosomes based on given genome id or file
 *
 * @param idOrFile string//from ww  w. java  2 s . c om
 * @return list of chromosomes
 */
public static List<Chromosome> loadChromosomes(String idOrFile) {

    InputStream is = null;

    try {
        // Note: to get this to work, had to edit Intellij settings
        // so that "?*.sizes" are considered sources to be copied to class path
        is = ChromosomeSizes.class.getResourceAsStream(idOrFile + ".chrom.sizes");

        if (is == null) {
            // Not an ID,  see if its a file
            File file = new File(idOrFile);

            try {
                if (file.exists()) {
                    is = new FileInputStream(file);
                } else {
                    System.err.println("Could not find chromosome sizes file for: " + idOrFile);
                    System.exit(-3);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        List<Chromosome> chromosomes = new ArrayList<Chromosome>();
        chromosomes.add(0, null); // Index 0 reserved for "whole genome" pseudo-chromosome

        Pattern pattern = Pattern.compile("\t");
        BufferedReader reader = new BufferedReader(new InputStreamReader(is), HiCGlobals.bufferSize);
        String nextLine;
        long genomeLength = 0;
        int idx = 1;

        try {
            while ((nextLine = reader.readLine()) != null) {
                String[] tokens = pattern.split(nextLine);
                if (tokens.length == 2) {
                    String name = tokens[0];
                    int length = Integer.parseInt(tokens[1]);
                    genomeLength += length;
                    chromosomes.add(idx, new Chromosome(idx, name, length));
                    idx++;
                } else {
                    System.out.println("Skipping " + nextLine);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        // Add the "pseudo-chromosome" All, representing the whole genome.  Units are in kilo-bases
        chromosomes.set(0, new Chromosome(0, "All", (int) (genomeLength / 1000)));

        return chromosomes;
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:org.netxilia.spi.impl.storage.db.CellsMapper.java

private void saveNormalData(DbSheetStorageInfo sheetStorage, SheetDbSession session, SheetFullName sheetName,
        Collection<CellDataWithProperties> cells, List<DbColumnStorageInfo> columnStorage)
        throws NotFoundException {
    String valueTableName = sheetStorage.getDbTableName();
    DbTable valuesTable = session.getWorkbookData().getSchema().getTable(valueTableName);
    if (valuesTable == null) {
        // the table should be created by the sheet
        throw new StorageException("The table " + valueTableName + " does not exist");
    }//from www  .java2  s . c  o m
    // TODO - quick save for one cell

    // cells grouped by row
    // for each row, the map contains the value in the corresponding column position
    // the special generic value is used to mark a cell to be ignored when saving
    Map<Integer, List<IGenericValue>> rows = new LinkedHashMap<Integer, List<IGenericValue>>();
    for (CellDataWithProperties saveCell : cells) {
        if (!saveCell.getProperties().contains(CellData.Property.value)) {
            continue;
        }
        CellReference ref = saveCell.getCellData().getReference();
        List<IGenericValue> row = rows.get(ref.getRowIndex());
        if (row == null) {
            row = new ArrayList<IGenericValue>(ref.getColumnIndex() + 1);
            rows.put(ref.getRowIndex(), row);
        }
        CollectionUtils.atLeastSize(row, ref.getColumnIndex() + 1, GENERIC_VALUE_CREATOR);
        row.set(ref.getColumnIndex(), saveCell.getCellData().getValue());
    }

    // save each row
    for (Map.Entry<Integer, List<IGenericValue>> entry : rows.entrySet()) {
        saveRow(session, valuesTable, entry.getKey(), entry.getValue(), columnStorage);
    }
}

From source file:com.gargoylesoftware.js.CodeUpdater.java

private static void processFile(final File originalFile, final boolean isMain) throws IOException {
    String relativePath = originalFile.getPath().replace('\\', '/');
    relativePath = "com/gargoylesoftware/js/"
            + relativePath.substring(relativePath.indexOf("/jdk/") + "/jdk/".length());
    final String root = isMain ? "src/main/java/" : "src/test/java/";
    final File localFile = new File(root + relativePath);
    if (!localFile.exists()) {
        System.out.println("File doesn't locally exist: " + relativePath);
        return;/*ww  w .  j a  va2s . c om*/
    }
    final List<String> originalLines = FileUtils.readLines(originalFile);
    final List<String> localLines = FileUtils.readLines(localFile);

    while (!isCodeStart(originalLines.get(0))) {
        originalLines.remove(0);
    }
    for (int i = 0; i < localLines.size(); i++) {
        if (isCodeStart(localLines.get(i))) {
            while (i < localLines.size()) {
                localLines.remove(i);
            }
            break;
        }
    }
    for (int i = 0; i < originalLines.size(); i++) {
        String line = originalLines.get(i);
        line = line.replace("jdk.internal.org.objectweb.asm", "org.objectweb.asm");
        line = line.replace("jdk.nashorn.internal", "com.gargoylesoftware.js.nashorn.internal");
        line = line.replace("jdk/nashorn/internal", "com/gargoylesoftware/js/nashorn/internal");
        line = line.replace("jdk/nashorn/javaadapters", "com/gargoylesoftware/js/nashorn/javaadapters");
        line = line.replace("jdk.nashorn.api", "com.gargoylesoftware.js.nashorn.api");
        line = line.replace("jdk.nashorn.tools", "com.gargoylesoftware.js.nashorn.tools");
        line = line.replace("jdk.internal.dynalink", "com.gargoylesoftware.js.internal.dynalink");
        line = line.replace("  @Constructor",
                "  @com.gargoylesoftware.js.nashorn.internal.objects.annotations.Constructor");
        line = line.replace("  @Property",
                "  @com.gargoylesoftware.js.nashorn.internal.objects.annotations.Property");
        originalLines.set(i, line);
        if (line.equals("@jdk.Exported")) {
            originalLines.remove(i--);
        }
    }
    localLines.addAll(originalLines);
    FileUtils.writeLines(localFile, localLines);
}

From source file:com.haulmont.cuba.gui.data.impl.DsContextImpl.java

@SuppressWarnings("unchecked")
protected void repairReferences(Entity entity, Entity contextEntity) {
    MetaClass metaClass = metadata.getClassNN(entity.getClass());
    MetaClass contextEntityMetaClass = metadata.getClassNN(contextEntity.getClass());

    for (MetaProperty property : metaClass.getProperties()) {
        if (!property.getRange().isClass() || !property.getRange().asClass().equals(contextEntityMetaClass)
                || !PersistenceHelper.isLoaded(entity, property.getName()))
            continue;

        Object value = entity.getValue(property.getName());
        if (value != null) {
            if (property.getRange().getCardinality().isMany()) {
                Collection collection = (Collection) value;
                for (Object item : new ArrayList(collection)) {
                    if (contextEntity.equals(item) && contextEntity != item) {
                        if (collection instanceof List) {
                            List list = (List) collection;
                            list.set(list.indexOf(item), contextEntity);
                        } else {
                            collection.remove(item);
                            collection.add(contextEntity);
                        }/* w  w w. j av  a 2  s .  c  om*/
                    }
                }
            } else {
                if (contextEntity.equals(value) && contextEntity != value) {
                    entity.setValue(property.getName(), contextEntity);
                }
            }
        }
    }
}

From source file:com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI.java

@SuppressWarnings("unchecked")
public List<Node> selectList(Node contextNode, String xpath) {
    @SuppressWarnings("rawtypes")
    List nodes;/*from   w  w  w . java  2s. c  om*/
    try {
        nodes = JXPathContext.newContext(contextNode).selectNodes(xpath);
        int i = 0;
        for (Object node : nodes) {
            if (node instanceof String) {
                node = contextNode.getOwnerDocument().createTextNode((String) node);
                nodes.set(i, node);
            }
            i++;
        }
    } catch (Exception e) {
        nodes = Collections.emptyList();
    }
    return (List<Node>) nodes;
}