List of usage examples for java.lang Integer compare
public static int compare(int x, int y)
From source file:Main.java
public static void main(String[] args) { if (Integer.compare(1, 1) == 0) { System.out.println("Equals"); }/* ww w .ja v a 2 s .c o m*/ }
From source file:org.apache.druid.examples.rabbitmq.RabbitMQProducerMain.java
public static void main(String[] args) throws Exception { // We use a List to keep track of option insertion order. See below. final List<Option> optionList = new ArrayList<Option>(); optionList.add(OptionBuilder.withLongOpt("help").withDescription("display this help message").create("h")); optionList.add(OptionBuilder.withLongOpt("hostname").hasArg() .withDescription("the hostname of the AMQP broker [defaults to AMQP library default]").create("b")); optionList.add(OptionBuilder.withLongOpt("port").hasArg() .withDescription("the port of the AMQP broker [defaults to AMQP library default]").create("n")); optionList.add(OptionBuilder.withLongOpt("username").hasArg() .withDescription("username to connect to the AMQP broker [defaults to AMQP library default]") .create("u")); optionList.add(OptionBuilder.withLongOpt("password").hasArg() .withDescription("password to connect to the AMQP broker [defaults to AMQP library default]") .create("p")); optionList.add(OptionBuilder.withLongOpt("vhost").hasArg() .withDescription("name of virtual host on the AMQP broker [defaults to AMQP library default]") .create("v")); optionList.add(OptionBuilder.withLongOpt("exchange").isRequired().hasArg() .withDescription("name of the AMQP exchange [required - no default]").create("e")); optionList.add(OptionBuilder.withLongOpt("key").hasArg() .withDescription("the routing key to use when sending messages [default: 'default.routing.key']") .create("k")); optionList.add(OptionBuilder.withLongOpt("type").hasArg() .withDescription("the type of exchange to create [default: 'topic']").create("t")); optionList.add(OptionBuilder.withLongOpt("durable") .withDescription("if set, a durable exchange will be declared [default: not set]").create("d")); optionList.add(OptionBuilder.withLongOpt("autodelete") .withDescription("if set, an auto-delete exchange will be declared [default: not set]") .create("a")); optionList.add(OptionBuilder.withLongOpt("single") .withDescription("if set, only a single message will be sent [default: not set]").create("s")); optionList.add(OptionBuilder.withLongOpt("start").hasArg() .withDescription("time to use to start sending messages from [default: 2010-01-01T00:00:00]") .create());//from w w w . jav a 2 s . c om optionList.add(OptionBuilder.withLongOpt("stop").hasArg().withDescription( "time to use to send messages until (format: '2013-07-18T23:45:59') [default: current time]") .create()); optionList.add(OptionBuilder.withLongOpt("interval").hasArg() .withDescription("the interval to add to the timestamp between messages in seconds [default: 10]") .create()); optionList.add(OptionBuilder.withLongOpt("delay").hasArg() .withDescription("the delay between sending messages in milliseconds [default: 100]").create()); // An extremely silly hack to maintain the above order in the help formatting. HelpFormatter formatter = new HelpFormatter(); // Add a comparator to the HelpFormatter using the ArrayList above to sort by insertion order. //noinspection ComparatorCombinators -- don't replace with comparingInt() to preserve comments formatter.setOptionComparator((o1, o2) -> { // I know this isn't fast, but who cares! The list is short. //noinspection SuspiciousMethodCalls return Integer.compare(optionList.indexOf(o1), optionList.indexOf(o2)); }); // Now we can add all the options to an Options instance. This is dumb! Options options = new Options(); for (Option option : optionList) { options.addOption(option); } CommandLine cmd = null; try { cmd = new BasicParser().parse(options, args); } catch (ParseException e) { formatter.printHelp("RabbitMQProducerMain", e.getMessage(), options, null); System.exit(1); } if (cmd.hasOption("h")) { formatter.printHelp("RabbitMQProducerMain", options); System.exit(2); } ConnectionFactory factory = new ConnectionFactory(); if (cmd.hasOption("b")) { factory.setHost(cmd.getOptionValue("b")); } if (cmd.hasOption("u")) { factory.setUsername(cmd.getOptionValue("u")); } if (cmd.hasOption("p")) { factory.setPassword(cmd.getOptionValue("p")); } if (cmd.hasOption("v")) { factory.setVirtualHost(cmd.getOptionValue("v")); } if (cmd.hasOption("n")) { factory.setPort(Integer.parseInt(cmd.getOptionValue("n"))); } String exchange = cmd.getOptionValue("e"); String routingKey = "default.routing.key"; if (cmd.hasOption("k")) { routingKey = cmd.getOptionValue("k"); } boolean durable = cmd.hasOption("d"); boolean autoDelete = cmd.hasOption("a"); String type = cmd.getOptionValue("t", "topic"); boolean single = cmd.hasOption("single"); int interval = Integer.parseInt(cmd.getOptionValue("interval", "10")); int delay = Integer.parseInt(cmd.getOptionValue("delay", "100")); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH); Date stop = sdf.parse(cmd.getOptionValue("stop", sdf.format(new Date()))); Random r = ThreadLocalRandom.current(); Calendar timer = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ENGLISH); timer.setTime(sdf.parse(cmd.getOptionValue("start", "2010-01-01T00:00:00"))); String msg_template = "{\"utcdt\": \"%s\", \"wp\": %d, \"gender\": \"%s\", \"age\": %d}"; Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(exchange, type, durable, autoDelete, null); do { int wp = (10 + r.nextInt(90)) * 100; String gender = r.nextBoolean() ? "male" : "female"; int age = 20 + r.nextInt(70); String line = StringUtils.format(msg_template, sdf.format(timer.getTime()), wp, gender, age); channel.basicPublish(exchange, routingKey, null, StringUtils.toUtf8(line)); System.out.println("Sent message: " + line); timer.add(Calendar.SECOND, interval); Thread.sleep(delay); } while ((!single && stop.after(timer.getTime()))); connection.close(); }
From source file:amie.keys.CSAKey.java
public static void main(String[] args) throws IOException, InterruptedException { final Triple<MiningAssistant, Float, String> parsedArgs = parseArguments(args); final Set<Rule> output = new LinkedHashSet<>(); // Helper object that contains the implementation for the calculation // of confidence and support // The file with the non-keys, one per line long timea = System.currentTimeMillis(); List<List<String>> inputNonKeys = Utilities.parseNonKeysFile(parsedArgs.third); System.out.println(inputNonKeys.size() + " input non-keys"); final List<List<String>> nonKeys = pruneBySupport(inputNonKeys, parsedArgs.second, parsedArgs.first.getKb());/*from www . j a v a2 s.com*/ Collections.sort(nonKeys, new Comparator<List<String>>() { @Override public int compare(List<String> o1, List<String> o2) { int r = Integer.compare(o2.size(), o1.size()); if (r == 0) { return Integer.compare(o2.hashCode(), o1.hashCode()); } return r; } }); System.out.println(nonKeys.size() + " non-keys after pruning"); int totalLoad = computeLoad(nonKeys); System.out.println(totalLoad + " is the total load"); int nThreads = Runtime.getRuntime().availableProcessors(); //int batchSize = Math.max(Math.min(maxBatchSize, totalLoad / nThreads), minBatchSize); int batchSize = Math.max(Math.min(maxLoad, totalLoad / nThreads), minLoad); final Queue<int[]> chunks = new PriorityQueue(50, new Comparator<int[]>() { @Override public int compare(int[] o1, int[] o2) { return Integer.compare(o2[2], o1[2]); } }); final HashSet<HashSet<Integer>> nonKeysInt = new HashSet<>(); final HashMap<String, Integer> property2Id = new HashMap<>(); final HashMap<Integer, String> id2Property = new HashMap<>(); final List<Integer> propertiesList = new ArrayList<>(); int support = (int) parsedArgs.second.floatValue(); KB kb = parsedArgs.first.getKb(); buildDictionaries(nonKeys, nonKeysInt, property2Id, id2Property, propertiesList, support, kb); final List<HashSet<Integer>> nonKeysIntList = new ArrayList<>(nonKeysInt); int start = 0; int[] nextIdx = nextIndex(nonKeysIntList, 0, batchSize); int end = nextIdx[0]; int load = nextIdx[1]; while (start < nonKeysIntList.size()) { int[] chunk = new int[] { start, end, load }; chunks.add(chunk); start = end; nextIdx = nextIndex(nonKeysIntList, end, batchSize); end = nextIdx[0]; load = nextIdx[1]; } Thread[] threads = new Thread[Math.min(Runtime.getRuntime().availableProcessors(), chunks.size())]; for (int i = 0; i < threads.length; ++i) { threads[i] = new Thread(new Runnable() { @Override public void run() { while (true) { int[] chunk = null; synchronized (chunks) { if (!chunks.isEmpty()) { chunk = chunks.poll(); } else { break; } } System.out.println("Processing chunk " + Arrays.toString(chunk)); mine(parsedArgs, nonKeysIntList, property2Id, id2Property, propertiesList, chunk[0], chunk[1], output); } } }); threads[i].start(); } for (int i = 0; i < threads.length; ++i) { threads[i].join(); } long timeb = System.currentTimeMillis(); System.out.println("==== Unique C-keys ====="); for (Rule r : output) { System.out.println(Utilities.formatKey(r)); } System.out.println( "VICKEY found " + output.size() + " unique conditional keys in " + (timeb - timea) + " ms"); }
From source file:org.eclipse.swt.snippets.SnippetExplorer.java
/** * SnippetExplorer main method.//from w w w . j a va 2 s .c o m * * @param args does not parse any arguments */ public static void main(String[] args) throws Exception { final String os = System.getProperty("os.name"); multiDisplaySupport = (os != null && os.toLowerCase().contains("windows")); if (canRunCommand("java")) { javaCommand = "java"; } else { final String javaHome = System.getProperty("java.home"); if (javaHome != null) { final Path java = Paths.get(javaHome, "bin", "java"); java.normalize(); if (canRunCommand(java.toString())) { javaCommand = java.toString(); } } } snippets = loadSnippets(); snippets.sort((a, b) -> { int cmp = Integer.compare(a.snippetNum, b.snippetNum); if (cmp == 0) { cmp = a.snippetName.compareTo(b.snippetName); } return cmp; }); new SnippetExplorer().open(); }
From source file:Main.java
public static <T> List range(List<? extends T> list, T min, T max) { List<? super T> copyList = new ArrayList<>(list); Collections.sort(copyList, (o1, o2) -> Integer.compare(o1.hashCode(), o2.hashCode())); if (copyList.indexOf(min) < copyList.indexOf(max)) { return copyList.subList(copyList.indexOf(min), copyList.indexOf(max)); } else {/* www .j av a 2 s . c om*/ return newArrayList(); } }
From source file:Main.java
public static int hashCode(List list) { if (list == null) { return 0; }//from www .j a v a2s . c o m if (list.isEmpty()) { return 1; } ArrayList<?> tmp = new ArrayList<>(list); Collections.sort(tmp, (o1, o2) -> Integer.compare(o1.hashCode(), o2.hashCode())); return tmp.hashCode(); }
From source file:Main.java
/** * Returns the indices that would sort an array. * @param array Array./*from w ww.j a v a2 s . c o m*/ * @param ascending Ascending order. * @return Array of indices. */ public static int[] Argsort(final int[] array, final boolean ascending) { Integer[] indexes = new Integer[array.length]; for (int i = 0; i < indexes.length; i++) { indexes[i] = i; } Arrays.sort(indexes, new Comparator<Integer>() { @Override public int compare(final Integer i1, final Integer i2) { return (ascending ? 1 : -1) * Integer.compare(array[i1], array[i2]); } }); return asArray(indexes); }
From source file:Main.java
@Override public int compare(Flight f1, Flight f2) { return Integer.compare(f2.getPriority(), f1.getPriority()); }
From source file:io.fabric8.maven.core.util.VersionUtil.java
/** * Compares two version strings such that "1.10.1" > "1.4" etc *//* w w w . jav a 2 s . co m*/ public static int compareVersions(String v1, String v2) { String[] components1 = split(v1); String[] components2 = split(v2); int diff; int length = Math.min(components1.length, components2.length); for (int i = 0; i < length; i++) { String s1 = components1[i]; String s2 = components2[i]; Integer i1 = tryParseInteger(s1); Integer i2 = tryParseInteger(s2); if (i1 != null && i2 != null) { diff = i1.compareTo(i2); } else { // lets assume strings instead diff = s1.compareTo(s2); } if (diff != 0) { return diff; } } diff = Integer.compare(components1.length, components2.length); if (diff == 0) { if (v1 == v2) { return 0; } /* if v1 == null then v2 can't be null here (see 'if' above). So for v1 == null its always smaller than v2 */; return v1 != null ? v1.compareTo(v2) : -1; } return diff; }
From source file:bwem.util.PairGenericAltitudeComparator.java
@Override public int compare(MutablePair<T, Altitude> o1, MutablePair<T, Altitude> o2) { int a1 = o1.getRight().intValue(); int a2 = o2.getRight().intValue(); return Integer.compare(a1, a2); }