Example usage for com.google.common.collect Table put

List of usage examples for com.google.common.collect Table put

Introduction

In this page you can find the example usage for com.google.common.collect Table put.

Prototype

@Nullable
V put(R rowKey, C columnKey, V value);

Source Link

Document

Associates the specified value with the specified keys.

Usage

From source file:paquete.AnalizadorSemantico.java

public Relacion Igual(NodoBase ni, NodoBase nd, Relacion relacion) {

    Table<Integer, String, Object> relacionTemporal = HashBasedTable.create();
    int j = 0;//from w ww.j a  v a2s.c  o  m
    if (checkTipos(ni, nd, relacion.getAtributos(), relacion.getTipos())) {

        if (ni instanceof NodoAtributo && nd instanceof NodoAtributo) {

            for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                if (relacion.getDatos().get(i, ni.getToken().getValor())
                        .equals(relacion.getDatos().get(i, nd.getToken().getValor()))) {

                    for (int col = 0; col < relacion.getAtributos().length; col++) {
                        relacionTemporal.put(j, relacion.getAtributos()[col],
                                relacion.getDatos().get(i, relacion.getAtributos()[col]));

                    }
                    j++;
                }
            }

        }

        else {

            for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                double temp;
                String tempS = nd.getToken().getValor();
                Date tempD = null;

                if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Double) {
                    temp = Double.parseDouble(nd.getToken().getValor());
                    if (relacion.getDatos().get(i, ni.getToken().getValor()).equals(temp)) {
                        for (int a = 0; a < relacion.getAtributos().length; a++) {
                            relacionTemporal.put(j, relacion.getAtributos()[a],
                                    relacion.getDatos().get(i, relacion.getAtributos()[a]));

                        }
                        j++;
                    }
                }

                else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String)
                    if (relacion.getDatos().get(i, ni.getToken().getValor()).equals(tempS)) {
                        for (int a = 0; a < relacion.getAtributos().length; a++) {
                            relacionTemporal.put(j, relacion.getAtributos()[a],
                                    relacion.getDatos().get(i, relacion.getAtributos()[a]));

                        }
                        j++;
                    }

                    else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Date) {
                        DateFormat df = new SimpleDateFormat("dd/mm/yyyy");
                        try {
                            tempD = df.parse(nd.getToken().getValor());
                        } catch (ParseException ex) {
                            Logger.getLogger(AnalizadorSemantico.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String)
                            if (relacion.getDatos().get(i, ni.getToken().getValor()).equals(tempD)) {
                                for (int a = 0; a < relacion.getAtributos().length; a++) {
                                    relacionTemporal.put(j, relacion.getAtributos()[a],
                                            relacion.getDatos().get(i, relacion.getAtributos()[a]));

                                }
                                j++;
                            }

                    }

            }
        }

    }
    if (!relacionTemporal.isEmpty())
        return new Relacion("", relacion.getAtributos(), relacion.getTipos(), relacionTemporal);

    else
        return null;

}

From source file:paquete.AnalizadorSemantico.java

