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

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

Introduction

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

Prototype

Set<R> rowKeySet();

Source Link

Document

Returns a set of row keys that have one or more values in the table.

Usage

From source file:com.fredhopper.core.connector.index.generate.validator.IntAttributeValidator.java

@Override
protected boolean isValidSize(final FhAttributeData attribute, final List<Violation> violations) {
    final Table<Optional<String>, Optional<Locale>, String> values = attribute.getValues();
    if (values.isEmpty() || values.rowKeySet().size() != 1) {
        rejectValue(attribute, violations, "The \"int\" attribute can only have one value.");
        return false;
    }//from  w w w  .  j  a  va 2s  .  c  o  m
    return true;
}

From source file:com.fredhopper.core.connector.index.generate.validator.FloatAttributeValidator.java

@Override
protected boolean isValidSize(final FhAttributeData attribute, final List<Violation> violations) {
    final Table<Optional<String>, Optional<Locale>, String> values = attribute.getValues();
    if (values.isEmpty() || values.rowKeySet().size() != 1) {
        rejectValue(attribute, violations, "The \"float\" attribute can only have one value.");
        return false;
    }/*from w w  w  .j a  va2s  . com*/
    return true;
}

From source file:com.przemo.etl.dataproviders.DefaultDatabaseDataProvider.java

