Example usage for java.util NavigableMap entrySet

List of usage examples for java.util NavigableMap entrySet

Introduction

In this page you can find the example usage for java.util NavigableMap entrySet.

Prototype

Set<Map.Entry<K, V>> entrySet();

Source Link

Document

Returns a Set view of the mappings contained in this map.

Usage

From source file:org.apache.hadoop.hbase.client.Mutation.java

/**
 * Method for setting the put's familyMap that is deprecated and inefficient.
 *
 * @deprecated use {@link #setFamilyCellMap(NavigableMap)} instead.
 *//*  w w w.  ja va 2 s .  c  o  m*/
@Deprecated
public Mutation setFamilyMap(NavigableMap<byte[], List<KeyValue>> map) {
    TreeMap<byte[], List<Cell>> fm = new TreeMap<byte[], List<Cell>>(Bytes.BYTES_COMPARATOR);
    for (Map.Entry<byte[], List<KeyValue>> e : map.entrySet()) {
        fm.put(e.getKey(), Lists.<Cell>newArrayList(e.getValue()));
    }
    this.familyMap = fm;
    return this;
}

From source file:com.twitter.hraven.datasource.AppSummaryService.java

/**
 * constructs App key from the result set based on cluster, user, appId
 * picks those results that satisfy the time range criteria
 * @param result//ww  w  . j  a  v  a2  s . c  o m
 * @param startTime
 * @param endTime
 * @return flow key
 * @throws IOException
 */
private AppKey getNewAppKeyFromResult(Result result, long startTime, long endTime) throws IOException {

    byte[] rowKey = result.getRow();
    byte[][] keyComponents = ByteUtil.split(rowKey, Constants.SEP_BYTES);
    String cluster = Bytes.toString(keyComponents[0]);
    String user = Bytes.toString(keyComponents[1]);
    String appId = Bytes.toString(keyComponents[2]);

    NavigableMap<byte[], byte[]> valueMap = result.getFamilyMap(Constants.INFO_FAM_BYTES);
    long runId = Long.MAX_VALUE;
    for (Map.Entry<byte[], byte[]> entry : valueMap.entrySet()) {
        long tsl = Bytes.toLong(entry.getValue());
        // get the earliest runid, which indicates the first time this app ran
        if (tsl < runId) {
            runId = tsl;
        }
    }
    if ((runId >= startTime) && (runId <= endTime)) {
        AppKey ak = new AppKey(cluster, user, appId);
        return ak;
    }
    return null;
}

From source file:org.commonvox.hbase_column_manager.ColumnInvalidityReport.java

private void outputReport() throws IOException {
    CSVFormat csvFormat = (verboseReport ? VERBOSE_CSV_FORMAT : SUMMARY_CSV_FORMAT);
    try (ResultScanner rows = tempReportTable.getScanner(new Scan().setMaxVersions());
            CSVPrinter csvPrinter = csvFormat.withHeaderComments((verboseReport ? "VERBOSE" : "SUMMARY")
                    + " Report on Invalid Column " + this.reportType + "S in Table <"
                    + sourceTable.getName().getNameAsString()
                    + (sourceColFamily == null ? "" : ">, ColumnFamily <" + Bytes.toString(sourceColFamily))
                    + "> -- Generated by " + Repository.PRODUCT_NAME + ":" + this.getClass().getSimpleName(),
                    new Date()).print(new FileWriter(targetFile))) {
        for (Result row : rows) {
            String[] reportLineComponents = parseRowId(row.getRow());
            NavigableMap<byte[], NavigableMap<Long, byte[]>> tempReportColumnMap = row.getMap().firstEntry()
                    .getValue(); // .get(TEMP_REPORT_CF);
            if (verboseReport) { // print line for each invalid occurrence found
                for (Entry<byte[], NavigableMap<Long, byte[]>> tempReportColumn : tempReportColumnMap
                        .entrySet()) {/*  w  w w  .j ava2 s .  c  o m*/
                    for (Entry<Long, byte[]> tempReportCell : tempReportColumn.getValue().entrySet()) {
                        for (String reportLineComponent : reportLineComponents) {
                            csvPrinter.print(reportLineComponent);
                        }
                        csvPrinter.print(Repository.getPrintableString(tempReportColumn.getKey())); // userRowId
                        csvPrinter.print(tempReportCell.getKey()); // cell timestamp
                        csvPrinter.print(Repository.getPrintableString(tempReportCell.getValue())); // colVal
                        csvPrinter.println();
                    }
                }
            } else { // print summary line giving count of invalid occurrences
                for (String reportLineComponent : reportLineComponents) {
                    csvPrinter.print(reportLineComponent);
                }
                csvPrinter.print(String.valueOf(tempReportColumnMap.size()));
                csvPrinter.println();
            }
        }
    }
}