public Relacion Diferente(NodoBase ni, NodoBase nd, Relacion relacion) {

    Table<Integer, String, Object> relacionTemporal = HashBasedTable.create();
    int j = 0;//from  w ww.  j a  v  a 2s  .  com
    if (checkTipos(ni, nd, relacion.getAtributos(), relacion.getTipos())) {

        if (ni instanceof NodoAtributo && nd instanceof NodoAtributo) {

            for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                if (!relacion.getDatos().get(i, ni.getToken().getValor())
                        .equals(relacion.getDatos().get(i, nd.getToken().getValor()))) {

                    for (int col = 0; col < relacion.getAtributos().length; col++) {
                        relacionTemporal.put(j, relacion.getAtributos()[col],
                                relacion.getDatos().get(i, relacion.getAtributos()[col]));

                    }
                    j++;
                }
            }

        }

        else {

            for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                double temp;
                String tempS = nd.getToken().getValor();
                Date tempD = null;

                if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Double) {
                    temp = Double.parseDouble(nd.getToken().getValor());
                    if (!relacion.getDatos().get(i, ni.getToken().getValor()).equals(temp)) {
                        for (int a = 0; a < relacion.getAtributos().length; a++) {
                            relacionTemporal.put(j, relacion.getAtributos()[a],
                                    relacion.getDatos().get(i, relacion.getAtributos()[a]));

                        }
                        j++;
                    }
                }

                else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String)
                    if (!relacion.getDatos().get(i, ni.getToken().getValor()).equals(tempS)) {
                        for (int a = 0; a < relacion.getAtributos().length; a++) {
                            relacionTemporal.put(j, relacion.getAtributos()[a],
                                    relacion.getDatos().get(i, relacion.getAtributos()[a]));

                        }
                        j++;
                    }

                    else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Date) {
                        DateFormat df = new SimpleDateFormat("dd/mm/yyyy");
                        try {
                            tempD = df.parse(nd.getToken().getValor());
                        } catch (ParseException ex) {
                            Logger.getLogger(AnalizadorSemantico.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String)
                            if (!relacion.getDatos().get(i, ni.getToken().getValor()).equals(tempD)) {
                                for (int a = 0; a < relacion.getAtributos().length; a++) {
                                    relacionTemporal.put(j, relacion.getAtributos()[a],
                                            relacion.getDatos().get(i, relacion.getAtributos()[a]));

                                }
                                j++;
                            }

                    }

            }
        }

    }
    if (!relacionTemporal.isEmpty())
        return new Relacion("", relacion.getAtributos(), relacion.getTipos(), relacionTemporal);

    else
        return null;

}

From source file:librec.data.DataDAO.java

/**
 * Read data from the data file. Note that we didn't take care of the duplicated lines.
 * /* w  w  w.  jav  a 2 s . c o m*/
 * @param cols
 *            the indexes of the relevant columns in the data file: {user, item, [rating, timestamp] (optional)}
 * @param binThold
 *            the threshold to binarize a rating. If a rating is greater than the threshold, the value will be 1;
 *            otherwise 0. To disable this feature, i.e., keep the original rating value, set the threshold a
 *            negative value
 * @return a sparse matrix storing all the relevant data
 */
public SparseMatrix[] readData(int[] cols, double binThold) throws Exception {

    Logs.info(String.format("Dataset: %s", Strings.last(dataPath, 38)));

    // Table {row-id, col-id, rate}
    Table<Integer, Integer, Double> dataTable = HashBasedTable.create();
    // Table {row-id, col-id, timestamp}
    Table<Integer, Integer, Long> timeTable = null;
    // Map {col-id, multiple row-id}: used to fast build a rating matrix
    Multimap<Integer, Integer> colMap = HashMultimap.create();

    BufferedReader br = FileIO.getReader(dataPath);
    String line = null;
    minTimestamp = Long.MAX_VALUE;
    maxTimestamp = Long.MIN_VALUE;
    while ((line = br.readLine()) != null) {
        if (isHeadline()) {
            setHeadline(false);
            continue;
        }

        String[] data = line.trim().split("[ \t,]+");

        String user = data[cols[0]];
        String item = data[cols[1]];
        Double rate = (cols.length >= 3 && data.length >= 3) ? Double.valueOf(data[cols[2]]) : 1.0;
        //System.out.println(user + " @" + item+" @"+rate);
        // binarize the rating for item recommendation task
        if (binThold >= 0)
            rate = rate > binThold ? 1.0 : 0.0;

        scaleDist.add(rate);

        // inner id starting from 0
        int row = userIds.containsKey(user) ? userIds.get(user) : userIds.size();
        userIds.put(user, row);

        int col = itemIds.containsKey(item) ? itemIds.get(item) : itemIds.size();
        itemIds.put(item, col);

        dataTable.put(row, col, rate);
        colMap.put(col, row);

        // record rating's issuing time
        if (cols.length >= 4 && data.length >= 4) {
            if (timeTable == null)
                timeTable = HashBasedTable.create();

            // convert to million-seconds
            long mms = 0L;
            try {
                mms = Long.parseLong(data[cols[3]]); // cannot format "9.7323480e+008"
            } catch (NumberFormatException e) {
                mms = (long) Double.parseDouble(data[cols[3]]);
            }
            long timestamp = timeUnit.toMillis(mms);

            if (minTimestamp > timestamp)
                minTimestamp = timestamp;

            if (maxTimestamp < timestamp)
                maxTimestamp = timestamp;

            timeTable.put(row, col, timestamp);
        }

    }
    br.close();

    numRatings = scaleDist.size();
    ratingScale = new ArrayList<>(scaleDist.elementSet());
    Collections.sort(ratingScale);

    int numRows = numUsers(), numCols = numItems();

    // if min-rate = 0.0, shift upper a scale
    double minRate = ratingScale.get(0).doubleValue();
    double epsilon = minRate == 0.0 ? ratingScale.get(1).doubleValue() - minRate : 0;
    if (epsilon > 0) {
        // shift upper a scale
        for (int i = 0, im = ratingScale.size(); i < im; i++) {
            double val = ratingScale.get(i);
            ratingScale.set(i, val + epsilon);
        }
        // update data table
        for (int row = 0; row < numRows; row++) {
            for (int col = 0; col < numCols; col++) {
                if (dataTable.contains(row, col))
                    dataTable.put(row, col, dataTable.get(row, col) + epsilon);
            }
        }
    }

    String dateRange = "";
    if (cols.length >= 4)
        dateRange = String.format(", Timestamps = {%s, %s}", Dates.toString(minTimestamp),
                Dates.toString(maxTimestamp));

    Logs.debug("With Specs: {Users, {}} = {{}, {}, {}}, Scale = {{}}{}",
            (isItemAsUser ? "Users, Links" : "Items, Ratings"), numRows, numCols, numRatings,
            Strings.toString(ratingScale), dateRange);

    // build rating matrix
    rateMatrix = new SparseMatrix(numRows, numCols, dataTable, colMap);

    if (timeTable != null)
        timeMatrix = new SparseMatrix(numRows, numCols, timeTable, colMap);

    // release memory of data table
    dataTable = null;
    timeTable = null;

    return new SparseMatrix[] { rateMatrix, timeMatrix };
}

