/**
   * Returns submap of x and y values according to the given start and end
   *
   * @param start start x value
   * @param stop stop x value
   * @return a submap of x and y values
   */
  public synchronized SortedMap<Double, Double> getRange(
      double start, double stop, int beforeAfterPoints) {
    // we need to add one point before the start and one point after the end (if
    // there are any)
    // to ensure that line doesn't end before the end of the screen

    // this would be simply: start = mXY.lowerKey(start) but NavigableMap is
    // available since API 9
    SortedMap<Double, Double> headMap = mXY.headMap(start);
    if (!headMap.isEmpty()) {
      start = headMap.lastKey();
    }

    // this would be simply: end = mXY.higherKey(end) but NavigableMap is
    // available since API 9
    // so we have to do this hack in order to support older versions
    SortedMap<Double, Double> tailMap = mXY.tailMap(stop);
    if (!tailMap.isEmpty()) {
      Iterator<Double> tailIterator = tailMap.keySet().iterator();
      Double next = tailIterator.next();
      if (tailIterator.hasNext()) {
        stop = tailIterator.next();
      } else {
        stop += next;
      }
    }
    return new TreeMap<Double, Double>(mXY.subMap(start, stop));
  }
 /** subMap returns map with keys in requested range */
 public void testDescendingSubMapContents() {
   ConcurrentNavigableMap map = dmap5();
   SortedMap sm = map.subMap(m2, m4);
   assertEquals(m2, sm.firstKey());
   assertEquals(m3, sm.lastKey());
   assertEquals(2, sm.size());
   assertFalse(sm.containsKey(m1));
   assertTrue(sm.containsKey(m2));
   assertTrue(sm.containsKey(m3));
   assertFalse(sm.containsKey(m4));
   assertFalse(sm.containsKey(m5));
   Iterator i = sm.keySet().iterator();
   Object k;
   k = (Integer) (i.next());
   assertEquals(m2, k);
   k = (Integer) (i.next());
   assertEquals(m3, k);
   assertFalse(i.hasNext());
   Iterator j = sm.keySet().iterator();
   j.next();
   j.remove();
   assertFalse(map.containsKey(m2));
   assertEquals(4, map.size());
   assertEquals(1, sm.size());
   assertEquals(m3, sm.firstKey());
   assertEquals(m3, sm.lastKey());
   assertEquals("C", sm.remove(m3));
   assertTrue(sm.isEmpty());
   assertEquals(3, map.size());
 }
 /** subMap returns map with keys in requested range */
 public void testSubMapContents() {
   ConcurrentNavigableMap map = map5();
   SortedMap sm = map.subMap(two, four);
   assertEquals(two, sm.firstKey());
   assertEquals(three, sm.lastKey());
   assertEquals(2, sm.size());
   assertFalse(sm.containsKey(one));
   assertTrue(sm.containsKey(two));
   assertTrue(sm.containsKey(three));
   assertFalse(sm.containsKey(four));
   assertFalse(sm.containsKey(five));
   Iterator i = sm.keySet().iterator();
   Object k;
   k = (Integer) (i.next());
   assertEquals(two, k);
   k = (Integer) (i.next());
   assertEquals(three, k);
   assertFalse(i.hasNext());
   Iterator j = sm.keySet().iterator();
   j.next();
   j.remove();
   assertFalse(map.containsKey(two));
   assertEquals(4, map.size());
   assertEquals(1, sm.size());
   assertEquals(three, sm.firstKey());
   assertEquals(three, sm.lastKey());
   assertEquals("C", sm.remove(three));
   assertTrue(sm.isEmpty());
   assertEquals(3, map.size());
 }
Ejemplo n.º 4
0
 /**
  * Add three {@link AbundanceColumn} into {@link AbundanceColumn}, {@link #optionalColumnMapping}
  * and {@link #columnMapping} at one time. The header like: {Section}_abundance_study_variable[1],
  * {Section}_abundance_stdev_study_variable[1], {Section}_abundance_std_error_study_variable[1].
  *
  * @see AbundanceColumn#createOptionalColumns(Section, StudyVariable, String)
  * @param studyVariable SHOULD NOT empty.
  */
 public String addAbundanceOptionalColumn(StudyVariable studyVariable) {
   SortedMap<String, MZTabColumn> columns =
       AbundanceColumn.createOptionalColumns(
           section, studyVariable, getColumnOrder(columnMapping.lastKey()));
   abundanceColumnMapping.putAll(columns);
   optionalColumnMapping.putAll(columns);
   columnMapping.putAll(columns);
   return columns.lastKey();
 }
