示例#1
0
 /**
  * Get the batch containing the given row. NOTE: the returned batch may be empty or may begin with
  * a row other than the one specified.
  *
  * @param row
  * @return
  * @throws TeiidComponentException
  *     <p>TODO: a method to get the raw batch
  */
 public TupleBatch getBatch(int row) throws TeiidComponentException {
   TupleBatch result = null;
   if (row > rowCount) {
     result = new TupleBatch(rowCount + 1, new List[] {});
   } else if (this.batchBuffer != null && row > rowCount - this.batchBuffer.size()) {
     result = new TupleBatch(rowCount - this.batchBuffer.size() + 1, batchBuffer);
     if (forwardOnly) {
       this.batchBuffer = null;
     }
   } else {
     if (this.batchBuffer != null && !this.batchBuffer.isEmpty()) {
       // this is just a sanity check to ensure we're not holding too many
       // hard references to batches.
       saveBatch(false);
     }
     Map.Entry<Integer, Long> entry = batches.floorEntry(row);
     Assertion.isNotNull(entry);
     Long batch = entry.getValue();
     List<List<?>> rows = manager.getBatch(batch, !forwardOnly);
     result = new TupleBatch(entry.getKey(), rows);
     if (isFinal && result.getEndRow() == rowCount) {
       result.setTerminationFlag(true);
     }
     if (forwardOnly) {
       batches.remove(entry.getKey());
     }
   }
   if (isFinal && result.getEndRow() == rowCount) {
     result.setTerminationFlag(true);
   }
   return result;
 }
示例#2
0
  /**
   * Returns the current price<br>
   * If there's no price available: return UNKNOWN_PRICE (100 cents)
   *
   * @param t timeStamp (UnixTime)
   */
  public double getPrice(long t) {
    if (t < priceUnknownBefore || t > priceUnknownAtAndAfter) {
      System.out.println("ERROR: Price unknown, using default price");
      System.out.println(
          "reuqested time outside of known intervall: "
              + t
              + " not in ["
              + priceUnknownBefore
              + " - "
              + priceUnknownAtAndAfter
              + "]");
      return UNKNOWN_PRICE;
    }

    // Return most recent price
    Entry<Long, Double> entry = prices.floorEntry(t);

    if (entry != null) {
      return entry.getValue();
    } else {
      System.out.println("ERROR: Price unknown, using default price");
      System.out.println("Price in known intervall, but floorEntry null, time: " + t);
      return UNKNOWN_PRICE;
    }
  }
示例#3
0
  /**
   * Search previous and following index entries around the requested position from the index.
   * Create a new index entry between these entries, if the distance between them is too big for
   * line-by-line reading. Effectively makes a binary search on the file to find a location that is
   * reasonably close to request position and precedes it.
   *
   * @param position
   * @return
   * @throws IOException
   * @throws GBrowserException
   */
  private long binarySearch(BpCoord position) throws IOException, GBrowserException {

    Entry<BpCoord, Long> floorEntry = index.floorEntry(position);
    Entry<BpCoord, Long> ceilingEntry = index.ceilingEntry(position);

    if (floorEntry == null) {
      // Request start is less than smallest index entry
      floorEntry = ceilingEntry;
    }

    if (ceilingEntry == null) {
      // Request start is greater than largest index entry
      ceilingEntry = floorEntry;
    }

    long floorFilePosition = floorEntry.getValue();
    long ceilingFilePosition = ceilingEntry.getValue();

    if (ceilingFilePosition - floorFilePosition > INDEX_INTERVAL) {

      splitIndexRegion(floorFilePosition, ceilingFilePosition);

      return binarySearch(position);
    }

    return floorEntry.getValue();
  }
示例#4
0
 /**
  * This picks a random block with the following constraints: A cactus is never chosen as the
  * bottom block. Water or lava never is placed above sugar cane or cactuses because when they
  * grow, they will touch the liquid and cause it to flow.
  *
  * @param random - random object
  * @param bottom - if true, result will never be CACTUS
  * @param noLiquid - if true, result will never be water or lava
  * @return Material selected
  */
 public Material getBlock(Random random, boolean bottom, boolean noLiquid) {
   Material temp = probMap.floorEntry(random.nextInt(total)).getValue();
   if (bottom && temp.equals(Material.CACTUS)) {
     return getBlock(random, bottom, noLiquid);
   } else if (noLiquid
       && (temp.equals(Material.STATIONARY_WATER) || temp.equals(Material.STATIONARY_LAVA))) {
     return getBlock(random, bottom, noLiquid);
   }
   return temp;
 }
  @Override
  public synchronized void remove(byte[] key) {
    TreeMap<byte[], String> m = currentMap.get();
    TreeMap<byte[], String> newMap = new TreeMap<>(m);

    Map.Entry<byte[], String> e = newMap.floorEntry(key);
    if (e != null) {
      newMap.remove(e.getKey());
    }
    currentMap.set(newMap);
  }
  public static <T> T getLatestKnownValue(
      Integer packetNumber, Unit unit, Map<Unit, TreeMap<Integer, T>> histogramMap) {
    TreeMap<Integer, T> packetNumberTMap = histogramMap.get(unit);

    if (packetNumberTMap == null) return null;

    if (packetNumberTMap.isEmpty()) return null;

    Map.Entry<Integer, T> entry = packetNumberTMap.floorEntry(packetNumber);

    if (entry != null) return entry.getValue();
    else return null;
  }