From source file:uk.ac.open.kmi.iserve.discovery.disco.impl.SparqlLogicConceptMatcher.java

/**
 * Obtain all match results for the set of origins that are within a range of match types
 * TODO: This method is buggy. To be fixed
 *
 * @param origins/*from   w w  w . ja  v a  2  s.  c o  m*/
 * @param minType
 * @param maxType
 * @return
 */
private Table<URI, URI, MatchResult> obtainMatchResults(Set<URI> origins, MatchType minType,
        MatchType maxType) {

    log.debug("Obtain match results for {}, with {} <= Match Result <= {}", origins, minType, maxType);

    Table<URI, URI, MatchResult> result = HashBasedTable.create();
    // Exit fast if no data is provided or no matches can be found
    if (origins == null || origins.isEmpty() || minType.compareTo(maxType) > 0)
        return result;

    // Create the query
    String queryStr = new StringBuffer().append(generateQueryHeader())
            .append(generateRangeMatchWhereClause(origins, minType, maxType)).append(generateQueryFooter())
            .toString();

    log.debug("SPARQL Query generated: \n {}", queryStr);

    // Query the engine
    Query query = QueryFactory.create(queryStr);
    QueryExecution qe = QueryExecutionFactory.sparqlService(this.sparqlEndpoint.toASCIIString(), query);
    MonitoredQueryExecution qexec = new MonitoredQueryExecution(qe);
    try {
        Stopwatch stopwatch = new Stopwatch().start();
        ResultSet qResults = qexec.execSelect();
        stopwatch.stop();
        log.debug("Obtained matches for {} concepts within range {} - {} in {}", origins.size(), minType,
                maxType, stopwatch);

        Resource origin;
        Resource destination;
        URI originUri;
        URI matchUri;
        int index = 0;
        // Iterate over the results obtained starting with the matches for class0 onwards
        while (qResults.hasNext()) {
            QuerySolution soln = qResults.nextSolution();
            origin = soln.getResource(ORIGIN_VAR);
            destination = soln.getResource(MATCH_VAR + index);

            if (origin != null && origin.isURIResource() && destination != null
                    && destination.isURIResource()) {
                originUri = new URI(origin.getURI());
                matchUri = new URI(destination.getURI());
                MatchType type = getMatchType(soln);
                result.put(originUri, matchUri, new AtomicMatchResult(originUri, matchUri, type, this));
                log.debug("Concept {} was matched to {} with type {}", originUri, matchUri, type);
            } else {
                log.warn("Skipping result as some URI is null: Origin - {}, Destination - {}", origin,
                        destination);
                break;
            }
        }
    } catch (URISyntaxException e) {
        log.error("Error obtaining match result. Expected a correct URI", e);
    } finally {
        qexec.close();
    }
    return result;

}