From source file:edu.oregonstate.eecs.mcplan.domains.voyager.policies.DefensePolicy.java

@Override
public VoyagerAction getAction() {
    final ArrayList<Planet> friendly = Voyager.playerPlanets(s_, self_);
    final NavigableMap<Planet, ArrayList<Spaceship>> incoming = new TreeMap<Planet, ArrayList<Spaceship>>();
    for (final Spaceship ship : s_.spaceships) {
        ArrayList<Spaceship> ships = incoming.get(ship.dest);
        if (ships == null) {
            ships = new ArrayList<Spaceship>();
            incoming.put(ship.dest, ships);
        }//  w w w  .j  a  v  a 2s.c  o  m
        ships.add(ship);
    }
    for (final ArrayList<Spaceship> ships : incoming.values()) {
        Collections.sort(ships, Spaceship.ArrivalTimeComparator);
    }
    final ArrayList<Pair<Integer, Planet>> events = new ArrayList<Pair<Integer, Planet>>();
    for (final Map.Entry<Planet, ArrayList<Spaceship>> ships : incoming.entrySet()) {
        int t = 0;
        int strength_balance = Voyager.defense_strength(ships.getKey().population());
        for (final Spaceship ship : ships.getValue()) {
            if (ship.owner == ships.getKey().owner()) {
                strength_balance += Voyager.defense_strength(ship.population);
            } else {
                // TODO: 2.0 is "safety margin"; should be a parameter
                strength_balance -= 2.0 * Voyager.attack_strength(ship.population);
                if (strength_balance <= 0) {
                    t = ship.arrival_time;
                    break;
                }
            }
        }
        if (t > 0) {
            events.add(Pair.makePair(t, ships.getKey()));
            friendly.remove(ships.getKey());
        }
    }
    Collections.sort(events, new Pair.Comparator<Integer, Planet>());
    for (final Pair<Integer, Planet> e : events) {
        for (final Planet src : friendly) {
            // TODO: Need to account for ship speed
            if (Voyager.distance(src, e.second) < e.first) {
                // TODO: Garrison 1 should be parameter
                final int spare_soldiers = src.population(Unit.Soldier) - 1;
                if (spare_soldiers > 0) {
                    final int[] pop = new int[Unit.values().length];
                    pop[Unit.Soldier.ordinal()] = spare_soldiers;
                    return new LaunchAction(src, e.second, pop);
                }
            }
        }
    }

    return new NothingAction();
}

From source file:hrider.hbase.Scanner.java

/**
 * Loads column names./*from  w  w  w  .  ja  v  a2  s.  c o  m*/
 *
 * @param rowsNumber The number of rows to look for the column names. The column name is a key from key/value pairs in hbase row.
 * @throws IOException Error accessing hbase.
 */
