Example usage for java.util NavigableMap put

List of usage examples for java.util NavigableMap put

Introduction

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

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:io.pravega.controller.server.eventProcessor.LocalController.java

private StreamSegments getStreamSegments(List<SegmentRange> ranges) {
    NavigableMap<Double, Segment> rangeMap = new TreeMap<>();
    for (SegmentRange r : ranges) {
        rangeMap.put(r.getMaxKey(), ModelHelper.encode(r.getSegmentId()));
    }//from  www . j  a v  a2s . c o m
    return new StreamSegments(rangeMap);
}

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.//from w  ww.ja v a 2  s.  c om
 */
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:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceUtil.java

private static NavigableMap<String, String> createPrefixMap(Map<?, ?> properties, String prefix) {
    assert properties != null;
    assert prefix != null;
    NavigableMap<String, String> results = new TreeMap<>();
    for (Map.Entry<?, ?> entry : properties.entrySet()) {
        if ((entry.getKey() instanceof String) == false || (entry.getValue() instanceof String) == false) {
            continue;
        }/*w  ww  .  j a  v  a2  s  .  com*/
        String name = (String) entry.getKey();
        if (name.startsWith(prefix) == false) {
            continue;
        }
        results.put(name.substring(prefix.length()), (String) entry.getValue());
    }
    return results;
}

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   ww w.  j av  a 2  s  . 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:eu.ggnet.dwoss.report.eao.ReportLineEao.java

private NavigableMap<Date, Revenue> prepare(Date start, Date end, Step step) {
    NavigableMap<Date, Revenue> result = new TreeMap<>();
    Date actual = step.truncate(start);
    end = step.prepareEnd(end);//from  w w w.  j  a v  a2  s. c  om
    while (actual.before(end)) {
        result.put(actual, new Revenue());
        actual = step.incement(actual);
    }
    return result;
}

From source file:com.wibidata.shopping.servlet.HomePageServlet.java

private List<ProductRating> getRecentRatings(KijiTable userTable, String login) throws IOException {
    KijiTableReader reader = userTable.openTableReader();
    try {/*from  w w w  .  j  a va2s .c  o m*/
        final long now = System.currentTimeMillis();
        final long lastWeek = now - DateUtils.MILLIS_PER_DAY * 7L;

        EntityId entityId = userTable.getEntityId(login);
        KijiDataRequestBuilder drBuilder = KijiDataRequest.builder();
        drBuilder.newColumnsDef().addFamily("rating");
        drBuilder.withTimeRange(lastWeek, HConstants.LATEST_TIMESTAMP);
        KijiDataRequest dataRequest = drBuilder.build();

        KijiRowData row = reader.get(entityId, dataRequest);
        if (row.containsColumn("rating")) {
            NavigableMap<String, NavigableMap<Long, ProductRating>> ratingsMap = row.getValues("rating");
            NavigableMap<Long, ProductRating> sortedRatings = new TreeMap<Long, ProductRating>();
            for (NavigableMap<Long, ProductRating> value : ratingsMap.values()) {
                for (NavigableMap.Entry<Long, ProductRating> entry : value.entrySet()) {
                    sortedRatings.put(entry.getKey(), entry.getValue());
                }
            }
            return new ArrayList<ProductRating>(sortedRatings.descendingMap().values());
        }
        return null;
    } catch (KijiDataRequestException e) {
        throw new IOException(e);
    } finally {
        IOUtils.closeQuietly(reader);
    }
}

From source file:net.ripe.ipresource.IpResourceSet.java

public void retainAll(IpResourceSet other) {
    if (this.isEmpty()) {
        return;/*from w w w.java 2s. co m*/
    } else if (other.isEmpty()) {
        resourcesByEndPoint.clear();
        return;
    }

    NavigableMap<IpResource, IpResource> temp = new TreeMap<IpResource, IpResource>();
    Iterator<IpResource> thisIterator = this.iterator();
    Iterator<IpResource> thatIterator = other.iterator();
    IpResource thisResource = thisIterator.next();
    IpResource thatResource = thatIterator.next();
    while (thisResource != null && thatResource != null) {
        IpResource intersect = thisResource.intersect(thatResource);
        if (intersect != null) {
            temp.put(intersect.getEnd(), intersect);
        }
        int compareTo = thisResource.getEnd().compareTo(thatResource.getEnd());
        if (compareTo <= 0) {
            thisResource = thisIterator.hasNext() ? thisIterator.next() : null;
        }
        if (compareTo >= 0) {
            thatResource = thatIterator.hasNext() ? thatIterator.next() : null;
        }
    }
    this.resourcesByEndPoint = temp;
}

