@Override
 public synchronized YieldCurveDefinitionDocument get(
     ObjectIdentifiable objectIdable, VersionCorrection versionCorrection) {
   ArgumentChecker.notNull(objectIdable, "objectIdable");
   ObjectId objectId = objectIdable.getObjectId();
   if (!getUniqueIdScheme().equals(objectId.getScheme())) {
     throw new DataNotFoundException(
         "Scheme '" + objectId.getScheme() + "' not valid for '" + getUniqueIdScheme() + "'");
   }
   final int i = objectId.getValue().indexOf('_');
   if (i <= 0) {
     throw new DataNotFoundException(
         "Identifier '" + objectId.getValue() + "' not valid for '" + getUniqueIdScheme() + "'");
   }
   final String name = objectId.getValue().substring(0, i);
   final String iso = objectId.getValue().substring(i + 1);
   final Currency currency;
   try {
     currency = Currency.of(iso);
   } catch (IllegalArgumentException e) {
     throw new DataNotFoundException(
         "Identifier '" + objectId.getValue() + "' not valid for '" + getUniqueIdScheme() + "'",
         e);
   }
   final TreeMap<Instant, YieldCurveDefinition> definitions =
       _definitions.get(Pair.of(currency, name));
   if (definitions == null) {
     throw new DataNotFoundException("Curve definition not found");
   }
   final YieldCurveDefinition definition = definitions.lastEntry().getValue();
   if (definition == null) {
     throw new DataNotFoundException("Curve definition not found");
   }
   return new YieldCurveDefinitionDocument(objectId.atLatestVersion(), definition);
 }
 void run() {
   int[] is = in.nextIntArray(6);
   TreeMap<Integer, Integer> cnt = new TreeMap<Integer, Integer>();
   for (int i : is) {
     Num.inc(cnt, i);
   }
   if (cnt.size() == 1) {
     out.println("Elephant");
   } else if (cnt.size() == 2) {
     int a = cnt.firstEntry().getValue();
     int b = cnt.lastEntry().getValue();
     if (a == 2 || b == 2) out.println("Elephant");
     else if (a == 1 || b == 1) out.println("Bear");
     else out.println("Alien");
   } else if (cnt.size() == 3) {
     int[] cs = new int[3];
     int i = 0;
     for (Map.Entry<Integer, Integer> es : cnt.entrySet()) {
       cs[i++] = es.getValue();
     }
     if ((cs[0] == 1 || cs[1] == 1) && (cs[0] == 4 || cs[1] == 4 || cs[2] == 4)) {
       out.println("Bear");
     } else {
       out.println("Alien");
     }
   } else {
     out.println("Alien");
   }
 }
 public Map.Entry<Courier, Long> getCheapestCourierEntry(
     String pincode,
     boolean cod,
     Warehouse srcWarehouse,
     Double amount,
     Double weight,
     boolean ground) {
   TreeMap<Courier, Long> courierCostingMap =
       getCourierCostingMap(pincode, cod, srcWarehouse, amount, weight, ground);
   return courierCostingMap.lastEntry();
 }
  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    int maxLength = Integer.parseInt(br.readLine());
    String line;

    TreeMap<Integer, String> linesSorted = new TreeMap<>();

    while ((line = br.readLine()) != null && !line.isEmpty()) {

      linesSorted.put(line.length(), line);
    }

    while (maxLength-- > 0) {

      Integer i = linesSorted.lastEntry().getKey();

      System.out.println(linesSorted.lastEntry().getValue());
      linesSorted.remove(i);
    }
  }
 // -------------------------------------------------------------------------
 @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();
 }
 @Override
 public synchronized YieldCurveDefinitionDocument get(UniqueId uid) {
   ArgumentChecker.notNull(uid, "objectIdentifiable");
   if (!uid.isLatest()) {
     throw new IllegalArgumentException(
         "Only latest version supported by '" + getUniqueIdScheme() + "'");
   }
   if (!getUniqueIdScheme().equals(uid.getScheme())) {
     throw new DataNotFoundException(
         "Scheme '" + uid.getScheme() + "' not valid for '" + getUniqueIdScheme() + "'");
   }
   final int i = uid.getValue().indexOf('_');
   if (i <= 0) {
     throw new DataNotFoundException(
         "Identifier '" + uid.getValue() + "' not valid for '" + getUniqueIdScheme() + "'");
   }
   final String name = uid.getValue().substring(0, i);
   final String iso = uid.getValue().substring(i + 1);
   final Currency currency;
   try {
     currency = Currency.of(iso);
   } catch (IllegalArgumentException e) {
     throw new DataNotFoundException(
         "Identifier '" + uid.getValue() + "' not valid for '" + getUniqueIdScheme() + "'", e);
   }
   final TreeMap<Instant, YieldCurveDefinition> definitions =
       _definitions.get(Pair.of(currency, name));
   if (definitions == null) {
     throw new DataNotFoundException("Curve definition not found");
   }
   final YieldCurveDefinition definition = definitions.lastEntry().getValue();
   if (definition == null) {
     throw new DataNotFoundException("Curve definition not found");
   }
   return new YieldCurveDefinitionDocument(uid, definition);
 }
 public Map.Entry<K, V> lastEntry() {
   return realMap.lastEntry();
 }
 public BigDecimal getCurrentAmount() {
   return equityCurve.lastEntry().getValue();
 }