From source file:ca.wumbo.wdl.parser.Player.java

/**
 * A central refactored method for handling damage.
 * //from www. j av a2s.  c  o  m
 * @param target
 *       The player that is killed.
 * 
 * @param weapon
 *       The weapon mod.
 * 
 * @param dmgTbl
 *       The table to be updated.
 * 
 * @param enemyHpDmg
 *       The enemy's HP damage given.
 * 
 * @param enemyArmorDmg
 *       The enemy's armor damage given.
 * 
 * @param normalizedGametic
 *       The gametic this occured on.
 * 
 * @throws CorruptStatFileException
 *       If the enemy health goes under 0 HP.
 */
private void handleDamageFor(Player target, WeaponModType weapon,
        Table<Player, WeaponModType, DamageData> dmgTbl, int enemyHpDmg, int enemyArmorDmg,
        int normalizedGametic) {
    assert target != null;
    assert weapon != null;
    assert dmgTbl != null;
    assert enemyHpDmg >= 0 && enemyHpDmg <= 200;
    assert enemyArmorDmg >= 0 && enemyArmorDmg <= 200;
    assert normalizedGametic >= 0;

    // Do nothing if we somehow manage to damage our allies (which shouldn't be possible).
    if (getTeam() == target.getTeam()) {
        return;
    }

    DamageData dmgData = null;
    if (!dmgTbl.contains(target, weapon)) {
        dmgData = new DamageData();
        dmgTbl.put(target, weapon, dmgData);
    } else {
        dmgData = dmgTbl.get(target, weapon);
    }

    dmgData.incrementHp(enemyHpDmg);
    target.currentHealth -= enemyHpDmg;
    if (target.hasBlueArmor) {
        dmgData.incrementBlueArmor(enemyArmorDmg);
        target.currentBlueArmor -= enemyArmorDmg;
    } else {
        dmgData.incrementGreenArmor(enemyArmorDmg);
        target.currentGreenArmor -= enemyArmorDmg;
    }

    if (hasFlag) {
        damageOutputBetweenTouchAndCapture.add(enemyHpDmg);
        totalCarrierDamageHPOutput += enemyHpDmg;
    } else {
        totalDamageHPOutput += enemyHpDmg;
    }

    // Sometimes the port reports weird values, so clamp it.
    target.currentHealth = Math.max(target.currentHealth, 0);
}

From source file:org.eclipse.tracecompass.tmf.core.event.matching.TmfNetworkEventMatching.java