Ejemplo n.º 5
0
 /**
  * Add {@link AbundanceColumn} into {@link AbundanceColumn}, {@link #optionalColumnMapping} and
  * {@link #columnMapping}. The header like: {Section}_abundance_assay[1]
  *
  * @see AbundanceColumn#createOptionalColumn(Section, Assay, int)
  * @param assay SHOULD NOT empty.
  */
 public String addAbundanceOptionalColumn(Assay assay) {
   MZTabColumn column =
       AbundanceColumn.createOptionalColumn(
           section, assay, new Integer(getColumnOrder(columnMapping.lastKey())));
   abundanceColumnMapping.put(column.getLogicPosition(), column);
   return addOptionColumn(column);
 }
Ejemplo n.º 6
0
 public int getHighestTokenIndex() {
   try {
     return terminalNodes.lastKey();
   } catch (NoSuchElementException e) {
     return 0;
   }
 }
  /** parses a list of MappingCharFilter style rules into a custom byte[] type table */
  private byte[] parseTypes(Collection<String> rules) {
    SortedMap<Character, Byte> typeMap = new TreeMap<Character, Byte>();
    for (String rule : rules) {
      Matcher m = typePattern.matcher(rule);
      if (!m.find()) throw new RuntimeException("Invalid Mapping Rule : [" + rule + "]");
      String lhs = parseString(m.group(1).trim());
      Byte rhs = parseType(m.group(2).trim());
      if (lhs.length() != 1)
        throw new RuntimeException(
            "Invalid Mapping Rule : [" + rule + "]. Only a single character is allowed.");
      if (rhs == null)
        throw new RuntimeException("Invalid Mapping Rule : [" + rule + "]. Illegal type.");
      typeMap.put(lhs.charAt(0), rhs);
    }

    // ensure the table is always at least as big as DEFAULT_WORD_DELIM_TABLE for performance
    byte types[] =
        new byte
            [Math.max(
                typeMap.lastKey() + 1, WordDelimiterIterator.DEFAULT_WORD_DELIM_TABLE.length)];
    for (int i = 0; i < types.length; i++) types[i] = WordDelimiterIterator.getType(i);
    for (Map.Entry<Character, Byte> mapping : typeMap.entrySet())
      types[mapping.getKey()] = mapping.getValue();
    return types;
  }
Ejemplo n.º 8
0
 /**
  * Returns the largest key in the symbol table less than or equal to <tt>key</tt>.
  *
  * @return the largest key in the symbol table less than or equal to <tt>key</tt>
  * @param key the key
  * @throws NoSuchElementException if the symbol table is empty
  * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>
  */
 public Key floor(Key key) {
   if (key == null) throw new NullPointerException("called floor() with null key");
   // headMap does not include key if present (!)
   if (st.containsKey(key)) return key;
   SortedMap<Key, Value> head = st.headMap(key);
   if (head.isEmpty()) throw new NoSuchElementException();
   return head.lastKey();
 }
Ejemplo n.º 9
0
  /** Returns the oldest build in the record. */
  @Exported
  @QuickSilver
  public RunT getFirstBuild() {
    SortedMap<Integer, ? extends RunT> runs = _getRuns();

    if (runs.isEmpty()) return null;
    return runs.get(runs.lastKey());
  }
Ejemplo n.º 10
0
  /** @see it.matrix.aod.postel.at.ATParserImpl#buildIvaDataMap(java.util.TreeMap) */
  @Override
  public SortedMap<Integer, String> buildIvaDataMap(TreeMap<Integer, String> rawMap) {

    SortedMap<Integer, String> footerMap = buildImponibiliIvaDataMap(rawMap);

    String firstLine = footerMap.get(0);
    footerMap.put(0, firstLine.substring(0, 68));

    return footerMap.subMap(0, footerMap.lastKey());
  }