Beispiel #9
0
  // Offer a new message. Return false if the offered message can be run immediately.
  public boolean offer(long inTxnId, TransactionInfoBaseMessage in) {
    ReplayEntry found = m_replayEntries.get(inTxnId);

    if (in instanceof Iv2EndOfLogMessage) {
      m_mpiEOLReached = true;
      return true;
    }

    if (in instanceof MultiPartitionParticipantMessage) {
      /*
       * DR sends multiple @LoadMultipartitionTable proc calls with the
       * same txnId, which is the snapshot txnId. For each partition,
       * there is a sentinel paired with the @LoadMultipartitionTable
       * call. Dedupe the sentinels the same way as we dedupe fragments,
       * so that there won't be sentinels end up in the sequencer where
       * matching fragments are deduped.
       */
      if (inTxnId <= m_lastPolledFragmentTxnId) {
        return true;
      }

      if (found == null) {
        ReplayEntry newEntry = new ReplayEntry();
        newEntry.m_sentinalTxnId = inTxnId;
        m_replayEntries.put(inTxnId, newEntry);
      } else {
        found.m_sentinalTxnId = inTxnId;
        assert (found.isReady());
      }
    } else if (in instanceof FragmentTaskMessage) {
      // already sequenced
      if (inTxnId <= m_lastPolledFragmentTxnId) {
        return false;
      }

      FragmentTaskMessage ftm = (FragmentTaskMessage) in;
      if (found == null) {
        ReplayEntry newEntry = new ReplayEntry();
        newEntry.m_firstFragment = ftm;
        m_replayEntries.put(inTxnId, newEntry);
      } else if (found.m_firstFragment == null) {
        found.m_firstFragment = ftm;
        assert (found.isReady());
      } else {
        found.addFragmentMessage(ftm);
      }
    } else if (in instanceof CompleteTransactionMessage) {
      CompleteTransactionMessage ctm = (CompleteTransactionMessage) in;
      // already sequenced
      if (inTxnId <= m_lastPolledFragmentTxnId) {
        if (found != null && found.m_firstFragment != null) {
          found.markLastFragment(ctm);
        }
        return false;
      }
      if (found != null && found.m_firstFragment != null) {
        found.addCompletedMessage(ctm);
      } else {
        // Always expect to see the fragment first, but there are places in the protocol
        // where CompleteTransactionMessages may arrive for transactions that this site hasn't
        // done/won't do, e.g. txn restart, so just tell the caller that we can't do
        // anything with it and hope the right thing happens.
        return false;
      }

    } else {
      if (dedupe(inTxnId, in) != null) {
        // Ignore an already seen txn
        return true;
      }
      updateLastSeenTxnId(inTxnId, in);

      if (m_replayEntries.isEmpty() || !m_replayEntries.lastEntry().getValue().hasSentinel()) {
        // not-blocked work; rejected and not queued.
        return false;
      } else {
        // blocked work queues with the newest replayEntry
        m_replayEntries.lastEntry().getValue().addBlockedMessage(in);
      }
    }
    return true;
  }
 public int lastValue() {
   return map.lastEntry().getValue();
 }
Beispiel #11
0
 /** Return the endpoint that has the highest token less than this ep's token */
 EndPoint getTokenBefore(EndPoint ep) {
   BigInteger token = endPointToTokenMap_.get(ep);
   Map.Entry<BigInteger, EndPoint> entry = tokenToEndPointMap_.lowerEntry(token);
   if (entry != null) return entry.getValue();
   return tokenToEndPointMap_.lastEntry().getValue(); // wrap
 }
  /**
   * Decodes a byte array generated with the arithmetic encoding compression algorithm into clear
   * text.
   *
   * @param codedMessage the message to decode
   * @return the clear, decoded message
   */
  @Override
  public String decode(byte[] codedMessage) {
    String message = "";

    ByteArrayInputStream inputBytes = new ByteArrayInputStream(codedMessage);
    DataInputStream input = new DataInputStream(inputBytes);

    int zeroes = 0;

    BigInteger code;
    BigInteger power;
    CharMap key = new CharMap();
    TreeMap<Integer, Character> reverseKey = new TreeMap<Integer, Character>();

    // Read in the key and the coded message from the byte array.
    try {
      int keyLength = input.readInt();
      zeroes = input.readInt();
      for (int i = 0; i < keyLength; ++i) {
        key.put(input.readChar(), input.readInt());
      }

      byte[] valueStorage = new byte[inputBytes.available()];
      input.readFully(valueStorage);
      code = new BigInteger(valueStorage);
    } catch (java.io.IOException e) {
      System.err.println("There was an IOException");
      return null;
    }

    // Use the zeroes count to recreate the full encoded value.
    code = code.shiftLeft(zeroes);

    // Create a reverse key for decoding purposes.
    for (Character c : key.keySet()) {
      reverseKey.put(key.getPosition(c), c);
    }

    // Get the total length of the original message as the number of
    // characters.
    int messageLength = 0;
    for (Integer j : key.values()) {
      messageLength += j;
    }

    // Implement Wikipedia's decoding algorithm. I wish I knew exactly why
    // it worked, but I don't. But it works.
    power = BigInteger.valueOf(messageLength).pow(messageLength - 1);

    for (;
        power.compareTo(BigInteger.ZERO) > 0;
        power = power.divide(BigInteger.valueOf(messageLength))) {
      char c = ' ';
      int codedChar = (code.divide(power)).intValue();

      char lastChar = reverseKey.lastEntry().getValue();
      c = lastChar;
      for (Map.Entry<Integer, Character> e : reverseKey.entrySet()) {
        if (codedChar < e.getKey()) {
          c = lastChar;
          break;
        } else if (codedChar == e.getKey()) {
          c = e.getValue();
          break;
        }
        lastChar = e.getValue();
      }

      code =
          (code.subtract(power.multiply(BigInteger.valueOf(key.getPosition(c)))))
              .divide(BigInteger.valueOf(key.getProbability(c)));

      message += c;
    }

    // Return the decoded message.
    return message;
  }