@Override
public synchronized void matchEvent(ITmfEvent event, ITmfTrace trace) {
    ITmfNetworkMatchDefinition def = null;
    Direction evType = null;//from   ww  w  . java2 s  . c o  m
    for (ITmfMatchEventDefinition oneDef : getEventDefinitions(event.getTrace())) {
        if (oneDef instanceof ITmfNetworkMatchDefinition) {
            def = (ITmfNetworkMatchDefinition) oneDef;
            evType = def.getDirection(event);
            if (evType != null) {
                break;
            }
        }
    }

    if (def == null || evType == null) {
        return;
    }

    /* Get the event's unique fields */
    IEventMatchingKey eventKey = def.getEventKey(event);

    if (eventKey == null) {
        return;
    }
    Table<ITmfTrace, IEventMatchingKey, ITmfEvent> unmatchedTbl, companionTbl;

    /* Point to the appropriate table */
    switch (evType) {
    case IN:
        unmatchedTbl = fUnmatchedIn;
        companionTbl = fUnmatchedOut;
        break;
    case OUT:
        unmatchedTbl = fUnmatchedOut;
        companionTbl = fUnmatchedIn;
        break;
    default:
        return;
    }

    boolean found = false;
    TmfEventDependency dep = null;
    /* Search for the event in the companion table */
    for (ITmfTrace mTrace : getIndividualTraces()) {
        if (companionTbl.contains(mTrace, eventKey)) {
            found = true;
            ITmfEvent companionEvent = companionTbl.get(mTrace, eventKey);

            /* Remove the element from the companion table */
            companionTbl.remove(mTrace, eventKey);

            /* Create the dependency object */
            switch (evType) {
            case IN:
                dep = new TmfEventDependency(companionEvent, event);
                break;
            case OUT:
                dep = new TmfEventDependency(event, companionEvent);
                break;
            default:
                break;

            }
        }
    }

    /*
     * If no companion was found, add the event to the appropriate unMatched
     * lists
     */
    if (found) {
        getProcessingUnit().addMatch(dep);
    } else {
        /*
         * If an event is already associated with this key, do not add it
         * again, we keep the first event chronologically, so if its match
         * is eventually found, it is associated with the first send or
         * receive event. At best, it is a good guess, at worst, the match
         * will be too far off to be accurate. Too bad!
         *
         * TODO: maybe instead of just one event, we could have a list of
         * events as value for the unmatched table. Not necessary right now
         * though
         */
        if (!unmatchedTbl.contains(event.getTrace(), eventKey)) {
            unmatchedTbl.put(event.getTrace(), eventKey, event);
        }
    }

}

From source file:paquete.AnalizadorSemantico.java

public Relacion Mayor(NodoBase ni, NodoBase nd, Relacion relacion) {

    Table<Integer, String, Object> relacionTemporal = HashBasedTable.create();
    int j = 0;/*from   ww w  .j  a va  2s .c  om*/
    if (checkTipos(ni, nd, relacion.getAtributos(), relacion.getTipos())) {

        if (ni instanceof NodoAtributo && nd instanceof NodoAtributo) {

            if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof Double) {
                for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                    if ((Double) relacion.getDatos().get(i, ni.getToken().getValor()) > (Double) (relacion
                            .getDatos().get(i, nd.getToken().getValor()))) {

                        for (int col = 0; col < relacion.getAtributos().length; col++) {
                            relacionTemporal.put(j, relacion.getAtributos()[col],
                                    relacion.getDatos().get(i, relacion.getAtributos()[col]));

                        }
                        j++;
                    }
                }
            }

            if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof Date) {
                for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                    if (((Date) relacion.getDatos().get(i, ni.getToken().getValor()))
                            .after((Date) (relacion.getDatos().get(i, nd.getToken().getValor())))) {

                        for (int col = 0; col < relacion.getAtributos().length; col++) {
                            relacionTemporal.put(j, relacion.getAtributos()[col],
                                    relacion.getDatos().get(i, relacion.getAtributos()[col]));

                        }
                        j++;
                    }
                }
            }

            if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof String) {
                for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                    if (((String) relacion.getDatos().get(i, ni.getToken().getValor()))
                            .compareTo((String) (relacion.getDatos().get(i, nd.getToken().getValor()))) > 0) {

                        for (int col = 0; col < relacion.getAtributos().length; col++) {
                            relacionTemporal.put(j, relacion.getAtributos()[col],
                                    relacion.getDatos().get(i, relacion.getAtributos()[col]));

                        }
                        j++;
                    }
                }
            }

        }

        else {

            for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                double temp;
                String tempS = nd.getToken().getValor();
                Date tempD = null;

                if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Double) {
                    temp = Double.parseDouble(nd.getToken().getValor());
                    if ((Double) relacion.getDatos().get(i, ni.getToken().getValor()) > (temp)) {
                        for (int a = 0; a < relacion.getAtributos().length; a++) {
                            relacionTemporal.put(j, relacion.getAtributos()[a],
                                    relacion.getDatos().get(i, relacion.getAtributos()[a]));

                        }
                        j++;
                    }
                }

                else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String)
                    if (((String) relacion.getDatos().get(i, ni.getToken().getValor())).compareTo(tempS) > 0) {
                        for (int a = 0; a < relacion.getAtributos().length; a++) {
                            relacionTemporal.put(j, relacion.getAtributos()[a],
                                    relacion.getDatos().get(i, relacion.getAtributos()[a]));

                        }
                        j++;
                    }

                    else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Date) {
                        DateFormat df = new SimpleDateFormat("dd/mm/yyyy");
                        try {
                            tempD = df.parse(nd.getToken().getValor());
                        } catch (ParseException ex) {
                            Logger.getLogger(AnalizadorSemantico.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String)
                            if (((Date) relacion.getDatos().get(i, ni.getToken().getValor())).after(tempD)) {
                                for (int a = 0; a < relacion.getAtributos().length; a++) {
                                    relacionTemporal.put(j, relacion.getAtributos()[a],
                                            relacion.getDatos().get(i, relacion.getAtributos()[a]));

                                }
                                j++;
                            }

                    }

            }
        }

    }
    if (!relacionTemporal.isEmpty())
        return new Relacion("", relacion.getAtributos(), relacion.getTipos(), relacionTemporal);

    else
        return null;

}