From source file:com.palantir.atlasdb.keyvalue.partition.map.DynamicPartitionMapImpl.java

public static DynamicPartitionMapImpl fromTable(Map<Cell, byte[]> table) {
    try {//from  www .ja  v  a 2  s. c  om

        int repf = Integer.parseInt(new String(table.get(REPF_CELL)));
        int readf = Integer.parseInt(new String(table.get(READF_CELL)));
        int writef = Integer.parseInt(new String(table.get(WRITEF_CELL)));
        long version = Long.parseLong(new String(table.get(VERSION_CELL)));
        long operationsInProgress = Long.parseLong(new String(table.get(OPS_IN_PROGRESS_CELL)));
        QuorumParameters parameters = new QuorumParameters(repf, readf, writef);
        NavigableMap<byte[], EndpointWithStatus> ring = Maps
                .newTreeMap(UnsignedBytes.lexicographicalComparator());

        for (Entry<Cell, byte[]> entry : table.entrySet()) {
            if (!Arrays.equals(entry.getKey().getRowName(), "map".getBytes())) {
                continue;
            }
            byte[] key = entry.getKey().getColumnName();
            EndpointWithStatus ews = RemotingKeyValueService.kvsMapper().readValue(entry.getValue(),
                    EndpointWithStatus.class);
            ring.put(key, ews);
        }

        return new DynamicPartitionMapImpl(parameters, CycleMap.wrap(ring), version, operationsInProgress,
                PTExecutors.newCachedThreadPool());

    } catch (IOException e) {
        throw Throwables.throwUncheckedException(e);
    }
}

From source file:co.cask.cdap.data2.increment.hbase94.IncrementHandler.java

@Override
public void prePut(ObserverContext<RegionCoprocessorEnvironment> ctx, Put put, WALEdit edit, boolean writeToWAL)
        throws IOException {
    if (put.getAttribute(HBaseOrderedTable.DELTA_WRITE) != null) {
        // incremental write
        NavigableMap<byte[], List<KeyValue>> newFamilyMap = new TreeMap<byte[], List<KeyValue>>(
                Bytes.BYTES_COMPARATOR);
        for (Map.Entry<byte[], List<KeyValue>> entry : put.getFamilyMap().entrySet()) {
            List<KeyValue> newCells = new ArrayList<KeyValue>(entry.getValue().size());
            for (KeyValue kv : entry.getValue()) {
                // rewrite the cell value with a special prefix to identify it as a delta
                // for 0.98 we can update this to use cell tags
                byte[] newValue = Bytes.add(DELTA_MAGIC_PREFIX, kv.getValue());
                newCells.add(new KeyValue(kv.getRow(), kv.getFamily(), kv.getQualifier(), kv.getTimestamp(),
                        newValue));//from ww  w  . j a  v  a  2  s.  c om
            }
            newFamilyMap.put(entry.getKey(), newCells);
        }
        put.setFamilyMap(newFamilyMap);
    }
    // put completes normally with value prefix marker
}

From source file:co.cask.tigon.data.increment.hbase94.IncrementHandler.java

@Override
public void prePut(ObserverContext<RegionCoprocessorEnvironment> ctx, Put put, WALEdit edit, boolean writeToWAL)
        throws IOException {
    if (put.getAttribute(Constants.DELTA_WRITE) != null) {
        // incremental write
        NavigableMap<byte[], List<KeyValue>> newFamilyMap = new TreeMap<byte[], List<KeyValue>>(
                Bytes.BYTES_COMPARATOR);
        for (Map.Entry<byte[], List<KeyValue>> entry : put.getFamilyMap().entrySet()) {
            List<KeyValue> newCells = new ArrayList<KeyValue>(entry.getValue().size());
            for (KeyValue kv : entry.getValue()) {
                // rewrite the cell value with a special prefix to identify it as a delta
                // for 0.98 we can update this to use cell tags
                byte[] newValue = Bytes.add(DELTA_MAGIC_PREFIX, kv.getValue());
                newCells.add(new KeyValue(kv.getRow(), kv.getFamily(), kv.getQualifier(), kv.getTimestamp(),
                        newValue));/* ww w.  ja  v  a 2s  .  com*/
            }
            newFamilyMap.put(entry.getKey(), newCells);
        }
        put.setFamilyMap(newFamilyMap);
    }
    // put completes normally with value prefix marker
}