本文整理匯總了Java中java.util.TreeMap.descendingKeySet方法的典型用法代碼示例。如果您正苦於以下問題:Java TreeMap.descendingKeySet方法的具體用法?Java TreeMap.descendingKeySet怎麽用?Java TreeMap.descendingKeySet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.TreeMap
的用法示例。
在下文中一共展示了TreeMap.descendingKeySet方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testDescendingKeySetOrder
import java.util.TreeMap; //導入方法依賴的package包/類
/**
* descendingKeySet is ordered
*/
public void testDescendingKeySetOrder() {
TreeMap map = map5();
Set s = map.descendingKeySet();
Iterator i = s.iterator();
Integer last = (Integer)i.next();
assertEquals(last, five);
int count = 1;
while (i.hasNext()) {
Integer k = (Integer)i.next();
assertTrue(last.compareTo(k) > 0);
last = k;
++count;
}
assertEquals(5, count);
}
示例2: testDescendingKeySetDescendingIteratorOrder
import java.util.TreeMap; //導入方法依賴的package包/類
/**
* descending iterator of descendingKeySet is ordered
*/
public void testDescendingKeySetDescendingIteratorOrder() {
TreeMap map = map5();
NavigableSet s = map.descendingKeySet();
Iterator i = s.descendingIterator();
Integer last = (Integer)i.next();
assertEquals(last, one);
int count = 1;
while (i.hasNext()) {
Integer k = (Integer)i.next();
assertTrue(last.compareTo(k) < 0);
last = k;
++count;
}
assertEquals(5, count);
}
示例3: testDescendingKeySetToArray
import java.util.TreeMap; //導入方法依賴的package包/類
/**
* descendingkeySet.toArray returns contains all keys
*/
public void testDescendingKeySetToArray() {
TreeMap map = map5();
Set s = map.descendingKeySet();
Object[] ar = s.toArray();
assertEquals(5, ar.length);
assertTrue(s.containsAll(Arrays.asList(ar)));
ar[0] = m10;
assertFalse(s.containsAll(Arrays.asList(ar)));
}
示例4: packEventPointsIntoFingerprints
import java.util.TreeMap; //導入方法依賴的package包/類
private void packEventPointsIntoFingerprints(){
int size = Config.getInt(Key.NFFT_SIZE);
FFT fft = new FFT(size);
float[] binStartingPointsInCents = new float[size];
float[] binHeightsInCents = new float[size];
for (int i = 1; i < size; i++) {
binStartingPointsInCents[i] = (float) PitchConverter.hertzToAbsoluteCent(fft.binToHz(i,sampleRate));
binHeightsInCents[i] = binStartingPointsInCents[i] - binStartingPointsInCents[i-1];
}
float frameDurationInMS = Config.getInt(Key.NFFT_STEP_SIZE)/ ((float) Config.getInt(Key.NFFT_SAMPLE_RATE)) * 1000.f;
int maxEventPointDeltaTInMs = 2000; //two seconds
int maxEventPointDeltaFInCents = 1800; //1.5 octave
int minEventPointDeltaTInMs = 60;//milliseconds
//Collections.shuffle(eventPoints);
TreeMap<Float,NFFTFingerprint> printsOrderedByEnergy = new TreeMap<Float,NFFTFingerprint>();
//int countPrint = 0;
//Pack the event points into fingerprints
for(int i = 0; i < eventPoints.size();i++){
int t1 = eventPoints.get(i).t;
float f1 = binStartingPointsInCents[eventPoints.get(i).f];
//int maxtFirstLevel = t1 + maxEventPointDeltaTInSteps;
float maxfFirstLevel = f1 + maxEventPointDeltaFInCents;
float minfFirstLevel = f1 - maxEventPointDeltaFInCents;
for(int j = 0; j < eventPoints.size() ;j++){
int t2 = eventPoints.get(j).t;
float f2 = binStartingPointsInCents[eventPoints.get(j).f];
if(t1 < t2 && f1 != f2 && Math.abs(t2-t1) * frameDurationInMS > minEventPointDeltaTInMs && Math.abs(t2-t1) * frameDurationInMS < maxEventPointDeltaTInMs && f2 > minfFirstLevel && f2 < maxfFirstLevel){
float energy = eventPoints.get(i).contrast + eventPoints.get(j).contrast;
NFFTFingerprint fingerprint;
fingerprint = new NFFTFingerprint(eventPoints.get(i),eventPoints.get(j));
fingerprint.energy = energy;
printsOrderedByEnergy.put(energy,fingerprint);
//countPrint++;
}
}
}
//System.out.println(countPrint + " prints created, stored : " + printsOrderedByEnergy.size());
//countPrint=0;
int maxPrintsPerPoint = Config.getInt(Key.NFFT_MAX_FINGERPRINTS_PER_EVENT_POINT);
HashMap<NFFTEventPoint,Integer> printsPerPoint = new HashMap<NFFTEventPoint, Integer>();
for(int i = 0; i < eventPoints.size();i++){
printsPerPoint.put(eventPoints.get(i), 0);
}
for(Float key: printsOrderedByEnergy.descendingKeySet()){
NFFTFingerprint print = printsOrderedByEnergy.get(key);
if(printsPerPoint.get(print.p1)<maxPrintsPerPoint && printsPerPoint.get(print.p2)<maxPrintsPerPoint){
printsPerPoint.put(print.p1,printsPerPoint.get(print.p1)+1);
printsPerPoint.put(print.p2,printsPerPoint.get(print.p2)+1);
fingerprints.add(print);
//countPrint++;
}
}
//System.out.println(countPrint + " prints created");
}
示例5: packEventPointsIntoFingerprints
import java.util.TreeMap; //導入方法依賴的package包/類
private void packEventPointsIntoFingerprints(){
int size = Config.getInt(Key.NFFT_SIZE);
FFT fft = new FFT(size);
float[] binStartingPointsInCents = new float[size];
float[] binHeightsInCents = new float[size];
for (int i = 1; i < size; i++) {
binStartingPointsInCents[i] = (float) PitchConverter.hertzToAbsoluteCent(fft.binToHz(i,sampleRate));
binHeightsInCents[i] = binStartingPointsInCents[i] - binStartingPointsInCents[i-1];
}
float frameDurationInMS = Config.getInt(Key.NFFT_STEP_SIZE)/ ((float) Config.getInt(Key.NFFT_SAMPLE_RATE)) * 1000.f;
int maxEventPointDeltaTInMs = 2000; //two seconds
int maxEventPointDeltaFInCents = 1800; //1.5 octave
int minEventPointDeltaTInMs = 60;//milliseconds
//Collections.shuffle(eventPoints);
TreeMap<Float,QIFFTFingerprint> printsOrderedByEnergy = new TreeMap<Float,QIFFTFingerprint>();
//int countPrint = 0;
//Pack the event points into fingerprints
for(int i = 0; i < eventPoints.size();i++){
float t1 = eventPoints.get(i).t;
float f1 = eventPoints.get(i).getFrequencyInCents();
//int maxtFirstLevel = t1 + maxEventPointDeltaTInSteps;
float maxfFirstLevel = f1 + maxEventPointDeltaFInCents;
float minfFirstLevel = f1 - maxEventPointDeltaFInCents;
for(int j = 0; j < eventPoints.size() ;j++){
float t2 = eventPoints.get(j).t;
float f2 = eventPoints.get(j).getFrequencyInCents();
if(t1 < t2 && f1 != f2 && Math.abs(t2-t1) * frameDurationInMS > minEventPointDeltaTInMs && Math.abs(t2-t1) * frameDurationInMS < maxEventPointDeltaTInMs && f2 > minfFirstLevel && f2 < maxfFirstLevel){
float energy = eventPoints.get(i).contrast + eventPoints.get(j).contrast;
QIFFTFingerprint fingerprint;
fingerprint = new QIFFTFingerprint(eventPoints.get(i),eventPoints.get(j));
fingerprint.energy = energy;
printsOrderedByEnergy.put(energy,fingerprint);
}
}
}
//System.out.println(countPrint + " prints created, stored : " + printsOrderedByEnergy.size());
//int countPrint=0;
int maxPrintsPerPoint = Config.getInt(Key.NFFT_MAX_FINGERPRINTS_PER_EVENT_POINT);
HashMap<QIFFTEventPoint,Integer> printsPerPoint = new HashMap<QIFFTEventPoint, Integer>();
for(int i = 0; i < eventPoints.size();i++){
printsPerPoint.put(eventPoints.get(i), 0);
}
for(Float key: printsOrderedByEnergy.descendingKeySet()){
QIFFTFingerprint print = printsOrderedByEnergy.get(key);
if(printsPerPoint.get(print.p1)<maxPrintsPerPoint && printsPerPoint.get(print.p2)<maxPrintsPerPoint){
printsPerPoint.put(print.p1,printsPerPoint.get(print.p1)+1);
printsPerPoint.put(print.p2,printsPerPoint.get(print.p2)+1);
fingerprints.add(print);
//countPrint++;
}
}
}
示例6: main
import java.util.TreeMap; //導入方法依賴的package包/類
public static final void main (String[] input)
throws Exception
{
String fileLocation = "C:\\DRIP\\CreditAnalytics\\Daemons\\Feeds\\TextMiner\\RomeoAndJuliet.txt";
int fileLineCount = NumberOfLinesInFile (fileLocation);
String[] fileContents = ReadFile (fileLocation);
int totalWords = 0;
HashMap<String, Integer> wordToCountMap = new HashMap<String, Integer>();
for (int i = 0; i < fileLineCount; i = i + 1)
{
String currentLine = fileContents[i];
int numberOfWordsInCurrentLine = WordCount (currentLine);
totalWords = totalWords + numberOfWordsInCurrentLine;
String[] wordsInCurrentLine = Words (currentLine);
String wordDump = "";
AddWordToCountMap (currentLine, wordToCountMap);
for (int j = 0; j < numberOfWordsInCurrentLine; j = j + 1)
{
wordDump = wordDump + wordsInCurrentLine[j] + ",";
}
System.out.println (wordDump);
}
System.out.println ("\tNumber of Lines in File: " + fileLineCount);
System.out.println ("\tNumber of Words in File: " + totalWords);
/* Set<String> wordSet = wordToCountMap.keySet();
for (String word : wordSet)
{
System.out.println ("\t\t[" + word + "] => " + wordToCountMap.get (word));
} */
/*
* Begin Added 7 May 2016
*/
TreeMap<Integer, String> wordCounterMap = CountToWordMap (wordToCountMap);
Set<Integer> wordCounterSet = wordCounterMap.descendingKeySet();
for (int wordCount : wordCounterSet)
{
System.out.println ("\t\t[" + wordCount + "] => '" + wordCounterMap.get (wordCount) + "'");
}
TreeMap<Integer, Set<String>> wordCountSetMap = CountToWordArrayMap (wordToCountMap);
Set<Integer> wordSetCountSet = wordCountSetMap.descendingKeySet();
for (int wordSetCount : wordSetCountSet)
{
String counterLineToPrint = "\t\t[" + wordSetCount + "] =>";
Set<String> countedWordSet = wordCountSetMap.get (wordSetCount);
for (String countedWord : countedWordSet)
{
counterLineToPrint = counterLineToPrint + " '" + countedWord + "' |";
}
System.out.println (counterLineToPrint);
}
/*
* End Added 7 May 2016
*/
}