protected boolean executeQuery(DbConnector connector, Table Data, String basicQuery) {
    for (Object row : Data.rowKeySet()) {
        String vals = prepareQueryValues(Data, row);
        try {/*  www . j a  v  a 2  s  .  com*/
            if (connector != null) {
                connector.execute(basicQuery.replace(valsReplacer, vals));
            }
        } catch (Exception ex) {
            Logger.getLogger(DefaultDatabaseDataProvider.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    return true;
}

From source file:com.przemo.etl.transformations.FlatDateGapFiller.java

@Override
protected void fillGap(Integer previousKey, Integer rowNumber, Table<Integer, Object, Object> data) {
    Integer maxRowNumber = Collections.max(data.rowKeySet());
    if (gapColumn != null && data.get(previousKey, gapColumn) instanceof Date
            && data.get(rowNumber, gapColumn) instanceof Date) {
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
        c1.setTime((Date) data.get(previousKey, gapColumn));
        c2.setTime((Date) data.get(rowNumber, gapColumn));
        long r = (c2.getTimeInMillis() - c1.getTimeInMillis()) / (timeStep * getMilisOfField(timeField));
        Calendar cx = Calendar.getInstance();
        cx.setTimeInMillis(timeStep * getMilisOfField(timeField));
        while (c2.getTimeInMillis() > (c1.getTimeInMillis() + cx.getTimeInMillis())) {
            c1.setTimeInMillis(c1.getTimeInMillis() + cx.getTimeInMillis());
            data.put(++maxRowNumber, gapColumn, c1.getTime());
            for (Object s : data.columnKeySet()) {
                if (s instanceof String && !s.equals(gapColumn)) {
                    String col = (String) s;
                    data.put(maxRowNumber, col, data.get(previousKey, s));
                }/*  ww w. j  a v a  2 s .  c  o  m*/
            }
        }
    }

}

From source file:com.fredhopper.core.connector.index.generate.validator.ListAttributeValidator.java

@Override
protected boolean hasValidValueId(final FhAttributeData attribute, final List<Violation> violations) {
    final Table<Optional<String>, Optional<Locale>, String> values = attribute.getValues();
    for (final Optional<String> optional : values.rowKeySet()) {
        final String key = optional == null || !optional.isPresent() ? "_absent_" : optional.get();
        if (!key.matches(VALUE_ID_PATTERN)) {
            rejectValue(attribute, violations, "The \"list\" attribute valueId key \"" + key
                    + "\" does not match the appropriate pattern.");
            return false;
        }/*w w w .j  a v a2s .com*/
    }
    return true;
}

From source file:com.fredhopper.core.connector.index.generate.validator.SetAttributeValidator.java

@Override
protected boolean hasValidValueId(final FhAttributeData attribute, final List<Violation> violations) {
    final Table<Optional<String>, Optional<Locale>, String> values = attribute.getValues();
    for (final Optional<String> optional : values.rowKeySet()) {
        final String key = optional == null || !optional.isPresent() ? "_absent_" : optional.get();
        if (!key.matches(VALUE_ID_PATTERN)) {
            rejectValue(attribute, violations, "The \"set\" attribute valueId key \"" + key
                    + "\" does not match the appropriate pattern.");
            return false;
        }//from www  .  j a  v a 2 s  .  co m
    }
    return true;
}

From source file:com.fredhopper.core.connector.index.generate.validator.ListAttributeValidator.java

@Override
protected void validateValue(final FhAttributeData attribute, final List<Violation> violations) {
    final Table<Optional<String>, Optional<Locale>, String> values = attribute.getValues();
    for (final Optional<String> valueId : values.rowKeySet()) {
        final Map<Optional<Locale>, String> valueMap = values.row(valueId);
        if (CollectionUtils.isEmpty(valueMap) || valueMap.keySet().size() != 1
                || valueMap.containsKey(Optional.empty()) || valueMap.containsKey(null)) {
            rejectValue(attribute, violations, "The \"list\" attribute value unique Locale key must be set.");
            return;
        }//from w ww  . ja v  a  2s .  com
        if (valueMap.containsValue(null) || valueMap.containsValue("")) {
            rejectValue(attribute, violations, "The \"list\" attribute value must not be blank.");
            return;
        }
    }
}

From source file:com.fredhopper.core.connector.index.generate.validator.SetAttributeValidator.java

@Override
protected void validateValue(final FhAttributeData attribute,
        final List<com.fredhopper.core.connector.index.report.Violation> violations) {
    final Table<Optional<String>, Optional<Locale>, String> values = attribute.getValues();
    for (final Optional<String> valueId : values.rowKeySet()) {
        final Map<Optional<Locale>, String> valueMap = values.row(valueId);
        if (CollectionUtils.isEmpty(valueMap) || valueMap.containsKey(Optional.empty())
                || valueMap.containsKey(null)) {
            rejectValue(attribute, violations, "The \"set\" attribute Locale key must be set.");
            return;
        }/*from   w w w  .ja  v a2  s.c  o m*/
        if (valueMap.containsValue(null) || valueMap.containsValue("")) {
            rejectValue(attribute, violations, "The \"set\" attribute value must not be blank.");
            return;
        }
    }
}

From source file:de.tudarmstadt.ukp.dkpro.keyphrases.bookindexing.aggregation.aggregationstrategy.SumAggregation.java

@Override
public List<RankedPhrase> aggregatePhrases(Table<String, Integer, Double> phraseSegmentTable) {

    List<RankedPhrase> rankedPhrases = new ArrayList<RankedPhrase>();

    for (String phrase : phraseSegmentTable.rowKeySet()) {
        Collection<Double> segmentScores = phraseSegmentTable.row(phrase).values();
        Double newScore = sum(segmentScores);
        if (getLogger() != null && getLogger().isLoggable(Level.FINEST))
            getLogger().log(Level.FINEST,
                    String.format(Locale.US, "Summed score for phrase %s in %d segments was %.3f.", phrase,
                            segmentScores.size(), newScore));

        rankedPhrases.add(new RankedPhrase(phrase, newScore));

    }/*from  w ww  . j  a va  2  s  . co  m*/
    return rankedPhrases;

}

From source file:com.fredhopper.core.connector.index.generate.writer.AttributeCsvWriter.java

protected void printAttributeValueCollection(final FhAttributeData source) throws IOException {

    final Table<Optional<String>, Optional<Locale>, String> values = source.getValues();
    for (final Optional<String> valueId : values.rowKeySet()) {
        final String attributeValueId = valueId.isPresent() ? valueId.get() : EMPTY_VALUE;
        final Map<Optional<Locale>, String> valueMap = values.row(valueId);
        for (final Entry<Optional<Locale>, String> entry : valueMap.entrySet()) {
            printLine(source.getItemId(), entry.getKey().get().toString(), source.getAttributeId(),
                    attributeValueId, valueMap.get(entry.getKey()));
        }//from w  w w. ja v  a 2 s. co  m
    }
}