From source file:paquete.AnalizadorSemantico.java

public Relacion Menor(NodoBase ni, NodoBase nd, Relacion relacion) {

    Table<Integer, String, Object> relacionTemporal = HashBasedTable.create();
    int j = 0;//from   www. ja v a2  s  . com
    if (checkTipos(ni, nd, relacion.getAtributos(), relacion.getTipos())) {

        if (ni instanceof NodoAtributo && nd instanceof NodoAtributo) {

            if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof Double) {
                for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                    if ((Double) relacion.getDatos().get(i, ni.getToken().getValor()) < (Double) (relacion
                            .getDatos().get(i, nd.getToken().getValor()))) {

                        for (int col = 0; col < relacion.getAtributos().length; col++) {
                            relacionTemporal.put(j, relacion.getAtributos()[col],
                                    relacion.getDatos().get(i, relacion.getAtributos()[col]));

                        }
                        j++;
                    }
                }
            }

            if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof Date) {
                for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                    if (((Date) relacion.getDatos().get(i, ni.getToken().getValor()))
                            .before((Date) (relacion.getDatos().get(i, nd.getToken().getValor())))) {

                        for (int col = 0; col < relacion.getAtributos().length; col++) {
                            relacionTemporal.put(j, relacion.getAtributos()[col],
                                    relacion.getDatos().get(i, relacion.getAtributos()[col]));

                        }
                        j++;
                    }
                }
            }

            if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof String) {
                for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                    if (((String) relacion.getDatos().get(i, ni.getToken().getValor()))
                            .compareTo((String) (relacion.getDatos().get(i, nd.getToken().getValor()))) < 0) {

                        for (int col = 0; col < relacion.getAtributos().length; col++) {
                            relacionTemporal.put(j, relacion.getAtributos()[col],
                                    relacion.getDatos().get(i, relacion.getAtributos()[col]));

                        }
                        j++;
                    }
                }
            }

        }

        else {

            for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                double temp;
                String tempS = nd.getToken().getValor();
                Date tempD = null;

                if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Double) {
                    temp = Double.parseDouble(nd.getToken().getValor());
                    if ((Double) relacion.getDatos().get(i, ni.getToken().getValor()) < (temp)) {
                        for (int a = 0; a < relacion.getAtributos().length; a++) {
                            relacionTemporal.put(j, relacion.getAtributos()[a],
                                    relacion.getDatos().get(i, relacion.getAtributos()[a]));

                        }
                        j++;
                    }
                }

                else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String)
                    if (((String) relacion.getDatos().get(i, ni.getToken().getValor())).compareTo(tempS) < 0) {
                        for (int a = 0; a < relacion.getAtributos().length; a++) {
                            relacionTemporal.put(j, relacion.getAtributos()[a],
                                    relacion.getDatos().get(i, relacion.getAtributos()[a]));

                        }
                        j++;
                    }

                    else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Date) {
                        DateFormat df = new SimpleDateFormat("dd/mm/yyyy");
                        try {
                            tempD = df.parse(nd.getToken().getValor());
                        } catch (ParseException ex) {
                            Logger.getLogger(AnalizadorSemantico.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String)
                            if (((Date) relacion.getDatos().get(i, ni.getToken().getValor())).before(tempD)) {
                                for (int a = 0; a < relacion.getAtributos().length; a++) {
                                    relacionTemporal.put(j, relacion.getAtributos()[a],
                                            relacion.getDatos().get(i, relacion.getAtributos()[a]));

                                }
                                j++;
                            }

                    }

            }
        }

    }
    if (!relacionTemporal.isEmpty())
        return new Relacion("", relacion.getAtributos(), relacion.getTipos(), relacionTemporal);

    else
        return null;

}

