File: Util.java

package info (click to toggle)
libjaba-client-java 2.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 2,052 kB
  • sloc: java: 17,308; makefile: 12
file content (48 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package compbio.util;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Random;

/**
 * Utility methods
 * 
 * @author pvtroshin
 * 
 */
public class Util {

	public static final boolean isEmpty(String string) {
		return string == null || string.trim().length() == 0;
	}

	public static final SimpleDateFormat datef = new SimpleDateFormat(
			"HH:mm-dd/MM/yyyy");

	public static <K, V> HashMap<K, V> getNewHashMap() {
		return new HashMap<K, V>();
	}

	final static Random rand = new Random();

	/*
	 * Returns random integers with value in range from min to max
	 * @param min
	 * @param max
	 * @return
	 */
	public static int getRandomNumber(int start, int end) {
		if (start >= end) {
			throw new IllegalArgumentException("Start cannot exceed End.");
		}
		// get the range, casting to long to avoid overflow problems
		long range = (long) end - (long) start + 1;
		// compute a fraction of the range, 0 <= frac < range
		long fraction = (long) (range * rand.nextDouble());
		return (int) (fraction + start);
	}

	public static double getRandomNumber(double min, double max) {
		return (max - min) * rand.nextDouble() + min;
	}
}