Example usage for java.util NavigableMap get

List of usage examples for java.util NavigableMap get

Introduction

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

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:com.twitter.hraven.util.ByteUtil.java

/**
 * return a value from the NavigableMap as a Double
 * @param key to be looked up for the value
 * @param infoValues - the map containing the key values
 * @return value as Double or 0.0/*from w w w .j a  v  a2s  .  co m*/
 */
public static double getValueAsDouble(byte[] key, NavigableMap<byte[], byte[]> infoValues) {
    byte[] value = infoValues.get(key);
    if (value != null) {
        return Bytes.toDouble(value);
    } else {
        return 0.0;
    }
}

From source file:com.antsdb.saltedfish.storage.Helper.java

public static long getVersion(Result r) {
    NavigableMap<byte[], byte[]> sys = r.getFamilyMap(SYS_COLUMN_FAMILY_BYTES);
    byte[] versionBytes = sys.get(SYS_COLUMN_VERSION_BYTES);
    long version = Bytes.toLong(versionBytes);
    return version;
}

From source file:com.antsdb.saltedfish.storage.Helper.java

public static long toRow(Heap heap, Result r, TableMeta table) {
    if (r.isEmpty()) {
        return 0;
    }//from  ww  w.  j  a v a2s. c om

    // some preparation

    NavigableMap<byte[], byte[]> sysFamilyMap = r.getFamilyMap(SYS_COLUMN_FAMILY_BYTES);
    NavigableMap<byte[], byte[]> dataFamilyMap = r.getFamilyMap(DATA_COLUMN_FAMILY_BYTES);
    byte[] colDataType = sysFamilyMap.get(SYS_COLUMN_DATATYPE_BYTES);
    byte[] versionBytes = sysFamilyMap.get(SYS_COLUMN_VERSION_BYTES);
    byte[] sizeBytes = sysFamilyMap.get(SYS_COLUMN_SIZE_BYTES);
    long version = Bytes.toLong(versionBytes);
    int size = Bytes.toInt(sizeBytes);

    // populate the row. system table doesn't come with metadata

    MutableRow row = null;
    if (table != null) {
        row = populateUsingMetadata(heap, table, dataFamilyMap, colDataType, size);
    } else {
        row = populateDirect(heap, dataFamilyMap, colDataType, size);
    }
    byte[] key = hbaseKeyToAnts(r.getRow());
    row.setKey(key);
    row.setVersion(version);
    return row.getAddress();
}

From source file:com.moz.fiji.schema.tools.ToolUtils.java

/**
 * Prints cell data from the <code>row</code> for each column specified on the
 * <code>request</code>.//w  w w  .  ja v  a 2s.c o  m
 *
 * @param row The row to read from.
 * @param mapTypeFamilies The map type families to print.
 * @param groupTypeColumns The group type columns to print.
 * @param printStream The stream to print to.
 * @throws IOException if there is an error retrieving data from the FijiRowData.
 */
public static void printRow(FijiRowData row, Map<FamilyLayout, List<String>> mapTypeFamilies,
        Map<FamilyLayout, List<ColumnLayout>> groupTypeColumns, PrintStream printStream) throws IOException {

    // Unpack and print result for the map type families.
    for (Entry<FamilyLayout, List<String>> entry : mapTypeFamilies.entrySet()) {
        final FamilyLayout family = entry.getKey();
        if (family.getDesc().getMapSchema().getType() == SchemaType.COUNTER) {

            // If this map family of counters has no qualifiers, print entire family.
            if (entry.getValue().isEmpty()) {
                for (String key : row.getQualifiers(family.getName())) {
                    FijiCell<Long> counter = row.getMostRecentCell(family.getName(), key);
                    if (null != counter) {
                        printCell(row.getEntityId(), counter, printStream);
                    }
                }
                // If this map family of counters has been qualified, print only the given columns.
            } else {
                for (String key : entry.getValue()) {
                    FijiCell<Long> counter = row.getMostRecentCell(family.getName(), key);
                    if (null != counter) {
                        printCell(row.getEntityId(), counter, printStream);
                    }
                }
            }
        } else {
            // If this map family of non-counters has no qualifiers, print entire family.
            if (entry.getValue().isEmpty()) {
                NavigableMap<String, NavigableMap<Long, Object>> keyTimeseriesMap = row
                        .getValues(family.getName());
                for (String key : keyTimeseriesMap.keySet()) {
                    for (Entry<Long, Object> timestampedCell : keyTimeseriesMap.get(key).entrySet()) {
                        long timestamp = timestampedCell.getKey();
                        printCell(row.getEntityId(), timestamp, family.getName(), key,
                                timestampedCell.getValue(), printStream);
                    }
                }
                // If this map family of non-counters has been qualified, print only the given columns.
            } else {
                for (String key : entry.getValue()) {
                    NavigableMap<Long, Object> timeseriesMap = row.getValues(family.getName(), key);
                    for (Entry<Long, Object> timestampedCell : timeseriesMap.entrySet()) {
                        long timestamp = timestampedCell.getKey();
                        printCell(row.getEntityId(), timestamp, family.getName(), key,
                                timestampedCell.getValue(), printStream);
                    }
                }
            }
        }
    }

    // Unpack and print result for the group type families.
    for (Entry<FamilyLayout, List<ColumnLayout>> entry : groupTypeColumns.entrySet()) {
        String familyName = entry.getKey().getName();
        for (ColumnLayout column : entry.getValue()) {
            final FijiColumnName colName = FijiColumnName.create(familyName, column.getName());
            if (column.getDesc().getColumnSchema().getType() == SchemaType.COUNTER) {
                final FijiCell<Long> counter = row.getMostRecentCell(colName.getFamily(),
                        colName.getQualifier());
                if (null != counter) {
                    printCell(row.getEntityId(), counter, printStream);
                }
            } else {
                for (Entry<Long, Object> timestampedCell : row
                        .getValues(colName.getFamily(), colName.getQualifier()).entrySet()) {
                    long timestamp = timestampedCell.getKey();
                    printCell(row.getEntityId(), timestamp, colName.getFamily(), colName.getQualifier(),
                            timestampedCell.getValue(), printStream);
                }
            }
        }
    }
    printStream.println("");
}

