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:gr.iti.mklab.reveal.forensics.util.Util.java
public static double[][] normalizeIm(float[][] imIn) { // Normalize single-channel image pixel values to [0, 1] int imWidth = imIn.length; int imHeight = imIn[0].length; double imOut[][] = new double[imWidth][imHeight]; double min = Double.MAX_VALUE; double max = -Double.MAX_VALUE; double colMin, colMax; for (float[] imInRow : imIn) { List<Float> b = Arrays.asList(ArrayUtils.toObject(imInRow)); colMin = (float) Collections.min(b); if (colMin < min) { min = colMin;/*from w w w. j av a2s . c o m*/ } colMax = (float) Collections.max(b); if (colMax > max) { max = colMax; } } double spread = max - min; for (int ii = 0; ii < imWidth; ii++) { for (int jj = 0; jj < imHeight; jj++) { imOut[ii][jj] = (imIn[ii][jj] - min) / spread; } } return imOut; }
From source file:de.tudarmstadt.ukp.clarin.webanno.tcf.TcfReader.java
/** * Get the start and end offsets of a span annotation * //from w w w .j a v a2 s. c om * @param aSpanTokens * list of span {@link eu.clarin.weblicht.wlfxb.tc.api.Token}s * @param aAllTokens * all available tokens in the file */ private int[] getOffsets(eu.clarin.weblicht.wlfxb.tc.api.Token[] aSpanTokens, Map<String, Token> aAllTokens) { List<Integer> beginPositions = new ArrayList<Integer>(); List<Integer> endPositions = new ArrayList<Integer>(); for (eu.clarin.weblicht.wlfxb.tc.api.Token token : aSpanTokens) { beginPositions.add(aAllTokens.get(token.getID()).getBegin()); endPositions.add(aAllTokens.get(token.getID()).getEnd()); } return new int[] { (Collections.min(beginPositions)), (Collections.max(endPositions)) }; }
From source file:org.gradoop.flink.model.impl.operators.matching.common.query.QueryHandler.java
/** * Returns all vertex ids that have a minimum eccentricity. * * @return vertex identifiers// ww w . j av a 2 s . co m */ public Collection<Long> getCentralVertexIds() { Map<Long, Integer> eccMap = GraphMetrics.getEccentricity(this); Integer min = Collections.min(eccMap.values()); List<Long> result = Lists.newArrayList(); for (Map.Entry<Long, Integer> eccEntry : eccMap.entrySet()) { if (eccEntry.getValue().equals(min)) { result.add(eccEntry.getKey()); } } return result; }
From source file:com.vgi.mafscaling.OpenLoop.java
private void setRanges() { double paddingX; double paddingY; XYPlot plot = mafChartPanel.getChartPanel().getChart().getXYPlot(); plot.getDomainAxis(0).setLabel(XAxisName); plot.getRangeAxis(1).setLabel(Y2AxisName); plot.getRangeAxis(0).setVisible(true); if (checkBoxMafRpmData.isSelected() && checkBoxMafRpmData.isEnabled()) { paddingX = runData.getMaxX() * 0.05; paddingY = runData.getMaxY() * 0.05; plot.getDomainAxis(0).setRange(runData.getMinX() - paddingX, runData.getMaxX() + paddingX); plot.getRangeAxis(1).setRange(runData.getMinY() - paddingY, runData.getMaxY() + paddingY); plot.getRangeAxis(0).setVisible(false); plot.getRangeAxis(1).setLabel(XAxisName); plot.getDomainAxis(0).setLabel(rpmAxisName); } else if (checkBoxRunData.isSelected() && checkBoxRunData.isEnabled() && !checkBoxCurrentMaf.isSelected() && !checkBoxCorrectedMaf.isSelected() && !checkBoxSmoothedMaf.isSelected()) { paddingX = runData.getMaxX() * 0.05; paddingY = runData.getMaxY() * 0.05; plot.getDomainAxis(0).setRange(runData.getMinX() - paddingX, runData.getMaxX() + paddingX); plot.getRangeAxis(1).setRange(runData.getMinY() - paddingY, runData.getMaxY() + paddingY); } else if (checkBoxSmoothing.isSelected()) { double maxY = Collections.max(Arrays.asList( new Double[] { currMafData.getMaxY(), smoothMafData.getMaxY(), corrMafData.getMaxY() })); double minY = Collections.min(Arrays.asList( new Double[] { currMafData.getMinY(), smoothMafData.getMinY(), corrMafData.getMinY() })); paddingX = smoothMafData.getMaxX() * 0.05; paddingY = maxY * 0.05;/*from ww w .ja v a2 s. com*/ plot.getDomainAxis(0).setRange(smoothMafData.getMinX() - paddingX, smoothMafData.getMaxX() + paddingX); plot.getRangeAxis(0).setRange(minY - paddingY, maxY + paddingY); } else if ((checkBoxCurrentMaf.isSelected() && checkBoxCurrentMaf.isEnabled()) || (checkBoxCorrectedMaf.isSelected() && checkBoxCorrectedMaf.isEnabled()) || (checkBoxSmoothedMaf.isSelected() && checkBoxSmoothedMaf.isEnabled())) { paddingX = voltArray.get(voltArray.size() - 1) * 0.05; paddingY = gsCorrected.get(gsCorrected.size() - 1) * 0.05; plot.getDomainAxis(0).setRange(voltArray.get(0) - paddingX, voltArray.get(voltArray.size() - 1) + paddingX); plot.getRangeAxis(0).setRange(gsCorrected.get(0) - paddingY, gsCorrected.get(gsCorrected.size() - 1) + paddingY); if (checkBoxRunData.isSelected()) { paddingX = runData.getMaxX() * 0.05; paddingY = runData.getMaxY() * 0.05; plot.getRangeAxis(1).setRange(runData.getMinY() - paddingY, runData.getMaxY() + paddingY); } } else { plot.getRangeAxis(0).setAutoRange(true); plot.getDomainAxis(0).setAutoRange(true); } }
From source file:de.tudarmstadt.ukp.clarin.webanno.tcf.TcfReader.java
/** * Get the start and end offsets of a span annotation * //from w ww. ja v a2 s . c om * @param aSpanTokens * list of span token ids. [t_3,_t_5, t_1] * @param aAllTokens * all available tokens in the file */ private int[] getOffsets(String[] aSpanTokens, Map<String, Token> aAllTokens) { List<Integer> beginPositions = new ArrayList<Integer>(); List<Integer> endPositions = new ArrayList<Integer>(); for (String token : aSpanTokens) { beginPositions.add(aAllTokens.get(token).getBegin()); endPositions.add(aAllTokens.get(token).getEnd()); } return new int[] { (Collections.min(beginPositions)), (Collections.max(endPositions)) }; }
From source file:gr.iti.mklab.reveal.forensics.util.Util.java
public static double[][] normalizeIm(double[][] imIn) { // Normalize single-channel image pixel values to [0, 1] int imWidth = imIn.length; int imHeight = imIn[0].length; double imOut[][] = new double[imWidth][imHeight]; double min = Double.MAX_VALUE; double max = -Double.MAX_VALUE; double colMin, colMax; for (double[] imInRow : imIn) { List<Double> b = Arrays.asList(ArrayUtils.toObject(imInRow)); colMin = (double) Collections.min(b); if (colMin < min) { min = colMin;/*from w w w .j ava2 s . c om*/ } colMax = (double) Collections.max(b); if (colMax > max) { max = colMax; } } double spread = max - min; for (int ii = 0; ii < imWidth; ii++) { for (int jj = 0; jj < imHeight; jj++) { imOut[ii][jj] = (imIn[ii][jj] - min) / spread; } } return imOut; }
From source file:Main_Window.java
public void Send_Receive_Data_Google_Service(boolean State) { try {/* w ww. j a v a 2s.co m*/ ServerAddress = new URL("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + Double.parseDouble(Latitude_TextField.getText()) + "," + Double.parseDouble(Longitude_TextField.getText()) + "&radius=" + Double.parseDouble(Radius_TextField.getText()) + "&opennow=" + Boolean.toString(State) + "&types=" + Categories.getSelectedItem().toString() + "&key=" + API_KEY); //DELTE String str = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + Double.parseDouble(Latitude_TextField.getText()) + "," + Double.parseDouble(Longitude_TextField.getText()) + "&radius=" + Double.parseDouble(Radius_TextField.getText()) + "&opennow=" + Boolean.toString(State) + "&types=" + Categories.getSelectedItem().toString() + "&key=" + API_KEY; System.out.println(" To url einai -> " + str); //set up out communications stuff Connection = null; //Set up the initial connection Connection = (HttpURLConnection) ServerAddress.openConnection(); Connection.setRequestMethod("GET"); Connection.setDoOutput(true); //Set the DoOutput flag to true if you intend to use the URL connection for output Connection.setDoInput(true); Connection.setRequestProperty("Content-type", "text/xml"); //Sets the general request property Connection.setAllowUserInteraction(false); Encode_String = URLEncoder.encode("test", "UTF-8"); Connection.setRequestProperty("Content-length", "" + Encode_String.length()); Connection.setReadTimeout(10000); // A non-zero value specifies the timeout when reading from Input stream when a connection is established to a resource. //If the timeout expires before there is data available for read, a java.net.SocketTimeoutException is raised. } catch (IOException IOE) { JOptionPane.showMessageDialog(null, "Error -> " + IOE.getLocalizedMessage(), "Exception - IOException", JOptionPane.ERROR_MESSAGE, null); } try { wr = new DataOutputStream(Connection.getOutputStream()); //open output stream to write } catch (IOException IOE) { JOptionPane.showMessageDialog(null, "Error -> " + IOE.getLocalizedMessage(), "Exception - IOException", JOptionPane.ERROR_MESSAGE, null); } try { wr.writeBytes("q=" + strData); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error -> " + ex.getLocalizedMessage(), "Exception - IOException", JOptionPane.ERROR_MESSAGE, null); } try { wr.flush(); //Force all data to write in channel } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error -> " + ex.getLocalizedMessage(), "Exception - IOException", JOptionPane.ERROR_MESSAGE, null); } try { //read the result from the server Buffered_Reader = new BufferedReader(new InputStreamReader(Connection.getInputStream())); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error -> " + ex.getLocalizedMessage(), "Exception - IOException", JOptionPane.ERROR_MESSAGE, null); } jsonParser = new JSONParser(); //JSON Parser try { JsonObject = (JSONObject) jsonParser.parse(Buffered_Reader); //Parse whole BuffererReader IN Object JSONArray Results_Array_Json = (JSONArray) JsonObject.get("results"); //take whole array - from json format //results - is as string unique that contains all the essential information such as arrays, and strings. So to extract all info we extract results into JSONarray //And this comes up due to json format for (int i = 0; i < Results_Array_Json.size(); i++) // Loop over each each part of array that contains info we must extract { JSONObject o = (JSONObject) Results_Array_Json.get(i); try { //We assume that for every POI exists for sure an address !!! thats why the code is not insida a try-catch Temp_Name = (String) o.get("name"); Temp_Address = (String) o.get("vicinity"); JSONObject Str_1 = (JSONObject) o.get("geometry"); //Geometry is object so extract geometry JSONArray Photo_1 = (JSONArray) o.get("photos"); JSONObject Photo_2 = (JSONObject) Photo_1.get(0); String Photo_Ref = (String) Photo_2.get("photo_reference"); JSONObject Str_2 = (JSONObject) Str_1.get("location"); Temp_X = (double) Str_2.get("lat"); Temp_Y = (double) Str_2.get("lng"); //In case some POI has no Rating try { //Inside try-catch block because may some POI has no rating Temp_Rating = (double) o.get("rating"); Point POI_Object = new Point(Temp_Name, Temp_Address, Photo_Ref, Temp_Rating, Temp_X, Temp_Y); POI_List.add(POI_Object); //Add POI in List to keep it } catch (Exception Er) { //JOptionPane.showMessageDialog ( null, "No rating for this POI " ) ; Point POI_Object_2 = new Point(Temp_Name, Temp_Address, Photo_Ref, 0.0, Temp_X, Temp_Y); POI_List.add(POI_Object_2); //Add POI in List to keep it } } catch (Exception E) { //JOptionPane.showMessageDialog ( this, "Error -> " + E.getLocalizedMessage ( ) + ", " + E.getMessage ( ) ) ; } o.clear(); } } catch (ParseException PE) { JOptionPane.showMessageDialog(this, "Error -> " + PE.getLocalizedMessage(), "Parse, inside while JSON ERROR", JOptionPane.ERROR_MESSAGE, null); } catch (IOException IOE) { JOptionPane.showMessageDialog(this, "Error -> " + IOE.getLocalizedMessage(), "IOExcpiton", JOptionPane.ERROR_MESSAGE, null); } if (POI_List.isEmpty()) { JOptionPane.showMessageDialog(this, "No Results"); } else { //Calculate Distance every POI from Longitude and latitude of User for (int k = 0; k < POI_List.size(); k++) { double D1 = Double.parseDouble(Latitude_TextField.getText()) - POI_List.get(k).Get_Distance_X(); double D2 = Double.parseDouble(Longitude_TextField.getText()) - POI_List.get(k).Get_Distance_Y(); double a = pow(sin(D1 / 2), 2) + cos(POI_List.get(k).Get_Distance_X()) * cos(Double.parseDouble(Latitude_TextField.getText())) * pow(sin(D2 / 2), 2); double c = 2 * atan2(sqrt(a), sqrt(1 - a)); double d = 70000 * c; // (where R is the radius of the Earth) in meters //add to list Distances_List.add(d); } //COPY array because Distances_List will be corrupted for (int g = 0; g < Distances_List.size(); g++) { Distances_List_2.add(Distances_List.get(g)); } for (int l = 0; l < Distances_List.size(); l++) { int Dou = Distances_List.indexOf(Collections.min(Distances_List)); //Take the min , but the result is the position that the min is been placed Number_Name N = new Number_Name(POI_List.get(Dou).Get_Name()); //Create an object with the name of POI in the min position in the POI_List Temp_List.add(N); Distances_List.set(Dou, 9999.99); //Make the number in the min position so large so be able to find the next min } String[] T = new String[Temp_List.size()]; //String array to holds all names of POIS that are going to be dispayled in ascending order //DISPLAY POI IN JLIST - Create String Array with Names in ascending order to create JList for (int h = 0; h < Temp_List.size(); h++) { T[h] = Temp_List.get(h).Get_Name(); } //System.out.println ( " Size T -> " + T.length ) ; //Make JList and put String names list = new JList(T); list.setForeground(Color.BLACK); list.setBackground(Color.GRAY); list.setBounds(550, 140, 400, 400); //list.setSelectionMode ( ListSelectionModel.SINGLE_SELECTION ) ; JScrollPane p = new JScrollPane(list); P.add(p); setContentPane(pane); //OK list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { String selected = list.getSelectedValue().toString(); System.out.println("Selected string" + selected); for (int n = 0; n < POI_List.size(); n++) { if (selected.equals(POI_List.get(n).Get_Name())) { try { //read the result from the server BufferedImage img = null; URL u = new URL( "https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=" + POI_List.get(n).Get_Photo_Ref() + "&key=" + API_KEY); Image image = ImageIO.read(u); IMAGE_LABEL.setText(""); IMAGE_LABEL.setIcon(new ImageIcon(image)); IMAGE_LABEL.setBounds(550, 310, 500, 200); //SOSOSOSOSOS pane.add(IMAGE_LABEL); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error -> " + ex.getLocalizedMessage(), "Exception - IOException", JOptionPane.ERROR_MESSAGE, null); } Distance_L.setBounds(550, 460, 350, 150); Distance_L.setText(""); Distance_L.setText( "Distance from the current location: " + Distances_List_2.get(n) + "m"); pane.add(Distance_L); Address_L.setBounds(550, 500, 350, 150); Address_L.setText(""); Address_L.setText("Address: " + POI_List.get(n).Get_Address()); pane.add(Address_L); Rating_L.setBounds(550, 540, 350, 150); Rating_L.setText(""); Rating_L.setText("Rating: " + POI_List.get(n).Get_Rating()); pane.add(Rating_L); } } } }); } //Else not empty }
From source file:org.apache.hadoop.hbase.regionserver.HLog.java
private Long getOldestOutstandingSeqNum() { return Collections.min(this.lastSeqWritten.values()); }
From source file:com.feilong.core.util.AggregateUtil.java
/** * <code>map</code>,keys,? value ?. * //from w ww . j a va2 s . co m * <h3>:</h3> * <blockquote> * * <pre class="code"> * Map{@code <String, Integer>} map = new HashMap{@code <String, Integer>}(); * * map.put("a", 3007); * map.put("b", 3001); * map.put("c", 3002); * map.put("d", 3003); * map.put("e", 3004); * map.put("f", 3005); * map.put("g", -1005); * * LOGGER.info("" + AggregateUtil.getMinValue(map, "a", "b", "d", "g", "m")); * </pre> * * <b>:</b> * -1005 * * </blockquote> * * @param <K> * the key type * @param <T> * the generic type * @param map * map * @param keys * key * @return <code>map</code> nullempty, null;<br> * <code>keys</code> nullempty,<code>map</code>value?<br> * key?map key?,mapkey,warn level log<br> * keys key ? map ,null * @see MapUtil#getSubMap(Map, Object...) * @see java.util.Collections#min(Collection) */ @SafeVarargs public static <K, T extends Number & Comparable<? super T>> T getMinValue(Map<K, T> map, K... keys) { Map<K, T> subMap = MapUtil.getSubMap(map, keys); return isNullOrEmpty(subMap) ? null : Collections.min(subMap.values()); //? Number Comparable? }
From source file:gr.iti.mklab.reveal.forensics.util.Util.java
public static float minDouble2DArray(float[][] arrayIn) { // Calculate the minimum value of a 2D float array float min = Float.MAX_VALUE; float colMin; for (float[] arrayInRow : arrayIn) { List b = Arrays.asList(ArrayUtils.toObject(arrayInRow)); colMin = (float) Collections.min(b); if (colMin < min) { min = colMin;/* ww w . j ava 2 s. com*/ } } return min; }