Ejemplo n.º 11
0
 protected String getBestIdForNameInList(String pkgName, List<? extends Package> pkgList) {
   String foundId = null;
   SortedMap<Version, String> foundPkgs = new TreeMap<Version, String>();
   SortedMap<Version, String> matchingPkgs = new TreeMap<Version, String>();
   for (Package pkg : pkgList) {
     if (pkg.getName().equals(pkgName)) {
       foundPkgs.put(pkg.getVersion(), pkg.getId());
       if (Arrays.asList(pkg.getTargetPlatforms()).contains(targetPlatform)) {
         matchingPkgs.put(pkg.getVersion(), pkg.getId());
       }
     }
   }
   if (matchingPkgs.size() != 0) {
     foundId = matchingPkgs.get(matchingPkgs.lastKey());
   } else if (foundPkgs.size() != 0) {
     foundId = foundPkgs.get(foundPkgs.lastKey());
   }
   return foundId;
 }
  /** public for testing purposes */
  public synchronized void removeOldBackups() {

    SortedMap<Long, File> filesMap = getBackupFiles();

    if (filesMap.size() > 0) {

      Calendar rangeStart = TaskActivityUtil.getCalendar();
      rangeStart.setTimeInMillis(filesMap.lastKey());
      TaskActivityUtil.snapStartOfHour(rangeStart);
      int startHour = rangeStart.get(Calendar.HOUR_OF_DAY);
      Calendar rangeEnd = TaskActivityUtil.getCalendar();
      rangeEnd.setTimeInMillis(rangeStart.getTimeInMillis());
      rangeEnd.add(Calendar.HOUR_OF_DAY, 1);
      // Keep one backup for last 8 hours of today
      for (int x = 0; x <= startHour && x < 9; x++) {
        SortedMap<Long, File> subMap =
            filesMap.subMap(rangeStart.getTimeInMillis(), rangeEnd.getTimeInMillis());
        if (subMap.size() > 1) {
          while (subMap.size() > 1) {
            File toDelete = subMap.remove(subMap.firstKey());
            toDelete.delete();
          }
        }
        rangeStart.add(Calendar.HOUR_OF_DAY, -1);
        rangeEnd.add(Calendar.HOUR_OF_DAY, -1);
      }

      // Keep one backup a day for the past 12 days
      TaskActivityUtil.snapStartOfDay(rangeEnd);
      rangeStart.add(Calendar.DAY_OF_YEAR, -1);
      for (int x = 1; x <= 12; x++) {
        SortedMap<Long, File> subMap =
            filesMap.subMap(rangeStart.getTimeInMillis(), rangeEnd.getTimeInMillis());
        if (subMap.size() > 1) {
          while (subMap.size() > 1) {
            File toDelete = subMap.remove(subMap.firstKey());
            toDelete.delete();
          }
        }
        rangeStart.add(Calendar.DAY_OF_YEAR, -1);
        rangeEnd.add(Calendar.DAY_OF_YEAR, -1);
      }

      // Remove all older backups
      SortedMap<Long, File> subMap = filesMap.subMap(0l, rangeStart.getTimeInMillis());
      if (subMap.size() > 0) {
        while (subMap.size() > 0) {
          File toDelete = subMap.remove(subMap.firstKey());
          toDelete.delete();
        }
      }
    }
  }
Ejemplo n.º 13
0
  /** Return the index of the node in the ring that handles this token */
  int getTokenIndex(BigInteger token) {
    // Find keys strictly less than token
    SortedMap<BigInteger, EndPoint> head = tokenToEndPointMap_.headMap(token);

    // If the last key less than token is the last key of the map total, then
    // we are greater than all keys in the map. Therefore the lowest node in the
    // ring is responsible.
    if (!head.isEmpty() && head.lastKey().equals(tokenToEndPointMap_.lastKey())) {
      return 0;
    }
    // otherwise return the number of elems in the map smaller than token
    return head.size();
  }
 /**
  * Find the relevant compression codec for the given file based on its filename suffix.
  *
  * @param file the filename to check
  * @return the codec object
  */
 public CompressionCodec getCodec(Path file) {
   CompressionCodec result = null;
   if (codecs != null) {
     String filename = file.getName();
     String reversedFilename = new StringBuffer(filename).reverse().toString();
     SortedMap<String, CompressionCodec> subMap = codecs.headMap(reversedFilename);
     if (!subMap.isEmpty()) {
       String potentialSuffix = subMap.lastKey();
       if (reversedFilename.startsWith(potentialSuffix)) {
         result = codecs.get(potentialSuffix);
       }
     }
   }
   return result;
 }