From source file:com.ery.hadoop.mrddx.hbase.HbaseInputFormat.java

/**
 * ?TableRegionInfo?/*from   w w  w  .  j a va 2  s. c om*/
 * 
 * @param job job
 * @param tableName ??
 * @throws IOException IO
 */
private static void printTableAllRegionInfo(Configuration job, String tableName) throws IOException {
    HTable table = new HTable(job, tableName);
    StringBuilder regionLog = new StringBuilder();
    regionLog.append("<<Table[");
    regionLog.append(new String(table.getTableName()));
    regionLog.append("]all RegionInfo>>");
    NavigableMap<HRegionInfo, ServerName> mapHRegionInfo = table.getRegionLocations();
    Iterator<HRegionInfo> hregionIterator = mapHRegionInfo.keySet().iterator();
    while (hregionIterator.hasNext()) {
        regionLog.append("\nHRegionInfo:");
        HRegionInfo key = hregionIterator.next();
        ServerName value = mapHRegionInfo.get(key);
        regionLog.append(key.toString());
        regionLog.append("ServerInfo:");
        regionLog.append("{name=>:");
        regionLog.append(value.getServerName());
        regionLog.append(" ,HostAndPort=>:");
        regionLog.append(value.getHostAndPort());
        regionLog.append("}");
    }
    MRLog.info(LOG, regionLog.toString());
}

From source file:org.kiji.rest.representations.KijiRestRow.java

/**
 * Adds a new cell (specified by the family, qualifier, timestamp and value) to the current row.
 *
 * @param family is the family of the cell to add.
 * @param qualifier is the qualifier of the cell to add.
 * @param timestamp is the timestamp of the cell to add.
 * @param value is the value of the cell to add.
 * @param writerSchema is the writer schema (contained as an option: either as a string or uid)
 *        of the cell's value./*  w  w w  .j a  v a  2 s  . c o m*/
 */
public void addCell(String family, String qualifier, Long timestamp, Object value, SchemaOption writerSchema) {
    NavigableMap<String, List<KijiRestCell>> familyMap = mKijiCellMap.get(family);
    if (familyMap == null) {
        familyMap = Maps.newTreeMap();
        mKijiCellMap.put(family, familyMap);
    }
    List<KijiRestCell> restCells = familyMap.get(qualifier);
    if (restCells == null) {
        restCells = Lists.newArrayList();
        familyMap.put(qualifier, restCells);
    }
    restCells.add(new KijiRestCell(timestamp, value, writerSchema));
}

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);
        }/*from   w  ww  . ja v a  2  s .c om*/
        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:com.alibaba.wasp.master.handler.TableEventHandler.java