From source file:paquete.AnalizadorSemantico.java

public Relacion MayorIgual(NodoBase ni, NodoBase nd, Relacion relacion) {

    Table<Integer, String, Object> relacionTemporal = HashBasedTable.create();
    int j = 0;/*from  ww w  . ja va2 s . c  om*/
    if (checkTipos(ni, nd, relacion.getAtributos(), relacion.getTipos())) {

        if (ni instanceof NodoAtributo && nd instanceof NodoAtributo) {

            if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof Double) {
                for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                    if ((Double) relacion.getDatos().get(i, ni.getToken().getValor()) >= (Double) (relacion
                            .getDatos().get(i, nd.getToken().getValor()))) {

                        for (int col = 0; col < relacion.getAtributos().length; col++) {
                            relacionTemporal.put(j, relacion.getAtributos()[col],
                                    relacion.getDatos().get(i, relacion.getAtributos()[col]));

                        }
                        j++;
                    }
                }
            }

            if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof Date) {
                for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                    if (((Date) relacion.getDatos().get(i, ni.getToken().getValor()))
                            .after((Date) (relacion.getDatos().get(i, nd.getToken().getValor())))
                            || ((Date) relacion.getDatos().get(i, ni.getToken().getValor()))
                                    .equals((Date) (relacion.getDatos().get(i, nd.getToken().getValor())))) {

                        for (int col = 0; col < relacion.getAtributos().length; col++) {
                            relacionTemporal.put(j, relacion.getAtributos()[col],
                                    relacion.getDatos().get(i, relacion.getAtributos()[col]));

                        }
                        j++;
                    }
                }
            }

            if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof String) {
                for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                    if (((String) relacion.getDatos().get(i, ni.getToken().getValor()))
                            .compareTo((String) (relacion.getDatos().get(i, nd.getToken().getValor()))) >= 0) {

                        for (int col = 0; col < relacion.getAtributos().length; col++) {
                            relacionTemporal.put(j, relacion.getAtributos()[col],
                                    relacion.getDatos().get(i, relacion.getAtributos()[col]));

                        }
                        j++;
                    }
                }
            }

        }

        else {

            for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                double temp;
                String tempS = nd.getToken().getValor();
                Date tempD = null;

                if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Double) {
                    temp = Double.parseDouble(nd.getToken().getValor());
                    if ((Double) relacion.getDatos().get(i, ni.getToken().getValor()) >= (temp)) {
                        for (int a = 0; a < relacion.getAtributos().length; a++) {
                            relacionTemporal.put(j, relacion.getAtributos()[a],
                                    relacion.getDatos().get(i, relacion.getAtributos()[a]));

                        }
                        j++;
                    }
                }

                else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String)
                    if (((String) relacion.getDatos().get(i, ni.getToken().getValor())).compareTo(tempS) >= 0) {
                        for (int a = 0; a < relacion.getAtributos().length; a++) {
                            relacionTemporal.put(j, relacion.getAtributos()[a],
                                    relacion.getDatos().get(i, relacion.getAtributos()[a]));

                        }
                        j++;
                    }

                    else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Date) {
                        DateFormat df = new SimpleDateFormat("dd/mm/yyyy");
                        try {
                            tempD = df.parse(nd.getToken().getValor());
                        } catch (ParseException ex) {
                            Logger.getLogger(AnalizadorSemantico.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String)
                            if (((Date) relacion.getDatos().get(i, ni.getToken().getValor())).after(tempD)
                                    || ((Date) relacion.getDatos().get(i, ni.getToken().getValor()))
                                            .equals(tempD)) {
                                for (int a = 0; a < relacion.getAtributos().length; a++) {
                                    relacionTemporal.put(j, relacion.getAtributos()[a],
                                            relacion.getDatos().get(i, relacion.getAtributos()[a]));

                                }
                                j++;
                            }

                    }

            }
        }

    }
    if (!relacionTemporal.isEmpty())
        return new Relacion("", relacion.getAtributos(), relacion.getTipos(), relacionTemporal);

    else
        return null;

}