Ejemplo n.º 15
0
  /**
   * return the chunk that is a candidate for removal. By default, this checks the ejection policy.
   * If it is a LEAST*, it returns the oldest chunk, if it is a MOST*, it returns to oldest. Other
   * implementations may overload this in order to do more detailed calculations
   *
   * @return
   */
  protected IChunk getRemovalCandidate() {
    if (_sourceChunks.size() == 0) return null;

    switch (getEjectionPolicy()) {
      case LeastRecentlyAdded:
      case LeastRecentlyMatched:
      case LeastRecentlyUsed:
        return _sourceChunks.get(_sourceChunks.firstKey());
      case MostRecentlyAdded:
      case MostRecentlyMatched:
      case MostRecentlyUsed:
        return _sourceChunks.get(_sourceChunks.lastKey());
      default:
        throw new IllegalActivationBufferStateException("EjectionPolicy is invalid");
    }
  }
Ejemplo n.º 16
0
 @Override
 public TextPosition getPreTranslationPosition(TextPosition source) {
   // find the most recent change to the offset and add it to the
   // position
   Offset offset = null;
   if (offsetMap.containsKey(source)) { // offset change starts at the specified position
     offset = offsetMap.get(source);
   } else {
     SortedMap<TextPosition, Offset> headMap = offsetMap.headMap(source);
     if (headMap.isEmpty()) { // no offset change occurs before the position
       offset = new Offset(0, 0);
     } else { // offset change strictly precedes the position
       offset = headMap.get(headMap.lastKey());
     }
   }
   return offset.forwardOffset(source);
 }
Ejemplo n.º 17
0
 public void recordAndUpdateNewMessage(final ChatMessage aMsg) {
   final SortedMap<Date, ChatMessage> map = getMapForRoom(aMsg.getRoom());
   synchronized (map) {
     if (!map.isEmpty()) {
       final ChatMessage lastMsg = map.get(map.lastKey());
       while (aMsg.getDate().compareTo(lastMsg.getDate()) <= 0) {
         aMsg.setDate(new Date(1 + aMsg.getDate().getTime()));
       }
       aMsg.setPreviousMessageDate(lastMsg.getDate());
     }
     map.put(aMsg.getDate(), aMsg);
     while (map.size() > MAX_ROOM_HIST) {
       map.remove(map.firstKey());
     }
   }
   SynchroCache.put("ChatCache", m_chatCache);
 }
