Java Code Examples for java.util.TreeSet#lower()
The following examples show how to use
java.util.TreeSet#lower() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LastSeenLoggingScorerContinuous.java From ade with GNU General Public License v3.0 | 6 votes |
/** * Processes the previous time line of the current message ID. * @param messageID String value that contains the message ID * @param contextElement AnalyzedInterval object that contains summary results of interval. * @param sc Contains statistics for message ID. * @param timeLineSet time line of current message ID. * @throws AdeInternalException */ public void processPrevTimeLine(String messageID, IAnalyzedInterval contextElement, StatisticsChart sc, Set<Long> timeLineSet) throws AdeInternalException{ final TreeSet<Long> prevTimeLine = m_prevIntervalTimelineMap.get(messageID); if (prevTimeLine == null) { m_mainStat = MainStatVal.NEW; m_deltasInSeconds.add((m_firstMsgTime-contextElement.getIntervalStartTime())/DateTimeUtils.MILLIS_IN_SECOND); } else { final Long prevLastTime = prevTimeLine.lower(m_firstMsgTime); if (prevLastTime != null) { m_gc.setTimeInMillis(prevLastTime); sc.setStat("LastTime", String.valueOf(m_dataTypeFactory.newXMLGregorianCalendar(m_gc))); final long delta = (m_firstMsgTime - prevLastTime) / DateTimeUtils.MILLIS_IN_SECOND; m_deltasInSeconds.add(delta); timeLineSet.add(prevLastTime); } } }
Example 2
Source File: I151SChapter05Activity.java From AndroidStudyDemo with GNU General Public License v2.0 | 6 votes |
/** * 建议64: 多种最值算法,适时选择 */ private void suggest64() { Integer[] datas = new Integer[]{}; // 转换为列表 List<Integer> dataList = Arrays.asList(datas.clone()); // 转换为TreeSet,删除重复元素并升序排列 TreeSet<Integer> treeSet = new TreeSet<>(dataList); // 取得比最大值小的最大值,也就是老二了 Integer second = treeSet.lower(treeSet.last()); /* 剔除重复元素并升序排列,这都由TreeSet类实现的,然后可再使用lower方法寻找小于最大值的值 */ /** * 注意 * 最值计算时使用集合最简单,使用数组性能最优 */ }
Example 3
Source File: MovingWindowAlgorithm.java From incubator-pinot with Apache License 2.0 | 6 votes |
/** * Returns variable-size look back window for given timestamp. * * @param df data * @param tCurrent end timestamp (exclusive) * @param changePoints change points * @return window data frame */ DataFrame makeWindow(DataFrame df, long tCurrent, TreeSet<Long> changePoints) { DateTime now = new DateTime(tCurrent); long tStart = now.minus(this.windowSize).getMillis(); // truncate history at change point but leave at least a window equal to changeDuration Long changePoint = changePoints.lower(tCurrent); if (changePoint != null) { tStart = Math.max(tStart, changePoint); } // use non-outlier period, unless not enough history (anomalies are outliers too) BooleanSeries timeFilter = df.getLongs(COL_TIME).between(tStart, tCurrent); BooleanSeries outlierAndTimeFilter = df.getBooleans(COL_OUTLIER).not().and(timeFilter); // TODO make threshold for fallback to outlier period configurable if (outlierAndTimeFilter.sum().fillNull().longValue() <= timeFilter.sum().fillNull().longValue() / 3) { return df.filter(timeFilter).dropNull(COL_TIME, COL_COMPUTED_VALUE); } return df.filter(outlierAndTimeFilter).dropNull(COL_TIME, COL_COMPUTED_VALUE); }
Example 4
Source File: TreeSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * lower returns preceding element */ public void testLower() { TreeSet q = set5(); Object e1 = q.lower(three); assertEquals(two, e1); Object e2 = q.lower(six); assertEquals(five, e2); Object e3 = q.lower(one); assertNull(e3); Object e4 = q.lower(zero); assertNull(e4); }
Example 5
Source File: TreeSetTest.java From JavaBase with MIT License | 5 votes |
@Test public void testSort() { // 获取第二大元素 Integer[] nums = {1, 2, 432, 4523, 5433452, 34523452, 4573, 33421, 3456, 8567, 342, 76, 1234}; TreeSet<Integer> treeSet = new TreeSet<>(Arrays.asList(nums)); Integer result = treeSet.lower(treeSet.last()); System.out.println(treeSet); assertThat(result, equalTo(5433452)); }
Example 6
Source File: TreeSetTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * lower returns preceding element */ public void testLower() { TreeSet q = set5(); Object e1 = q.lower(three); assertEquals(two, e1); Object e2 = q.lower(six); assertEquals(five, e2); Object e3 = q.lower(one); assertNull(e3); Object e4 = q.lower(zero); assertNull(e4); }
Example 7
Source File: ConfigSampler.java From bestconf with Apache License 2.0 | 4 votes |
private static ArrayList<Attribute> scaleDownNeighbordists(Instances previousSet, Instance center){ ArrayList<Attribute> localAtts = new ArrayList<Attribute>(); int attNum = center.numAttributes(); int pos = -1; if(previousSet.attribute(PerformanceAttName)!=null) pos = previousSet.attribute(PerformanceAttName).index(); //traverse each dimension Enumeration<Instance> enu; double[] minDists = new double[2]; double val; for(int i=0;i<attNum;i++){ if(i==pos) continue; enu = previousSet.enumerateInstances(); minDists[0] = 1-Double.MAX_VALUE; minDists[1] = Double.MAX_VALUE; while(enu.hasMoreElements()){ Instance ins = enu.nextElement(); if(!ins.equals(center)){ val = ins.value(i)-center.value(i); if(val<0) minDists[0] = Math.max((double)((int)((ins.value(i)-center.value(i))*1000))/1000.0, minDists[0]); else minDists[1] = Math.min((double)((int)((ins.value(i)-center.value(i))*1000))/1000.0, minDists[1]); } } //now we set the range Properties p1 = new Properties(); double upper = center.value(i)+minDists[1], lower=center.value(i)+minDists[0]; TreeSet<Double> detourSet = new TreeSet<Double>(); detourSet.add(upper); detourSet.add(lower); detourSet.add(previousSet.attribute(i).getUpperNumericBound()); detourSet.add(previousSet.attribute(i).getLowerNumericBound()); switch(detourSet.size()){ case 1: upper=lower=detourSet.first(); break; case 2: upper = detourSet.last(); lower = detourSet.first(); break; case 3: upper=lower=detourSet.higher(detourSet.first()); break; default://case 4: upper=detourSet.lower(detourSet.last()); lower=detourSet.higher(detourSet.first()); break; } p1.setProperty("range", "["+String.valueOf(lower)+","+String.valueOf(upper)+"]"); ProtectedProperties prop1 = new ProtectedProperties(p1); localAtts.add(new Attribute(previousSet.attribute(i).name(), prop1)); } return localAtts; }
Example 8
Source File: ConfigSampler.java From bestconf with Apache License 2.0 | 4 votes |
private static ArrayList<Attribute> scaleDownMindists(Instances previousSet, Instance center){ ArrayList<Attribute> localAtts = new ArrayList<Attribute>(); int attNum = center.numAttributes(); int pos = previousSet.attribute(PerformanceAttName).index(); //traverse each dimension Enumeration<Instance> enu; double minDis; for(int i=0;i<attNum;i++){ if(i==pos) continue; enu = previousSet.enumerateInstances(); minDis = Double.MAX_VALUE; while(enu.hasMoreElements()){ Instance ins = enu.nextElement(); if(!ins.equals(center)) minDis = Math.min((double)((int)(Math.abs(ins.value(i)-center.value(i))*1000))/1000.0, minDis); } //now we set the range Properties p1 = new Properties(); double upper = center.value(i)+minDis, lower=center.value(i)-minDis; TreeSet<Double> detourSet = new TreeSet<Double>(); detourSet.add(upper); detourSet.add(lower); detourSet.add(previousSet.attribute(i).getUpperNumericBound()); detourSet.add(previousSet.attribute(i).getLowerNumericBound()); switch(detourSet.size()){ case 1: upper=lower=detourSet.first(); break; case 2: upper = detourSet.last(); lower = detourSet.first(); break; case 3: upper=lower=detourSet.higher(detourSet.first()); break; default://case 4: upper=detourSet.lower(detourSet.last()); lower=detourSet.higher(detourSet.first()); break; } p1.setProperty("range", "["+String.valueOf(lower)+","+String.valueOf(upper)+"]"); ProtectedProperties prop1 = new ProtectedProperties(p1); localAtts.add(new Attribute(previousSet.attribute(i).name(), prop1)); } return localAtts; }
Example 9
Source File: BestConf.java From bestconf with Apache License 2.0 | 4 votes |
public static ArrayList<Attribute> scaleDownDetour(Instances previousSet, Instance center){ ArrayList<Attribute> localAtts = new ArrayList<Attribute>(); int attNum = center.numAttributes(); int pos = previousSet.attribute(PerformanceAttName).index(); //traverse each dimension Enumeration<Instance> enu; double minDis; for(int i=0;i<attNum;i++){ if(i==pos) continue; enu = previousSet.enumerateInstances(); minDis = Double.MAX_VALUE; while(enu.hasMoreElements()){ Instance ins = enu.nextElement(); if(!ins.equals(center)) minDis = Math.min((double)((int)(Math.abs(ins.value(i)-center.value(i))*100))/100.0, minDis); } //now we set the range Properties p1 = new Properties(); double upper = center.value(i)+minDis, lower=center.value(i)-minDis; TreeSet<Double> detourSet = new TreeSet<Double>(); detourSet.add(upper); detourSet.add(lower); detourSet.add(previousSet.attribute(i).getUpperNumericBound()); detourSet.add(previousSet.attribute(i).getLowerNumericBound()); switch(detourSet.size()){ case 1: upper=lower=detourSet.first(); break; case 2: upper = detourSet.last(); lower = detourSet.first(); break; case 3: upper=lower=detourSet.higher(detourSet.first()); break; default://case 4: upper=detourSet.lower(detourSet.last()); lower=detourSet.higher(detourSet.first()); break; } p1.setProperty("range", "["+String.valueOf(lower)+","+String.valueOf(upper)+"]"); ProtectedProperties prop1 = new ProtectedProperties(p1); localAtts.add(new Attribute(previousSet.attribute(i).name(), prop1)); } return localAtts; }