本文整理汇总了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
*/
}