private Collection<ColumnQualifier> loadColumns(int rowsNumber) throws IOException {
    Collection<ColumnQualifier> columns = new ArrayList<ColumnQualifier>();
    columns.add(ColumnQualifier.KEY);

    Map<ColumnQualifier, ColumnQualifier> loadedColumns = new HashMap<ColumnQualifier, ColumnQualifier>();

    int itemsNumber = rowsNumber <= GlobalConfig.instance().getBatchSizeForRead() ? rowsNumber
            : GlobalConfig.instance().getBatchSizeForRead();

    Scan scan = getScanner();
    scan.setCaching(itemsNumber);

    HTable table = this.connection.getTableFactory().get(this.tableName);
    HTableDescriptor tableDescriptor = table.getTableDescriptor();

    ResultScanner scanner = table.getScanner(scan);
    try {
        TypeConverter nameConverter = getColumnNameConverterInternal();

        Result row;
        int counter = 0;

        do {
            row = scanner.next();
            if (row != null) {
                NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> familyMap = row.getMap();
                for (NavigableMap.Entry<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> familyEntry : familyMap
                        .entrySet()) {
                    HColumnDescriptor columnDescriptor = tableDescriptor.getFamily(familyEntry.getKey());

                    for (byte[] quantifier : familyEntry.getValue().keySet()) {
                        ColumnQualifier columnQualifier = new ColumnQualifier(quantifier,
                                new ColumnFamily(columnDescriptor), nameConverter);
                        if (!loadedColumns.containsKey(columnQualifier)) {
                            columns.add(columnQualifier);
                            loadedColumns.put(columnQualifier, null);
                        }
                    }
                }
            }

            counter++;
        } while (row != null && counter < rowsNumber);

        return columns;
    } finally {
        scanner.close();
    }
}

From source file:hrider.hbase.Scanner.java

/**
 * Loads a specified number of rows from the hbase.
 *
 * @param scanner    The hbase scanner to retrieve the data.
 * @param offset     The offset to start from.
 * @param rowsNumber The number of rows to load.
 * @param rows       The loaded rows. This is the output parameter.
 * @param columns    The columns loaded from rows. This is the output parameter.
 * @return A key of the last loaded row. Used to mark the current position for the next scan.
 * @throws IOException Error accessing hbase.
 *///from  w  ww.  j  a  v  a 2 s  .co m
protected ConvertibleObject loadRows(ResultScanner scanner, long offset, int rowsNumber,
        Collection<DataRow> rows, Collection<ColumnQualifier> columns) throws IOException {

    ColumnType keyType = this.columnTypes.get(ColumnQualifier.KEY.getName());
    Map<ColumnQualifier, ColumnQualifier> loadedColumns = new HashMap<ColumnQualifier, ColumnQualifier>();

    int index = 0;
    boolean isValid;
    ConvertibleObject key = null;

    TypeConverter nameConverter = getColumnNameConverterInternal();

    HTable table = this.connection.getTableFactory().get(this.tableName);
    HTableDescriptor tableDescriptor = table.getTableDescriptor();

    do {
        Result result = scanner.next();

        isValid = result != null && rows.size() < rowsNumber;
        if (isValid && isValidRow(result)) {
            if (index >= offset) {
                key = new ConvertibleObject(keyType, result.getRow());

                DataRow row = new DataRow(key);
                row.addCell(new DataCell(row, ColumnQualifier.KEY, key));

                NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> familyMap = result
                        .getMap();
                for (NavigableMap.Entry<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> familyEntry : familyMap
                        .entrySet()) {
                    HColumnDescriptor columnDescriptor = tableDescriptor.getFamily(familyEntry.getKey());

                    for (NavigableMap.Entry<byte[], NavigableMap<Long, byte[]>> qualifierEntry : familyEntry
                            .getValue().entrySet()) {
                        ColumnQualifier qualifier = new ColumnQualifier(qualifierEntry.getKey(),
                                new ColumnFamily(columnDescriptor), nameConverter);

                        String columnName = qualifier.getFullName();
                        ColumnType columnType = this.columnTypes.get(columnName);

                        if (columnType == null) {
                            columnType = ColumnType.String;
                        }

                        for (NavigableMap.Entry<Long, byte[]> cell : qualifierEntry.getValue().entrySet()) {
                            row.addCell(new DataCell(row, qualifier,
                                    new ConvertibleObject(columnType, cell.getValue())));
                        }

                        if (!loadedColumns.containsKey(qualifier)) {
                            columns.add(qualifier);
                            loadedColumns.put(qualifier, null);
                        }
                    }
                }

                rows.add(row);
            }

            index++;
        }
    } while (isValid);

    return key;
}