示例#7
0
  /* (non-Javadoc)
   * @see org.ejs.gui.images.IPaletteMapper#getRgbToGreyForGreyscaleMode(byte[])
   */
  @Override
  public byte[] getRgbToGreyForGreyscaleMode(byte[] rgb) {
    int lum = ColorMapUtils.getRGBLum(rgb);

    TreeMap<Integer, byte[]> map = getGreyToRgbMap();
    Entry<Integer, byte[]> entry = map.ceilingEntry(lum);
    if (entry == null) {
      entry = map.floorEntry(lum);
      if (entry == null) {
        throw new AssertionError();
      }
    }

    return entry.getValue();
  }
 @Override
 public YieldCurveDefinition getDefinition(
     final Currency currency, final String name, final VersionCorrection versionCorrection) {
   ArgumentChecker.notNull(currency, "currency");
   ArgumentChecker.notNull(name, "name");
   final TreeMap<Instant, YieldCurveDefinition> definitions =
       _definitions.get(Pair.of(currency, name));
   if (definitions == null) {
     return null;
   }
   final Map.Entry<Instant, YieldCurveDefinition> entry =
       definitions.floorEntry(versionCorrection.getVersionAsOf());
   if (entry == null) {
     return null;
   }
   return entry.getValue();
 }
 // -------------------------------------------------------------------------
 @Override
 public synchronized YieldCurveDefinition getDefinition(Currency currency, String name) {
   ArgumentChecker.notNull(currency, "currency");
   ArgumentChecker.notNull(name, "name");
   final TreeMap<Instant, YieldCurveDefinition> definitions =
       _definitions.get(Pair.of(currency, name));
   if (definitions == null) {
     return null;
   }
   final Map.Entry<Instant, YieldCurveDefinition> entry;
   if (_sourceVersionCorrection.getVersionAsOf() == null) {
     entry = definitions.lastEntry();
   } else {
     entry = definitions.floorEntry(_sourceVersionCorrection.getVersionAsOf());
   }
   if (entry == null) {
     return null;
   }
   return entry.getValue();
 }
  public double getValue(double x) {
    Map.Entry<Double, Double> e1, e2;
    double x1, x2;
    double y1, y2;

    if (Double.isNaN(x)) return Double.NaN;

    e1 = sortMap.floorEntry(x);

    if (e1 == null) {
      // x smaller than any value in the set
      e1 = sortMap.firstEntry();
      if (e1 == null) {
        return Double.NaN;
      }
      e2 = sortMap.higherEntry(e1.getKey());
      if (e2 == null) {
        // only one value in the set
        return e1.getValue();
      }
    } else {

      e2 = sortMap.higherEntry(e1.getKey());
      if (e2 == null) {
        // x larger than any value in the set
        e2 = e1;
        e1 = sortMap.lowerEntry(e2.getKey());
        if (e1 == null) {
          // only one value in the set
          return e2.getValue();
        }
      }
    }

    x1 = e1.getKey();
    x2 = e2.getKey();
    y1 = e1.getValue();
    y2 = e2.getValue();

    return (x - x1) / (x2 - x1) * (y2 - y1) + y1;
  }
示例#11
0
  /**
   * Calculates estimated number of points in interval [-∞,b].
   *
   * @param b upper bound of a interval to calculate sum
   * @return estimated number of points in a interval [-∞,b].
   */
  public double sum(double b) {
    double sum = 0;
    // find the points pi, pnext which satisfy pi <= b < pnext
    Map.Entry<Double, Long> pnext = bin.higherEntry(b);
    if (pnext == null) {
      // if b is greater than any key in this histogram,
      // just count all appearance and return
      for (Long value : bin.values()) sum += value;
    } else {
      Map.Entry<Double, Long> pi = bin.floorEntry(b);
      if (pi == null) return 0;
      // calculate estimated count mb for point b
      double weight = (b - pi.getKey()) / (pnext.getKey() - pi.getKey());
      double mb = pi.getValue() + (pnext.getValue() - pi.getValue()) * weight;
      sum += (pi.getValue() + mb) * weight / 2;

      sum += pi.getValue() / 2.0;
      for (Long value : bin.headMap(pi.getKey(), false).values()) sum += value;
    }
    return sum;
  }
示例#12
0
 public Map.Entry<K, V> floorEntry(K key) {
   return realMap.floorEntry(key);
 }
示例#13
0
 public Entry<Long, Double> getFloorEntry(long t) {
   return prices.floorEntry(t);
 }
 public int floorValue(int key) {
   return map.floorEntry(key).getValue();
 }