public boolean reOpenAllEntityGroups(List<EntityGroupInfo> entityGroups) throws IOException {
    boolean done = false;
    LOG.info("Bucketing entityGroups by entityGroup server...");
    TreeMap<ServerName, List<EntityGroupInfo>> serverToEntityGroups = Maps.newTreeMap();
    NavigableMap<EntityGroupInfo, ServerName> egiHserverMapping = FMetaScanner
            .allTableEntityGroups(server.getConfiguration(), tableName, false);

    List<EntityGroupInfo> reEntityGroups = new ArrayList<EntityGroupInfo>();
    for (EntityGroupInfo egi : entityGroups) {
        ServerName egLocation = egiHserverMapping.get(egi);

        // Skip the offlined split parent EntityGroup
        if (null == egLocation) {
            LOG.info("Skip " + egi);
            continue;
        }/*from   w  w w .j  a  v a 2  s  .  c  om*/
        if (!serverToEntityGroups.containsKey(egLocation)) {
            LinkedList<EntityGroupInfo> egiList = Lists.newLinkedList();
            serverToEntityGroups.put(egLocation, egiList);
        }
        reEntityGroups.add(egi);
        serverToEntityGroups.get(egLocation).add(egi);
    }

    LOG.info("Reopening " + reEntityGroups.size() + " entityGroups on " + serverToEntityGroups.size()
            + " fservers.");
    this.fMasterServices.getAssignmentManager().setEntityGroupsToReopen(reEntityGroups);
    BulkReOpen bulkReopen = new BulkReOpen(this.server, serverToEntityGroups,
            this.fMasterServices.getAssignmentManager());
    while (true) {
        try {
            if (bulkReopen.bulkReOpen()) {
                done = true;
                break;
            } else {
                LOG.warn("Timeout before reopening all entityGroups");
            }
        } catch (InterruptedException e) {
            LOG.warn("Reopen was interrupted");
            // Preserve the interrupt.
            Thread.currentThread().interrupt();
            break;
        }
    }
    return done;
}

From source file:eu.ggnet.dwoss.report.eao.ReportLineEao.java

/**
 * Returns the revenue in a range with the supplied Stepsize.
 * A step size of day will return daily revenues, while a stepsize of month returns monthly revenues.
 * For each stepsize the earliest possible day is used as identifier. e.g.: January 2012 it would be 2012-01-01.
 * <p>/*ww  w.  java 2s  .c o  m*/
 * @param posTypes      the positiontypes to include
 * @param start         the start
 * @param end           the end
 * @param step          the stepsize.
 * @param extraReported
 * @return the Revenue by Date in the stepsize.
 */
public NavigableMap<Date, Revenue> revenueByPositionTypesAndDate(List<PositionType> posTypes, Date start,
        Date end, Step step, boolean extraReported) {
    L.debug("Attempt to find revenue report data with posType={}, start={}, end={}, {}", posTypes, start, end,
            step);
    TypedQuery<RevenueHolder> q = em.createNamedQuery("ReportLine.revenueByPositionTypesAndDate",
            RevenueHolder.class);
    q.setParameter("positions", posTypes).setParameter("start", start).setParameter("end", end);

    NavigableMap<Date, Revenue> result = prepare(start, end, step);
    for (RevenueHolder holder : q.getResultList()) {
        Revenue revenueStep = result.get(step.truncate(holder.getReportingDate()));
        // Highly unlikely case, but if it happens a detail message might help.
        if (revenueStep == null)
            throw new RuntimeException("No prepared RevenueStep found for " + step.name() + ":reportingDate="
                    + DateFormats.ISO.format(holder.getReportingDate()) + ",truncated="
                    + DateFormats.ISO.format(step.truncate(holder.getReportingDate())) + ",keys="
                    + nice(result.keySet(), step));
        revenueStep.addTo(holder.getSalesChannel(), holder.getDocumentType(), holder.getContractor(),
                holder.getPrice(), 0., 0.);
    }
    if (!extraReported)
        return result;
    q = em.createNamedQuery("ReportLine.revenueByPositionTypesAndDateReported", RevenueHolder.class);
    q.setParameter("positions", posTypes).setParameter("start", start).setParameter("end", end);
    List<RevenueHolder> resultList = q.getResultList();
    System.out.println("Second run size:" + resultList.size());
    for (RevenueHolder holder : resultList) {
        System.out.println("Second run: " + holder);
        Revenue revenueStep = result.get(step.truncate(holder.getReportingDate()));
        // Highly unlikely case, but if it happens a detail message might help.
        if (revenueStep == null)
            throw new RuntimeException("No prepared RevenueStep found for " + step.name() + ":reportingDate="
                    + DateFormats.ISO.format(holder.getReportingDate()) + ",truncated="
                    + DateFormats.ISO.format(step.truncate(holder.getReportingDate())) + ",keys="
                    + nice(result.keySet(), step));
        revenueStep.addTo(holder.getSalesChannel(), holder.getDocumentType(), holder.getContractor(), 0.,
                holder.getPrice(), holder.getPurchasePrice());
    }
    return result;
}

From source file:com.twitter.hraven.JobDetails.java

/**
 * return an enum value from the NavigableMap for hadoop version
 * @param key//from   w  w w.  j ava  2s.c  o  m
 * @param infoValues
 * @return value as a enum or default of hadoop ONE
 */
private HadoopVersion getHadoopVersionFromResult(final JobHistoryKeys key,
        final NavigableMap<byte[], byte[]> infoValues) {
    byte[] value = infoValues.get(JobHistoryKeys.KEYS_TO_BYTES.get(key));
    if (value != null) {
        String hv = Bytes.toString(value);
        // could throw an NPE or IllegalArgumentException
        return HadoopVersion.valueOf(hv);
    } else {
        // default is hadoop 1
        return HadoopVersion.ONE;
    }
}