From source file:sadl.modellearner.rtiplus.SimplePDRTALearner.java

public List<Interval> checkDistribution(PDRTAState s, int alphIdx, DistributionCheckType type,
        StateColoring sc) {//from ww  w . j  av a  2s  . co m

    final NavigableMap<Integer, Interval> ins = s.getIntervals(alphIdx);
    if (ins.size() != 1) {
        return Collections.emptyList();
    }

    final Interval in = ins.firstEntry().getValue();
    if (in.isEmpty()) {
        return Collections.emptyList();
    }

    int tolerance;
    if (type.equals(DistributionCheckType.DISABLED)) {
        return Collections.emptyList();
    } else if (type.equals(DistributionCheckType.STRICT_BORDER) || type.equals(DistributionCheckType.STRICT)) {
        tolerance = 0;
    } else if (type.equals(DistributionCheckType.MAD_BORDER) || type.equals(DistributionCheckType.MAD)) {
        tolerance = getToleranceMAD(in, PDRTA.getMinData());
    } else if (type.equals(DistributionCheckType.OUTLIER_BORDER)
            || type.equals(DistributionCheckType.OUTLIER)) {
        tolerance = getToleranceOutliers(in, PDRTA.getMinData());
    } else {
        throw new IllegalArgumentException("Nonexistent type used!");
    }

    final NavigableMap<Integer, Collection<TimedTail>> tails = in.getTails().asMap();
    final List<Integer> splits = new ArrayList<>();

    if ((type.ordinal() - 1) % 2 != 0) {
        // The types without border
        final Iterator<Entry<Integer, Collection<TimedTail>>> it = tails.entrySet().iterator();
        if (it.hasNext()) {
            Entry<Integer, Collection<TimedTail>> ePrev = it.next();
            int t = ePrev.getKey().intValue();
            if (in.getBegin() <= t - tolerance - 1) {
                splits.add(new Integer(t - tolerance - 1));
            }
            while (it.hasNext()) {
                final Entry<Integer, Collection<TimedTail>> eCurr = it.next();
                t = ePrev.getKey().intValue();
                final int t2 = eCurr.getKey().intValue();
                final int diff = t2 - t - 1;
                if (diff > 2 * tolerance) {
                    splits.add(new Integer(t + tolerance));
                    splits.add(new Integer(t2 - tolerance - 1));
                }
                ePrev = eCurr;
            }
            t = ePrev.getKey().intValue();
            if (in.getEnd() > t + tolerance) {
                splits.add(new Integer(t + tolerance));
            }
        }
    } else {
        int t = tails.firstKey().intValue();
        if (in.getBegin() <= t - tolerance - 1) {
            splits.add(new Integer(t - tolerance - 1));
        }
        t = tails.lastKey().intValue();
        if (in.getEnd() > t + tolerance) {
            splits.add(new Integer(t + tolerance));
        }
    }

    // Interval cIn = new Interval(in);
    // for (int i = 0; i < splits.size(); i++) {
    // cIn.split(splits.get(i));
    // // TODO test resulting intervals for containing more than minData
    // // tails otherwise remove split
    // }

    if (splits.size() == 0) {
        return Collections.emptyList();
    }

    final List<Interval> resultingIns = new ArrayList<>(splits.size() + 1);
    Pair<Interval, Interval> splittedIns = null;
    for (int i = 0; i < splits.size(); i++) {
        splittedIns = OperationUtil.split(s, alphIdx, splits.get(i).intValue(), sc);
        if (!splittedIns.getLeft().isEmpty()) {
            resultingIns.add(splittedIns.getLeft());
        }
    }
    if (splittedIns != null && !splittedIns.getRight().isEmpty()) {
        resultingIns.add(splittedIns.getRight());
    }

    return resultingIns;
}

From source file:org.apache.hadoop.hbase.index.coprocessor.master.IndexMasterObserver.java

