List of usage examples for java.lang Math abs
@HotSpotIntrinsicCandidate public static double abs(double a)
From source file:Main.java
/** * Returns the smallest angle between two angles. * * @param alpha First angle in degrees//from w w w.j av a 2 s. c o m * @param beta Second angle in degrees * @return Smallest angle between two angles. */ public static double differenceBetweenAngles(double alpha, double beta) { double phi = Math.abs(beta - alpha) % 360; return phi > 180 ? 360 - phi : phi; }
From source file:Main.java
public static int days(String day1, String day2, String format) { DateFormat df = new SimpleDateFormat(format); long days = 0; try {/*from w w w . ja v a 2s.co m*/ Date d1 = df.parse(day1); Date d2 = df.parse(day2); long diff = Math.abs(d1.getTime() - d2.getTime()); days = diff / (1000 * 60 * 60 * 24); } catch (Exception e) { } return (int) days; }
From source file:Main.java
public static int getDiffOfYears(Date starDate, Date endDate) { Calendar star = Calendar.getInstance(); star.setTime(starDate);/*from w ww . j a v a 2s . c om*/ Calendar end = Calendar.getInstance(); end.setTime(endDate); int diffYear = star.get(Calendar.YEAR) - end.get(Calendar.YEAR); return Math.abs(diffYear); }
From source file:Main.java
public static long getDiffOfMillis(Date starDate, Date endDate) { Calendar star = Calendar.getInstance(); star.setTime(starDate);/*from w w w . j av a 2s. c o m*/ Calendar end = Calendar.getInstance(); end.setTime(endDate); long diff = star.getTimeInMillis() - end.getTimeInMillis(); long diffMillis = (Math.abs(diff)); return diffMillis; }
From source file:Main.java
public static String shortenString(String string, int targetLength, int maxDeviation) { targetLength = Math.abs(targetLength); maxDeviation = Math.abs(maxDeviation); if (string == null || string.length() <= targetLength + maxDeviation) { return string; }// www . j av a 2s .c o m int currentDeviation = 0; while (currentDeviation <= maxDeviation) { try { if (string.charAt(targetLength) == ' ') { return string.substring(0, targetLength) + " ..."; } if (string.charAt(targetLength + currentDeviation) == ' ') { return string.substring(0, targetLength + currentDeviation) + " ..."; } if (string.charAt(targetLength - currentDeviation) == ' ') { return string.substring(0, targetLength - currentDeviation) + " ..."; } } catch (Exception e) { //just in case } currentDeviation++; } return string.substring(0, targetLength) + " ..."; }
From source file:Main.java
public static Collection<Integer> seq(int start, int stop) { List<Integer> l = new ArrayList<Integer>(Math.abs(stop - start)); for (int i = Math.min(start, stop); i <= Math.max(start, stop); i++) { l.add(i);//from www.j a va 2 s. co m } if (stop < start) Collections.reverse(l); return l; }
From source file:Main.java
public static Size determineTargetPictureSize(Camera.Parameters params, int desiredResolution) { List<Size> sizes = params.getSupportedPictureSizes(); Size targetSize = sizes.get(0);/*from w w w. j a v a 2 s .c om*/ int delta = Integer.MAX_VALUE; for (Size size : sizes) { int diff = Math.abs(desiredResolution - pixelCount(size)); if (diff < delta) { targetSize = size; delta = diff; } } return targetSize; }
From source file:Main.java
/** * Check if a position is within a circle * * @param x x position//from w w w. ja v a2s . co m * @param y y position * @param centerX center x of circle * @param centerY center y of circle * @return true if within circle, false otherwise */ static boolean isInCircle(float x, float y, float centerX, float centerY, float radius) { return Math.abs(x - centerX) < radius && Math.abs(y - centerY) < radius; }
From source file:Main.java
/**Calculates the estimated distance between the access point based on frequency and signal strength in db. * Based on the Free-space path loss equation at http://en.wikipedia.org/wiki/FSPL * //from w w w . j av a 2 s .c o m * @param levelInDb * @param freqInMHz * @return */ public static double calculateDistance(double levelInDb, double freqInMHz) { double exp = (27.55 - (20 * Math.log10(freqInMHz)) + Math.abs(levelInDb)) / 20.0; return Math.pow(10.0, exp); }
From source file:Main.java
/** * This method used to get difference from minute. * /* w w w. java 2 s . c o m*/ * @param miliseconds * represented {@link Long} milliseconds * @return represented {@link Long} */ public static long getDfferenceInMinute(long miliseconds) { long diff = (Calendar.getInstance().getTimeInMillis() - miliseconds); diff = diff / 60000L; return Math.abs(diff); }