From source file:paquete.AnalizadorSemantico.java

public Relacion MenorIgual(NodoBase ni, NodoBase nd, Relacion relacion) {

    Table<Integer, String, Object> relacionTemporal = HashBasedTable.create();
    int j = 0;//ww  w  .  ja va 2 s.  c om
    if (checkTipos(ni, nd, relacion.getAtributos(), relacion.getTipos())) {

        if (ni instanceof NodoAtributo && nd instanceof NodoAtributo) {

            if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof Double) {
                for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                    if ((Double) relacion.getDatos().get(i, ni.getToken().getValor()) <= (Double) (relacion
                            .getDatos().get(i, nd.getToken().getValor()))) {

                        for (int col = 0; col < relacion.getAtributos().length; col++) {
                            relacionTemporal.put(j, relacion.getAtributos()[col],
                                    relacion.getDatos().get(i, relacion.getAtributos()[col]));

                        }
                        j++;
                    }
                }
            }

            if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof Date) {
                for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                    if (((Date) relacion.getDatos().get(i, ni.getToken().getValor()))
                            .before((Date) (relacion.getDatos().get(i, nd.getToken().getValor())))
                            || ((Date) relacion.getDatos().get(i, ni.getToken().getValor()))
                                    .equals((Date) (relacion.getDatos().get(i, nd.getToken().getValor())))) {

                        for (int col = 0; col < relacion.getAtributos().length; col++) {
                            relacionTemporal.put(j, relacion.getAtributos()[col],
                                    relacion.getDatos().get(i, relacion.getAtributos()[col]));

                        }
                        j++;
                    }
                }
            }

            if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof String) {
                for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                    if (((String) relacion.getDatos().get(i, ni.getToken().getValor()))
                            .compareTo((String) (relacion.getDatos().get(i, nd.getToken().getValor()))) <= 0) {

                        for (int col = 0; col < relacion.getAtributos().length; col++) {
                            relacionTemporal.put(j, relacion.getAtributos()[col],
                                    relacion.getDatos().get(i, relacion.getAtributos()[col]));

                        }
                        j++;
                    }
                }
            }

        }

        else {

            for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) {

                double temp;
                String tempS = nd.getToken().getValor();
                Date tempD = null;

                if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Double) {
                    temp = Double.parseDouble(nd.getToken().getValor());
                    if ((Double) relacion.getDatos().get(i, ni.getToken().getValor()) <= (temp)) {
                        for (int a = 0; a < relacion.getAtributos().length; a++) {
                            relacionTemporal.put(j, relacion.getAtributos()[a],
                                    relacion.getDatos().get(i, relacion.getAtributos()[a]));

                        }
                        j++;
                    }
                }

                else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String)
                    if (((String) relacion.getDatos().get(i, ni.getToken().getValor())).compareTo(tempS) <= 0) {
                        for (int a = 0; a < relacion.getAtributos().length; a++) {
                            relacionTemporal.put(j, relacion.getAtributos()[a],
                                    relacion.getDatos().get(i, relacion.getAtributos()[a]));

                        }
                        j++;
                    }

                    else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Date) {
                        DateFormat df = new SimpleDateFormat("dd/mm/yyyy");
                        try {
                            tempD = df.parse(nd.getToken().getValor());
                        } catch (ParseException ex) {
                            Logger.getLogger(AnalizadorSemantico.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String)
                            if (((Date) relacion.getDatos().get(i, ni.getToken().getValor())).before(tempD)
                                    || ((Date) relacion.getDatos().get(i, ni.getToken().getValor()))
                                            .equals(tempD)) {
                                for (int a = 0; a < relacion.getAtributos().length; a++) {
                                    relacionTemporal.put(j, relacion.getAtributos()[a],
                                            relacion.getDatos().get(i, relacion.getAtributos()[a]));

                                }
                                j++;
                            }

                    }

            }
        }

    }
    if (!relacionTemporal.isEmpty())
        return new Relacion("", relacion.getAtributos(), relacion.getTipos(), relacionTemporal);

    else
        return null;

}