List of usage examples for java.util Collections min
public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll)
From source file:org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.java
private void loadDescriptorDictionary(PDFontDescriptorDictionary fd, InputStream ttfData) throws IOException { TrueTypeFont ttf = null;/*w w w. ja v a2s . c o m*/ 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:org.geowebcache.grid.GridSubset.java
public int getZoomStart() { Integer firstLevel = Collections.min(gridCoverageLevels.keySet()); return firstLevel.intValue(); }
From source file:com.xpn.xwiki.store.hibernate.query.HqlQueryExecutor.java
/** * @param hquery query to populate parameters * @param query query from to populate.//w w w .j a v a2 s . c o m */ protected void populateParameters(org.hibernate.Query hquery, Query query) { if (query.getOffset() > 0) { hquery.setFirstResult(query.getOffset()); } if (query.getLimit() > 0) { hquery.setMaxResults(query.getLimit()); } for (Entry<String, Object> e : query.getNamedParameters().entrySet()) { setNamedParameter(hquery, e.getKey(), e.getValue()); } if (query.getPositionalParameters().size() > 0) { int start = Collections.min(query.getPositionalParameters().keySet()); if (start == 0) { // jdbc-style positional parameters. "?" for (Entry<Integer, Object> e : query.getPositionalParameters().entrySet()) { hquery.setParameter(e.getKey(), e.getValue()); } } else { // jpql-style. "?index" for (Entry<Integer, Object> e : query.getPositionalParameters().entrySet()) { // hack. hibernate assume "?1" is named parameter, so use string "1". setNamedParameter(hquery, String.valueOf(e.getKey()), e.getValue()); } } } }
From source file:org.apache.hadoop.hbase.client.TestMultipleTimestamps.java
/** * Uses the TimestampFilter on a Get to request a specified list of * versions for the row/column specified by rowIdx & colIdx. * *//*from ww w . j a va2 s. c om*/ private Cell[] getNVersions(HTable ht, byte[] cf, int rowIdx, int colIdx, List<Long> versions) throws IOException { byte row[] = Bytes.toBytes("row:" + rowIdx); byte column[] = Bytes.toBytes("column:" + colIdx); Get get = new Get(row); get.addColumn(cf, column); get.setMaxVersions(); get.setTimeRange(Collections.min(versions), Collections.max(versions) + 1); Result result = ht.get(get); return result.rawCells(); }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.area.AreaDRResultsController.java
/** * Create PdfTable with info on each condition of the analysis group; * * @return/*from ww w. j a v a2 s. c o m*/ */ //possibly reuse dRInputController's createTableModel(List<PlateCondition> processedConditions) @Override protected PdfPTable createAnalysisGroupInfoTable() { //maps log transformed conc (double) to list of velocities (double) List<DoseResponsePair> fittedData = doseResponseController.getDataToFit(false); //CONTROL HAS BEEN GIVEN A CONCENTRATION FOR FITTING PURPOSES: find control concentration (lowest) List<Double> allConcentrations = new ArrayList<>(); for (DoseResponsePair row : fittedData) { allConcentrations.add(row.getDose()); } Double controlConcentration = Collections.min(allConcentrations); // new table with 6 columns PdfPTable dataTable = new PdfPTable(6); PdfUtils.setUpPdfPTable(dataTable); // add 1st row: column names PdfUtils.addCustomizedCell(dataTable, "DRUG CONCENTRATION", boldFont); PdfUtils.addCustomizedCell(dataTable, "# TECHNICAL REPLICATES", boldFont); PdfUtils.addCustomizedCell(dataTable, "TECHNICAL REPLICATES EXCLUDED?", boldFont); PdfUtils.addCustomizedCell(dataTable, "LOWEST VELOCITY", boldFont); PdfUtils.addCustomizedCell(dataTable, "HIGHEST VELOCITY", boldFont); PdfUtils.addCustomizedCell(dataTable, "MEDIAN VELOCITY", boldFont); // for each condition get results and add a cell for (DoseResponsePair condition : fittedData) { Integer replicates = condition.getResponses().size(); String excluded; int excludedCount = 0; List<Double> velocities = condition.getResponses(); //count how many replicates were excluded for (int i = 0; i < velocities.size(); i++) { Double replicate = velocities.get(i); if (replicate == null) { excludedCount++; } } if (excludedCount == 0) { excluded = "NO"; } else { excluded = "YES, " + excludedCount; } //put log-value of the concentration back to an understandable format String concentration; Double logConc = condition.getDose(); Double transformed = Math.pow(10, logConc); //check which concentration unit is to be used //if lower than 0.1 M: use nM unit if (transformed < Math.pow(10, -7)) { concentration = AnalysisUtils.roundTwoDecimals(transformed * Math.pow(10, 9)) + " nM"; } //if lower than 0.1 mM: use M unit else if (transformed < Math.pow(10, -3)) { concentration = AnalysisUtils.roundTwoDecimals(transformed * Math.pow(10, 6)) + " M"; } //else for everything >= 1 mM use mM unit else { concentration = AnalysisUtils.roundTwoDecimals(transformed * Math.pow(10, 3)) + " mM"; } //if this is the control, replace concentration string if (logConc.equals(controlConcentration)) { concentration = "Control"; } //remove null's (excluded replicates) from velocities collection velocities.removeAll(Collections.singleton(null)); PdfUtils.addCustomizedCell(dataTable, concentration, bodyFont); PdfUtils.addCustomizedCell(dataTable, replicates.toString(), bodyFont); PdfUtils.addCustomizedCell(dataTable, excluded, bodyFont); PdfUtils.addCustomizedCell(dataTable, AnalysisUtils.roundThreeDecimals(Collections.min(velocities)).toString(), bodyFont); PdfUtils.addCustomizedCell(dataTable, AnalysisUtils.roundThreeDecimals(Collections.max(velocities)).toString(), bodyFont); PdfUtils.addCustomizedCell(dataTable, AnalysisUtils.roundThreeDecimals(AnalysisUtils.computeMedian(velocities)).toString(), bodyFont); } return dataTable; }
From source file:org.apache.hadoop.hbase.client.TestMultipleTimestamps.java
private ResultScanner scan(HTable ht, byte[] cf, Integer[] rowIndexes, Integer[] columnIndexes, Long[] versions, int maxVersions) throws IOException { Arrays.asList(rowIndexes);/* www. j a va 2s . c om*/ byte startRow[] = Bytes.toBytes("row:" + Collections.min(Arrays.asList(rowIndexes))); byte endRow[] = Bytes.toBytes("row:" + Collections.max(Arrays.asList(rowIndexes)) + 1); Scan scan = new Scan(startRow, endRow); for (Integer colIdx : columnIndexes) { byte column[] = Bytes.toBytes("column:" + colIdx); scan.addColumn(cf, column); } scan.setMaxVersions(maxVersions); scan.setTimeRange(Collections.min(Arrays.asList(versions)), Collections.max(Arrays.asList(versions)) + 1); ResultScanner scanner = ht.getScanner(scan); return scanner; }
From source file:org.apache.lens.cube.metadata.CubeFactTable.java
public Date getEndTime() { return Collections.min(Lists.newArrayList(getRelativeEndTime(), getAbsoluteEndTime())); }
From source file:au.org.ala.delta.intkey.ui.CharacterImageDialog.java
public FloatRange getInputRealValues() { FloatRange retRange = null;/*from ww w. j a v a 2s .c o m*/ String inputText = _multipleImageViewer.getVisibleViewer().getInputText(); if (!StringUtils.isEmpty(inputText)) { // Use value supplied in input field retRange = ParsingUtils.parseRealCharacterValue(inputText); } else { // Use values for selected value fields if (!_selectedValues.isEmpty()) { Set<Float> boundsSet = new HashSet<Float>(); for (Pair<String, String> selectedValue : _selectedValues) { float minVal = Float.parseFloat(selectedValue.getFirst()); boundsSet.add(minVal); // Second value in the pair will be null if the value field // represents a // single real value rather than a range. if (selectedValue.getSecond() != null) { float maxVal = Float.parseFloat(selectedValue.getSecond()); boundsSet.add(maxVal); } } float overallMin = Collections.min(boundsSet); float overallMax = Collections.max(boundsSet); retRange = new FloatRange(overallMin, overallMax); } } // if the range is still null, return a float range with negative // infinity. This represents "no values selected". if (retRange == null) { retRange = new FloatRange(Float.NEGATIVE_INFINITY); } return retRange; }
From source file:de.tud.kom.p2psim.impl.network.gnp.topology.GnpSpace.java
/** * Calculates a good positions for the host * /* w ww . j av a 2 s . c o m*/ * @param host * to position * @param monitorResheduling * number of rescheduling the downhill simplex * @return gnp position for peer */ private GnpPosition insertCoordinateDownhillSimplex(Host host, int monitorResheduling) { double alpha = 1.0; double beta = 0.5; double gamma = 2; double maxDiversity = 0.5; // N + 1 initial random Solutions ArrayList<GnpPosition> solutions = new ArrayList<GnpPosition>(noOfDimensions + 1); for (int c = -1; c < noOfDimensions; c++) { GnpPosition coord = new GnpPosition(noOfDimensions, host, this); solutions.add(coord); } // best and worst solution GnpPosition bestSolution = Collections.min(solutions); GnpPosition worstSolution = Collections.max(solutions); double bestError = bestSolution.getDownhillSimplexError(); double worstError = worstSolution.getDownhillSimplexError(); double newError = 0.0; for (int z = 0; z < monitorResheduling; z++) { // resheduling for (GnpPosition coord : solutions) { if (coord != bestSolution) { coord.diversify(this.getDimension(), maxDiversity); } } // best and worst solution bestSolution = Collections.min(solutions); worstSolution = Collections.max(solutions); bestError = bestSolution.getDownhillSimplexError(); worstError = worstSolution.getDownhillSimplexError(); // stop criterion while (worstError - bestError > 0.000001 && calculationInProgress) { // move to center ... GnpPosition center = GnpPosition.getCenterSolution(solutions); GnpPosition newSolution1 = GnpPosition.getMovedSolution(worstSolution, center, 1 + alpha); newError = newSolution1.getDownhillSimplexError(); if (newError <= bestError) { GnpPosition newSolution2 = GnpPosition.getMovedSolution(worstSolution, center, 1 + alpha + gamma); int IndexOfWorstSolution = solutions.indexOf(worstSolution); if (newSolution2.getDownhillSimplexError() <= newError) { solutions.set(IndexOfWorstSolution, newSolution2); } else { solutions.set(IndexOfWorstSolution, newSolution1); } bestSolution = solutions.get(IndexOfWorstSolution); bestError = bestSolution.getDownhillSimplexError(); } else if (newError < worstError) { int IndexOfWorstSolution = solutions.indexOf(worstSolution); solutions.set(IndexOfWorstSolution, newSolution1); } else { // ... or contract around best solution for (int c = 0; c < solutions.size(); c++) { if (solutions.get(c) != bestSolution) solutions.set(c, GnpPosition.getMovedSolution(solutions.get(c), bestSolution, beta)); } bestSolution = Collections.min(solutions); bestError = bestSolution.getDownhillSimplexError(); } worstSolution = Collections.max(solutions); worstError = worstSolution.getDownhillSimplexError(); } } // Set the Coordinate Reference to the Peer host.setPositionReference(bestSolution); return bestSolution; }
From source file:org.peerfact.impl.network.gnp.topology.GnpSpace.java
/** * Calculates a good positions for the host * /*w ww. j av a 2 s. c o m*/ * @param host * to position * @param monitorResheduling * number of rescheduling the downhill simplex * @return gnp position for peer */ private GnpPosition insertCoordinateDownhillSimplex(Host host, int monitorResheduling) { double alpha = 1.0; double beta = 0.5; double gamma = 2; double maxDiversity = 0.5; // N + 1 initial random Solutions ArrayList<GnpPosition> solutions = new ArrayList<GnpPosition>(noOfDimensions + 1); for (int c = -1; c < noOfDimensions; c++) { GnpPosition coord = new GnpPosition(noOfDimensions, host, this); solutions.add(coord); } // best and worst solution GnpPosition bestSolution = Collections.min(solutions); GnpPosition worstSolution = Collections.max(solutions); double bestError = bestSolution.getDownhillSimplexError(); double worstError = worstSolution.getDownhillSimplexError(); double newError = 0.0; for (int z = 0; z < monitorResheduling; z++) { // resheduling for (GnpPosition coord : solutions) { if (coord != bestSolution) { coord.diversify(this.getDimension(), maxDiversity); } } // best and worst solution bestSolution = Collections.min(solutions); worstSolution = Collections.max(solutions); bestError = bestSolution.getDownhillSimplexError(); worstError = worstSolution.getDownhillSimplexError(); // stop criterion while (worstError - bestError > 0.000001 && calculationInProgress) { // move to center ... GnpPosition center = GnpPosition.getCenterSolution(solutions); GnpPosition newSolution1 = GnpPosition.getMovedSolution(worstSolution, center, 1 + alpha); newError = newSolution1.getDownhillSimplexError(); if (newError <= bestError) { GnpPosition newSolution2 = GnpPosition.getMovedSolution(worstSolution, center, 1 + alpha + gamma); int IndexOfWorstSolution = solutions.indexOf(worstSolution); if (newSolution2.getDownhillSimplexError() <= newError) { solutions.set(IndexOfWorstSolution, newSolution2); } else { solutions.set(IndexOfWorstSolution, newSolution1); } bestSolution = solutions.get(IndexOfWorstSolution); bestError = bestSolution.getDownhillSimplexError(); } else if (newError < worstError) { int IndexOfWorstSolution = solutions.indexOf(worstSolution); solutions.set(IndexOfWorstSolution, newSolution1); } else { // ... or contract around best solution for (int c = 0; c < solutions.size(); c++) { if (solutions.get(c) != bestSolution) { solutions.set(c, GnpPosition.getMovedSolution(solutions.get(c), bestSolution, beta)); } } bestSolution = Collections.min(solutions); bestError = bestSolution.getDownhillSimplexError(); } worstSolution = Collections.max(solutions); worstError = worstSolution.getDownhillSimplexError(); } } // Set the Coordinate Reference to the Peer host.setPositionReference(bestSolution); return bestSolution; }