private boolean checkRegionInTransition(ObserverContext<MasterCoprocessorEnvironment> ctx, HRegionInfo hri) {
    MasterServices master = ctx.getEnvironment().getMasterServices();
    AssignmentManager am = master.getAssignmentManager();
    boolean isRegionInTransition = false;
    String tableName = hri.getTableNameAsString();
    if (false == IndexUtils.isIndexTable(tableName)) {
        NavigableMap<String, RegionState> regionsInTransition = am.getRegionsInTransition();
        RegionState regionState = regionsInTransition.get(hri.getEncodedName());
        if (regionState != null) {
            isRegionInTransition = true;
        } else {/*from   w  w w .  j  a v a  2 s  . c  o m*/
            String indexTableName = IndexUtils.getIndexTableName(tableName);
            for (Entry<String, RegionState> region : regionsInTransition.entrySet()) {
                HRegionInfo regionInfo = region.getValue().getRegion();
                if (indexTableName.equals(regionInfo.getTableNameAsString())) {
                    if (Bytes.compareTo(hri.getStartKey(), regionInfo.getStartKey()) == 0) {
                        isRegionInTransition = true;
                        break;
                    }
                }
            }
        }
    }
    return isRegionInTransition;
}

From source file:org.apache.gora.hbase.store.HBaseStore.java

private void setField(Result result, T persistent, HBaseColumn col, Field field, Schema fieldSchema)
        throws IOException {
    switch (fieldSchema.getType()) {
    case UNION://from w w w  .j a  v a 2 s.com
        int index = getResolvedUnionIndex(fieldSchema);
        if (index > 1) { //if more than 2 type in union, deserialize directly for now
            byte[] val = result.getValue(col.getFamily(), col.getQualifier());
            if (val == null) {
                return;
            }
            setField(persistent, field, val);
        } else {
            Schema resolvedSchema = fieldSchema.getTypes().get(index);
            setField(result, persistent, col, field, resolvedSchema);
        }
        break;
    case MAP:
        NavigableMap<byte[], byte[]> qualMap = result.getNoVersionMap().get(col.getFamily());
        if (qualMap == null) {
            return;
        }
        Schema valueSchema = fieldSchema.getValueType();
        Map<Utf8, Object> map = new HashMap<>();
        for (Entry<byte[], byte[]> e : qualMap.entrySet()) {
            map.put(new Utf8(Bytes.toString(e.getKey())), fromBytes(valueSchema, e.getValue()));
        }
        setField(persistent, field, map);
        break;
    case ARRAY:
        qualMap = result.getFamilyMap(col.getFamily());
        if (qualMap == null) {
            return;
        }
        valueSchema = fieldSchema.getElementType();
        ArrayList<Object> arrayList = new ArrayList<>();
        DirtyListWrapper<Object> dirtyListWrapper = new DirtyListWrapper<>(arrayList);
        for (Entry<byte[], byte[]> e : qualMap.entrySet()) {
            dirtyListWrapper.add(fromBytes(valueSchema, e.getValue()));
        }
        setField(persistent, field, arrayList);
        break;
    default:
        byte[] val = result.getValue(col.getFamily(), col.getQualifier());
        if (val == null) {
            return;
        }
        setField(persistent, field, val);
        break;
    }
}

From source file:com.alibaba.wasp.meta.FMetaServicesImplWithoutRetry.java

public LinkedHashMap<String, Index> parseIndex(Result rs) {
    LinkedHashMap<String, Index> indexs = new LinkedHashMap<String, Index>();
    NavigableMap<byte[], NavigableMap<byte[], byte[]>> familyMap = rs.getNoVersionMap();

    if (familyMap == null) {
        return indexs;
    }/*from  w w w  . ja v  a2 s . c o  m*/
    NavigableMap<byte[], byte[]> kvs = familyMap.get(FConstants.CATALOG_FAMILY);
    for (Map.Entry<byte[], byte[]> kv : kvs.entrySet()) {
        byte[] cq = kv.getKey();
        byte[] value = kv.getValue();
        if (Bytes.startsWith(cq, FConstants.INDEXQUALIFIER_PREFIX)) {
            Index index = Index.convert(value);
            indexs.put(index.getIndexName(), index);
        }
    }
    return indexs;
}