List of usage examples for java.util Collections max
public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll)
From source file:eionet.cr.dao.virtuoso.VirtuosoEndpointHarvestQueryDAO.java
@Override public void move(String endpointUrl, Set<Integer> ids, int direction) throws DAOException { if (StringUtils.isBlank(endpointUrl) || ids == null || ids.isEmpty()) { return;/*w ww. j av a 2 s.c o m*/ } if (direction == 0) { throw new IllegalArgumentException("Direction must not be 0!"); } // Prepare map where we can get queries by position, also find the max and min positions. LinkedHashMap<Integer, EndpointHarvestQueryDTO> queriesByPos = getQueriesByPosition(endpointUrl); if (queriesByPos.isEmpty()) { return; } Set<Integer> positions = queriesByPos.keySet(); int maxPos = Collections.max(positions); int minPos = Collections.min(positions); Connection conn = null; try { conn = getSQLConnection(); conn.setAutoCommit(false); // If even one query is already at position 1 then moving up is not considered possible. // And conversely, if even one query is already at the last position, then moving down // is not considered possible either. boolean isMovingPossible = true; List<Integer> selectedPositions = new ArrayList<Integer>(); List<EndpointHarvestQueryDTO> queries = new ArrayList<EndpointHarvestQueryDTO>(queriesByPos.values()); for (EndpointHarvestQueryDTO query : queries) { if (ids.contains(query.getId())) { int pos = query.getPosition(); if ((direction < 0 && pos == minPos) || (direction > 0 && pos == maxPos)) { isMovingPossible = false; } else { selectedPositions.add(pos); } } } if (isMovingPossible) { if (direction < 0) { for (Integer selectedPosition : selectedPositions) { EndpointHarvestQueryDTO queryToMove = queriesByPos.get(selectedPosition); int i = queries.indexOf(queryToMove); queries.set(i, queries.get(i - 1)); queries.set(i - 1, queryToMove); } } else { for (int j = selectedPositions.size() - 1; j >= 0; j--) { EndpointHarvestQueryDTO queryToMove = queriesByPos.get(selectedPositions.get(j)); int i = queries.indexOf(queryToMove); queries.set(i, queries.get(i + 1)); queries.set(i + 1, queryToMove); } } } SQLUtil.executeUpdate(INCREASE_POSITIONS_SQL, Arrays.asList(maxPos, endpointUrl), conn); for (int i = 0; i < queries.size(); i++) { SQLUtil.executeUpdate(UPDATE_POSITION_SQL, Arrays.asList(i + 1, queries.get(i).getId()), conn); } conn.commit(); } catch (Exception e) { SQLUtil.rollback(conn); throw new DAOException(e.getMessage(), e); } finally { SQLUtil.close(conn); } }
From source file:edu.wisc.ssec.mcidasv.data.hydra.Statistics.java
public static String sparkline(FlatField field, Statistics s) throws VisADException, RemoteException { Long[] values = histogram(field, 20); Real sMin = (Real) s.min();/*from w ww. j a v a 2 s .co m*/ Real sMax = (Real) s.max(); Collection<Long> collection = asList(values); long max = Collections.max(collection); long min = Collections.min(collection); float scale = (max - min) / 7f; final StringBuilder buf = new StringBuilder(values.length); // TJJ Mar 2018 - sandwich with min/max // http://mcidas.ssec.wisc.edu/inquiry-v/?inquiry=2548 buf.append(fmtMe((sMin).getValue())); for (Long value : values) { int index = Math.round((value - min) / scale); buf.append(CHARS.get(index)); } buf.append(fmtMe((sMax).getValue())); return buf.toString(); }
From source file:de.Maxr1998.xposed.maxlock.ui.LockFragment.java
@SuppressWarnings("deprecation") private void setupKnockCodeLayout() { final View container = rootView.findViewById(R.id.container); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) container.getLayoutParams(); params.setMargins(0, 0, 0, 0);/*from w ww .jav a 2s . c om*/ container.setLayoutParams(params); container.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent e) { if (e.getActionMasked() == MotionEvent.ACTION_DOWN) { mInputText.append("\u2022"); // Center values int[] loc = new int[2]; container.getLocationOnScreen(loc); int viewCenterX = loc[0] + container.getWidth() / 2; int viewCenterY = loc[1] + container.getHeight() / 2; // Track touch positions knockCodeX.add(e.getRawX()); knockCodeY.add(e.getRawY()); if (knockCodeX.size() != knockCodeY.size()) { throw new RuntimeException("The amount of the X and Y coordinates doesn't match!"); } // Calculate center float centerX; float differenceX = Collections.max(knockCodeX) - Collections.min(knockCodeX); if (differenceX > 50) { centerX = Collections.min(knockCodeX) + differenceX / 2; } else centerX = viewCenterX; float centerY; float differenceY = Collections.max(knockCodeY) - Collections.min(knockCodeY); if (differenceY > 50) { centerY = Collections.min(knockCodeY) + differenceY / 2; } else centerY = viewCenterY; // Calculate key key.setLength(0); for (int i = 0; i < knockCodeX.size(); i++) { float x = knockCodeX.get(i), y = knockCodeY.get(i); if (x < centerX && y < centerY) key.append("1"); else if (x > centerX && y < centerY) key.append("2"); else if (x < centerX && y > centerY) key.append("3"); else if (x > centerX && y > centerY) key.append("4"); } checkInput(); return true; } return false; } }); divider = new View(getActivity()); divider.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Math.round(getResources().getDisplayMetrics().density))); divider.setBackgroundColor(getResources().getColor(R.color.light_white)); ((ViewGroup) container).addView(divider); if (prefs.getBoolean(Common.INVERT_COLOR, false) && prefs.getBoolean(Common.KC_SHOW_DIVIDERS, true)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) divider.setBackground(getResources().getDrawable(android.R.color.black)); else divider.setBackgroundDrawable(getResources().getDrawable(android.R.color.black)); } else if (!prefs.getBoolean(Common.KC_SHOW_DIVIDERS, true) || screenWidth > screenHeight) { divider.setVisibility(View.GONE); } }
From source file:org.mifos.customers.group.business.GroupPerformanceHistoryEntity.java
public Short getMaxLoanCycleForProduct(final PrdOfferingBO prdOffering) { {/*w ww.j a v a 2 s . co m*/ Set<GroupLoanCounter> loanCounters = getLoanCounters(); try { Collection<Short> loanCyclesForProduct = select(loanCounters, new Predicate<GroupLoanCounter>() { @Override public boolean evaluate(GroupLoanCounter counter) { return counter.isOfSameProduct(prdOffering); } }, TRANSFORM_GROUP_LOAN_COUNTER_TO_LOAN_CYCLE); return loanCyclesForProduct.isEmpty() ? SHORT_ZERO : Collections.max(loanCyclesForProduct); } catch (Exception e) { return SHORT_ZERO; } } }
From source file:wef.articulab.view.ui.CombinedBNXYPlot.java
public void setDataset(ChartContainer chartContainer, ArrayList<Double>[] behaviors, double threshhold, String nameBehActivated, double activation) { chartContainer.behaviors = behaviors; chartContainer.thresholds.add(threshhold); chartContainer.activations.add(new Object[] { nameBehActivated, activation }); chartContainer.maxThreshold = Collections.max(chartContainer.thresholds); chartContainer.minThreshold = Collections.min(chartContainer.thresholds); if (activation > chartContainer.maxActivation) { chartContainer.maxActivation = activation; }//from www .ja v a2 s.co m double portion = (chartContainer.maxThreshold - chartContainer.minThreshold) / 6; if ((portion * 6) > (chartContainer.maxActivation / 4)) { chartContainer.maxThreshold = threshhold + portion > chartContainer.maxThreshold ? chartContainer.maxThreshold : threshhold + portion; chartContainer.minThreshold = threshhold - portion < chartContainer.minThreshold ? chartContainer.minThreshold : threshhold - portion; } refreshDataset(chartContainer); }
From source file:com.anstar.fieldwork.CaptureSignatureActivity.java
public float getHighest(ArrayList<SignaturePoints> m_list) { if (m_list != null && m_list.size() > 0) { ArrayList<Float> temp = new ArrayList<Float>(); for (SignaturePoints s : m_list) { temp.add(s.lx);/*from w ww . ja v a2 s . c o m*/ temp.add(s.ly); temp.add(s.mx); temp.add(s.my); } float h = Collections.max(temp); return h; } else { return 0; } }
From source file:org.onosproject.bmv2.demo.app.wcmp.WcmpFabricApp.java
public List<Integer> toPrefixLengths(List<Double> weigths) { final double weightSum = weigths.stream().mapToDouble(Double::doubleValue).map(this::roundDouble).sum(); if (Math.abs(weightSum - 1) > 0.0001) { throw new RuntimeException("WCMP weights sum is expected to be 1, found was " + weightSum); }//from w w w. j a v a 2 s .c om final int selectorBitWidth = WCMP_CONTEXT.configuration().headerType(WCMP_META_T).field(SELECTOR) .bitWidth(); final int availableBits = selectorBitWidth - 1; List<Long> prefixDiffs = weigths.stream().map(w -> Math.round(w * availableBits)).collect(toList()); final long bitSum = prefixDiffs.stream().mapToLong(Long::longValue).sum(); final long error = availableBits - bitSum; if (error != 0) { // Lazy intuition here is that the error can be absorbed by the longest prefixDiff with the minor impact. Long maxDiff = Collections.max(prefixDiffs); int idx = prefixDiffs.indexOf(maxDiff); prefixDiffs.remove(idx); prefixDiffs.add(idx, maxDiff + error); } List<Integer> prefixLengths = Lists.newArrayList(); int prefix = 1; for (Long p : prefixDiffs) { prefixLengths.add(prefix); prefix += p; } return ImmutableList.copyOf(prefixLengths); }
From source file:org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.java
private void loadDescriptorDictionary(PDFontDescriptorDictionary fd, InputStream ttfData) throws IOException { TrueTypeFont ttf = null;/*from w w w . jav a2 s .com*/ try { TTFParser parser = new TTFParser(); ttf = parser.parseTTF(ttfData); NamingTable naming = ttf.getNaming(); List<NameRecord> records = naming.getNameRecords(); for (int i = 0; i < records.size(); i++) { NameRecord nr = records.get(i); if (nr.getNameId() == NameRecord.NAME_POSTSCRIPT_NAME) { setBaseFont(nr.getString()); fd.setFontName(nr.getString()); } else if (nr.getNameId() == NameRecord.NAME_FONT_FAMILY_NAME) { fd.setFontFamily(nr.getString()); } } OS2WindowsMetricsTable os2 = ttf.getOS2Windows(); boolean isSymbolic = false; switch (os2.getFamilyClass()) { case OS2WindowsMetricsTable.FAMILY_CLASS_SYMBOLIC: isSymbolic = true; break; case OS2WindowsMetricsTable.FAMILY_CLASS_SCRIPTS: fd.setScript(true); break; case OS2WindowsMetricsTable.FAMILY_CLASS_CLAREDON_SERIFS: case OS2WindowsMetricsTable.FAMILY_CLASS_FREEFORM_SERIFS: case OS2WindowsMetricsTable.FAMILY_CLASS_MODERN_SERIFS: case OS2WindowsMetricsTable.FAMILY_CLASS_OLDSTYLE_SERIFS: case OS2WindowsMetricsTable.FAMILY_CLASS_SLAB_SERIFS: fd.setSerif(true); break; default: //do nothing } switch (os2.getWidthClass()) { case OS2WindowsMetricsTable.WIDTH_CLASS_ULTRA_CONDENSED: fd.setFontStretch("UltraCondensed"); break; case OS2WindowsMetricsTable.WIDTH_CLASS_EXTRA_CONDENSED: fd.setFontStretch("ExtraCondensed"); break; case OS2WindowsMetricsTable.WIDTH_CLASS_CONDENSED: fd.setFontStretch("Condensed"); break; case OS2WindowsMetricsTable.WIDTH_CLASS_SEMI_CONDENSED: fd.setFontStretch("SemiCondensed"); break; case OS2WindowsMetricsTable.WIDTH_CLASS_MEDIUM: fd.setFontStretch("Normal"); break; case OS2WindowsMetricsTable.WIDTH_CLASS_SEMI_EXPANDED: fd.setFontStretch("SemiExpanded"); break; case OS2WindowsMetricsTable.WIDTH_CLASS_EXPANDED: fd.setFontStretch("Expanded"); break; case OS2WindowsMetricsTable.WIDTH_CLASS_EXTRA_EXPANDED: fd.setFontStretch("ExtraExpanded"); break; case OS2WindowsMetricsTable.WIDTH_CLASS_ULTRA_EXPANDED: fd.setFontStretch("UltraExpanded"); break; default: //do nothing } fd.setFontWeight(os2.getWeightClass()); fd.setSymbolic(isSymbolic); fd.setNonSymbolic(!isSymbolic); //todo retval.setFixedPitch //todo retval.setItalic //todo retval.setAllCap //todo retval.setSmallCap //todo retval.setForceBold HeaderTable header = ttf.getHeader(); PDRectangle rect = new PDRectangle(); float scaling = 1000f / header.getUnitsPerEm(); rect.setLowerLeftX(header.getXMin() * scaling); rect.setLowerLeftY(header.getYMin() * scaling); rect.setUpperRightX(header.getXMax() * scaling); rect.setUpperRightY(header.getYMax() * scaling); fd.setFontBoundingBox(rect); HorizontalHeaderTable hHeader = ttf.getHorizontalHeader(); fd.setAscent(hHeader.getAscender() * scaling); fd.setDescent(hHeader.getDescender() * scaling); GlyphTable glyphTable = ttf.getGlyph(); GlyphData[] glyphs = glyphTable.getGlyphs(); PostScriptTable ps = ttf.getPostScript(); fd.setFixedPitch(ps.getIsFixedPitch() > 0); fd.setItalicAngle(ps.getItalicAngle()); String[] names = ps.getGlyphNames(); if (names != null) { for (int i = 0; i < names.length; i++) { //if we have a capital H then use that, otherwise use the //tallest letter if (names[i].equals("H")) { fd.setCapHeight(glyphs[i].getBoundingBox().getUpperRightY() / scaling); } if (names[i].equals("x")) { fd.setXHeight(glyphs[i].getBoundingBox().getUpperRightY() / scaling); } } } //hmm there does not seem to be a clear definition for StemV, //this is close enough and I am told it doesn't usually get used. fd.setStemV((fd.getFontBoundingBox().getWidth() * .13f)); CMAPTable cmapTable = ttf.getCMAP(); CMAPEncodingEntry[] cmaps = cmapTable.getCmaps(); CMAPEncodingEntry uniMap = null; for (int i = 0; i < cmaps.length; i++) { if (cmaps[i].getPlatformId() == CMAPTable.PLATFORM_WINDOWS) { int platformEncoding = cmaps[i].getPlatformEncodingId(); if (CMAPTable.ENCODING_UNICODE == platformEncoding) { uniMap = cmaps[i]; break; } } } Map<Integer, String> codeToName = this.getFontEncoding().getCodeToNameMap(); int firstChar = Collections.min(codeToName.keySet()); int lastChar = Collections.max(codeToName.keySet()); HorizontalMetricsTable hMet = ttf.getHorizontalMetrics(); int[] widthValues = hMet.getAdvanceWidth(); int nWidths = lastChar - firstChar + 1; List<Float> widths = new ArrayList<Float>(nWidths); // width of the .notdef character. Float zero = Float.valueOf(widthValues[0] * scaling); for (int i = 0; i < nWidths; i++) { widths.add(zero); } // Encoding singleton to have acces to the chglyph name to // unicode cpoint point mapping of Adobe's glyphlist.txt Encoding glyphlist = WinAnsiEncoding.INSTANCE; // A character code is mapped to a glyph name via the provided // font encoding. Afterwards, the glyph name is translated to a // glyph ID. // For details, see PDFReference16.pdf, Section 5.5.5, p.401 // for (Entry<Integer, String> e : codeToName.entrySet()) { String name = e.getValue(); // pdf code to unicode by glyph list. String c = glyphlist.getCharacter(name); int charCode = c.codePointAt(0); int gid = uniMap.getGlyphId(charCode); if (gid != 0) { widths.set(e.getKey().intValue() - firstChar, widthValues[gid] * scaling); } } setWidths(widths); setFirstChar(firstChar); setLastChar(lastChar); } finally { if (ttf != null) { ttf.close(); } } }
From source file:mx.itesm.web2mexadl.cluster.ClusterAnalyzer.java
/** * Generate the architecture document associated to the specified web * application data.//from w w w . j a va 2 s .c o m * * @param clustersData * @param internalPackages * @param outputDir * @return * @throws JDOMException * @throws IOException */ private static Map<String, Cluster> generateArchitecture(final Dataset[] clustersData, final Map<String, Set<String>> internalPackages, final File outputDir) throws IOException, JDOMException { int maxCount; int clusterIndex; int[] clustersCounts; Cluster[] clusters; List<Integer> clusterCountsList; Map<String, Cluster> returnValue; Set<String> currentPackageContent; StringBuilder[] implementationPackages; HashMap<String, Integer> clusterClasses; Map<String, Integer> packagesClassification; // Get the clusters assignments clusterIndex = -1; clusterClasses = new HashMap<String, Integer>(); for (Dataset cluster : clustersData) { clusterIndex++; for (Object clazz : cluster.classes()) { clusterClasses.put(clazz.toString(), clusterIndex); } } // Initialize clusters clusters = new Cluster[clustersData.length]; for (int i = 0; i < clustersData.length; i++) { clusters[i] = new Cluster(ClusterAnalyzer.getRandomColor()); } // Initialize implementation packages implementationPackages = new StringBuilder[clustersData.length]; for (int i = 0; i < implementationPackages.length; i++) { implementationPackages[i] = new StringBuilder(); } // Classify packages clustersCounts = new int[clustersData.length]; returnValue = new HashMap<String, Cluster>(); packagesClassification = new HashMap<String, Integer>(internalPackages.size()); for (String currentPackage : internalPackages.keySet()) { currentPackageContent = internalPackages.get(currentPackage); for (String component : currentPackageContent) { // Check if this component was assigned to any cluster if (clusterClasses.keySet().contains(component)) { clustersCounts[clusterClasses.get(component)]++; returnValue.put(component, clusters[clusterClasses.get(component)]); } } // Get the package cluster according to the most common cluster // between the package contents clusterCountsList = new ArrayList<Integer>(clustersCounts.length); for (int i : clustersCounts) { clusterCountsList.add(i); } maxCount = Collections.max(clusterCountsList); for (int i = 0; i < clustersCounts.length; i++) { if (clustersCounts[i] == maxCount) { packagesClassification.put(currentPackage, i); Util.addImplementationPackage(implementationPackages[i], currentPackage); break; } } } ClusterAnalyzer.exportToMexADL(outputDir, implementationPackages); return returnValue; }
From source file:org.geowebcache.grid.GridSubset.java
public int getZoomStop() { Integer maxLevel = Collections.max(gridCoverageLevels.keySet()); return maxLevel.intValue(); }