Ejemplo n.º 18
0
  protected Token getOrAddTerminalNode(int index) throws MaltChainedException {
    Token node = null;
    if (!terminalNodes.containsKey(index)) {
      if (index > 0) {
        node = terminalPool.checkOut();
        node.setIndex(index);
        node.setBelongsToGraph(this);

        if (index > 1) {
          Token prev = terminalNodes.get(index - 1);
          if (prev == null) {
            try {
              prev = terminalNodes.get(terminalNodes.headMap(index).lastKey());
            } catch (NoSuchElementException e) {

            }
          }
          if (prev != null) {
            prev.setSuccessor(node);
            node.setPredecessor(prev);
          }

          if (terminalNodes.lastKey() > index) {
            Token succ = terminalNodes.get(index + 1);
            if (succ == null) {
              try {
                succ = terminalNodes.get(terminalNodes.tailMap(index).firstKey());
              } catch (NoSuchElementException e) {

              }
            }
            if (succ != null) {
              succ.setPredecessor(node);
              node.setSuccessor(succ);
            }
          }
        }
      }
      terminalNodes.put(index, node);
      numberOfComponents++;
    } else {
      node = terminalNodes.get(index);
    }
    return node;
  }
  /** headMap returns map with keys in requested range */
  public void testDescendingTailMapContents() {
    ConcurrentNavigableMap map = dmap5();
    SortedMap sm = map.tailMap(m2);
    assertFalse(sm.containsKey(m1));
    assertTrue(sm.containsKey(m2));
    assertTrue(sm.containsKey(m3));
    assertTrue(sm.containsKey(m4));
    assertTrue(sm.containsKey(m5));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(m2, k);
    k = (Integer) (i.next());
    assertEquals(m3, k);
    k = (Integer) (i.next());
    assertEquals(m4, k);
    k = (Integer) (i.next());
    assertEquals(m5, k);
    assertFalse(i.hasNext());

    Iterator ei = sm.entrySet().iterator();
    Map.Entry e;
    e = (Map.Entry) (ei.next());
    assertEquals(m2, e.getKey());
    assertEquals("B", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(m3, e.getKey());
    assertEquals("C", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(m4, e.getKey());
    assertEquals("D", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(m5, e.getKey());
    assertEquals("E", e.getValue());
    assertFalse(i.hasNext());

    SortedMap ssm = sm.tailMap(m4);
    assertEquals(m4, ssm.firstKey());
    assertEquals(m5, ssm.lastKey());
    assertEquals("D", ssm.remove(m4));
    assertEquals(1, ssm.size());
    assertEquals(3, sm.size());
    assertEquals(4, map.size());
  }
  /** headMap returns map with keys in requested range */
  public void testTailMapContents() {
    ConcurrentNavigableMap map = map5();
    SortedMap sm = map.tailMap(two);
    assertFalse(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertTrue(sm.containsKey(three));
    assertTrue(sm.containsKey(four));
    assertTrue(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(two, k);
    k = (Integer) (i.next());
    assertEquals(three, k);
    k = (Integer) (i.next());
    assertEquals(four, k);
    k = (Integer) (i.next());
    assertEquals(five, k);
    assertFalse(i.hasNext());

    Iterator ei = sm.entrySet().iterator();
    Map.Entry e;
    e = (Map.Entry) (ei.next());
    assertEquals(two, e.getKey());
    assertEquals("B", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(three, e.getKey());
    assertEquals("C", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(four, e.getKey());
    assertEquals("D", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    assertFalse(i.hasNext());

    SortedMap ssm = sm.tailMap(four);
    assertEquals(four, ssm.firstKey());
    assertEquals(five, ssm.lastKey());
    assertEquals("D", ssm.remove(four));
    assertEquals(1, ssm.size());
    assertEquals(3, sm.size());
    assertEquals(4, map.size());
  }
  @Override
  public void readFromSortedMap(SortedMap<Integer, String> phonePrefixMap) {
    SortedSet<String> descriptionsSet = new TreeSet<String>();
    numOfEntries = phonePrefixMap.size();
    prefixSizeInBytes = getOptimalNumberOfBytesForValue(phonePrefixMap.lastKey());
    phoneNumberPrefixes = ByteBuffer.allocate(numOfEntries * prefixSizeInBytes);

    // Fill the phone number prefixes byte buffer, the set of possible lengths of prefixes and the
    // description set.
    int index = 0;
    for (Entry<Integer, String> entry : phonePrefixMap.entrySet()) {
      int prefix = entry.getKey();
      storeWordInBuffer(phoneNumberPrefixes, prefixSizeInBytes, index, prefix);
      possibleLengths.add((int) Math.log10(prefix) + 1);
      descriptionsSet.add(entry.getValue());
      ++index;
    }
    createDescriptionPool(descriptionsSet, phonePrefixMap);
  }
Ejemplo n.º 22
0
 @Test
 public void testByYearStatsFit() throws Exception {
   final SortedSet<ContinuousDailyHDD> hdds =
       DDNExtractor.extractForAllBaseTemperatures(DDNExtractorTest.getLargeEGLLHDDCSVReader());
   final SortedMap<Integer, Double> meterReadings =
       MeterReadingsExtractor.extractMeterReadings(
           MeterReadingsExtractorTest.getLargeEGLLMeterCSVReader());
   final ChangeFinder cf1 = new ChangeFinder(hdds, meterReadings, Util.DEFAULT_GAS_M3_TO_KWH);
   final SortedMap<Integer, Util.OptimumFit> byYear = cf1.getBestByCalendarYearFit();
   assertNotNull(byYear);
   assertEquals(4, byYear.size());
   assertEquals(2011, byYear.firstKey().intValue());
   assertEquals(2014, byYear.lastKey().intValue());
   for (final Util.OptimumFit of : byYear.values()) {
     assertEquals(2.3f, of.bestFit.slopeEnergyPerHDD, 0.6f);
     assertEquals(0.83f, of.bestFit.rsqFit, 0.1f);
     assertEquals(12.5f, of.hddBaseTempC, 0.1f);
   }
 }
Ejemplo n.º 23
0
 /**
  * Get the value for a load score
  *
  * @param score
  * @return the value for a load score
  */
 public BigDecimal getLoadScoreValue(int score) {
   if (score < minStrenghScoreWithLoad) {
     return BigDecimal.ZERO;
   } else if (score > maxStrengthScoreWithLoad) {
     if (getLoadMultiplierCount() == 1) {
       // TODO Isn't this a bug??
       return getLoadScoreValue(minStrenghScoreWithLoad);
     }
     return loadScoreMultiplier.multiply(getLoadScoreValue(score - loadMultStep));
   } else {
     BigDecimal loadScore = strengthLoadMap.get(score);
     if (loadScore == null) {
       SortedMap<Integer, BigDecimal> headMap = strengthLoadMap.headMap(score);
       /*
        * Assume headMap is populated, since minScore is tested, above -
        * thpr Mar 14, 2007
        */
       return strengthLoadMap.get(headMap.lastKey());
     }
     return loadScore;
   }
 }
Ejemplo n.º 24
0
 @Test
 public void testByYearStatsFitHuge() throws Exception {
   final SortedSet<ContinuousDailyHDD> hdds =
       DDNExtractor.extractForAllBaseTemperatures(DDNExtractorTest.getHugeEGLLHDDCSVReader());
   final SortedMap<Integer, Double> meterReadings =
       MeterReadingsExtractor.extractMeterReadings(
           MeterReadingsExtractorTest.getLargeEGLLMeterCSVReader());
   final ChangeFinder cf1 = new ChangeFinder(hdds, meterReadings, Util.DEFAULT_GAS_M3_TO_KWH);
   final SortedMap<Integer, Util.OptimumFit> byYear = cf1.getBestByCalendarYearFit();
   assertNotNull(byYear);
   assertEquals(6, byYear.size());
   assertEquals(2009, byYear.firstKey().intValue());
   assertEquals(2014, byYear.lastKey().intValue());
   for (final Map.Entry<Integer, Util.OptimumFit> e : byYear.entrySet()) {
     final Util.OptimumFit of = e.getValue();
     System.out.println("sample points in " + e.getKey() + " is " + of.bestFit.n);
     System.out.println("slope in " + e.getKey() + " is " + of.bestFit.slopeEnergyPerHDD);
     System.out.println("base load in " + e.getKey() + " is " + of.bestFit.interceptBaseline);
     System.out.println("optimum base temp in " + e.getKey() + " is " + of.hddBaseTempC);
     assertEquals(3.1f, of.bestFit.slopeEnergyPerHDD, 0.5f);
     assertEquals(0.83f, of.bestFit.rsqFit, 0.1f);
     assertEquals("optimum base temp in " + e.getKey(), 12.5f, of.hddBaseTempC, 2f);
   }
 }
Ejemplo n.º 25
0
 @Override
 public ContainerAutoScaler createContainerAutoScaler() {
   Collection<ContainerProvider> providerCollection = getProviders().values();
   for (ContainerProvider containerProvider : providerCollection) {
     // lets pick the highest weighted autoscaler (e.g. to prefer openshift to docker to child
     SortedMap<Integer, ContainerAutoScaler> sortedAutoScalers =
         new TreeMap<Integer, ContainerAutoScaler>();
     if (containerProvider instanceof ContainerAutoScalerFactory) {
       ContainerAutoScalerFactory provider = (ContainerAutoScalerFactory) containerProvider;
       ContainerAutoScaler autoScaler = provider.createAutoScaler();
       if (autoScaler != null) {
         int weight = autoScaler.getWeight();
         sortedAutoScalers.put(weight, autoScaler);
       }
     }
     if (!sortedAutoScalers.isEmpty()) {
       Integer key = sortedAutoScalers.lastKey();
       if (key != null) {
         return sortedAutoScalers.get(key);
       }
     }
   }
   return null;
 }
Ejemplo n.º 26
0
  private Date maxLastKey(SortedMap<Date, Double> firstSerie, SortedMap<Date, Double> secondSerie)
      throws NotEnoughDataException {

    Date maxDate = null;
    if (secondSerie.isEmpty() && firstSerie.isEmpty()) {
      throw new NotEnoughDataException(
          null, "No prediction data : No prediction period can be infered.", new Exception());
    } else if (secondSerie.isEmpty()) {
      maxDate = firstSerie.lastKey();
    } else if (firstSerie.isEmpty()) {
      maxDate = secondSerie.lastKey();
    } else {
      maxDate =
          (secondSerie.lastKey().after(firstSerie.lastKey()))
              ? secondSerie.lastKey()
              : firstSerie.lastKey();
    }
    return maxDate;
  }
Ejemplo n.º 27
0
 public byte[] lastKey() {
   return map.lastKey();
 }
Ejemplo n.º 28
0
  /** Writes the complete RTF document. */
  private void writeRtfDocument(Appendable out) throws IOException {
    /*
     * <File>     := '{' <header> <document>'}'
     * <header>   := \rtf <charset> \deff? <fonttbl> <colortbl> <stylesheet>?
     * <document> := <info>? <docfmt>* <section>+
     * <section>  := <secfmt>* <hdrftr>? <para>+ ( \sect <section>)?
     */

    // Write <header>

    /*
     * <header>   := \rtf
     *               <charset>
     *               <deffont>
     *               \deff?
     *               <fonttbl>
     *               <filetbl>?
     *               <colortbl>?
     *               <stylesheet>?
     *               <listtables>?
     *               <revtbl>?
     *               <rsidtable>?
     *               <generator>?
     */

    out.append("{"); // '{' <header> <document>'}'

    // The RTF version will always be 1 and the
    // character is \ansi = Windows 1252

    out.append("\\rtf1\\ansi\\deff0");

    /*
     * <fonttbl>  := '{' \fonttbl (<fontinfo> | ('{' <fontinfo> '}'))+ '}'
     */
    out.append("\n{\\fonttbl");

    if (headerFonts.isEmpty()) out.append("{\\f0 Times New Roman;}");
    else {
      for (RtfHeaderFont font : headerFonts) font.writeFontInfo(out);
    }

    out.append('}');

    /*
     * <colortbl> := '{' \colortbl <colordef>+ '}'
     */
    if (!headerColors.isEmpty()) {
      out.append("\n{\\colortbl");

      int maxColorIndex = headerColors.lastKey().intValue();

      for (int i = 0; i <= maxColorIndex; i++) {
        RtfHeaderColor color = headerColors.get(i);
        if (color == null) out.append(';');
        else color.writeColordef(out);
      }

      out.append('}');
    } else out.append("\n{\\colortbl;}");

    /*
     * <stylesheet> := '{' \ stylesheet <style>+ '}'
     */

    if (!headerStyles.isEmpty()) {
      out.append("\n{\\stylesheet");
      for (RtfHeaderStyle style : headerStyles) out.append(style.toString());

      out.append('}');
    }

    out.append('\n');

    // Write <info>

    if (info.length() > 0) {
      out.append("{\\info");
      out.append(info);
      out.append("}\n");
    }

    // Write <docfmt>

    if (docfmt.length() > 0) out.append(docfmt);

    /*
     * <document> := <info>? <docfmt>* <section>+
     * <section>  := <secfmt>* <hdrftr>? <para>+ ( \sect <section>)?
     */

    for (int sectionCnt = 0; sectionCnt < sectionParagraphs.size(); sectionCnt++) {
      RtfPara[] paragraphs = sectionParagraphs.get(sectionCnt);
      CharSequence secfmtHdrftr = secfmtHdrftrs.get(sectionCnt);

      // <secfmt>* <hdrftr>?

      if (secfmtHdrftr != null) out.append(secfmtHdrftr);

      // <para>+

      for (RtfPara rtfPara : paragraphs) rtfPara.rtf(out, true);

      // write \sect between sections but not at the end

      if (sectionCnt != sectionParagraphs.size() - 1) out.append("\\sect\n");
    }

    // TODO:
    //        // Place \par between paragraphs not at the end of every paragraph.
    //        // Consequence: If there is just one paragraph there isn't any \par
    //        if ( i > 0 )
    //        {
    //          // Just add \par if the one before is a paragraph too.
    //          // we don't want \par between table rows
    //          if (    paragraphs[i-1] instanceof RtfTextPara
    //               && paragraphs[ i ] instanceof RtfTextPara )
    //            out.append( "\\par\n" );
    //        }

    // We are done

    out.append("}");
  }
 private double density() {
   // We can use the calculators to work out range size
   double rangeSize =
       determineCalculation().calculatePosition(entries.firstKey(), entries.lastKey()) + 1;
   return entries.size() / rangeSize;
 }
 private LocalDateDoubleTimeSeries createDenseSeries() {
   return DenseLocalDateDoubleTimeSeries.of(
       entries.firstKey(), entries.lastKey(), streamEntries(), determineCalculation());
 }