List of usage examples for java.util Arrays sort
public static <T> void sort(T[] a, Comparator<? super T> c)
From source file:jetbrains.exodus.io.FileDataReader.java
public static void sortBlocks(Block[] result) { Arrays.sort(result, new Comparator<Block>() { @Override//from w ww . j a v a 2s.c o m public int compare(Block o1, Block o2) { if (o1.getAddress() < o2.getAddress()) { return -1; } if (o1.getAddress() > o2.getAddress()) { return 1; } return 0; } }); }
From source file:gemlite.shell.commands.admin.Monitor.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @CliCommand(value = "list services", help = "list services") public String services() { Set<ObjectInstance> names = jmxSrv.listMBeans(); List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); if (names == null) return "no services"; Object[] a = names.toArray(); //???/*from www . j a v a2 s .c om*/ Arrays.sort(a, (Comparator) new Comparator<ObjectInstance>() { @Override public int compare(ObjectInstance o1, ObjectInstance o2) { return (o1.getObjectName().toString()).compareTo(o2.getObjectName().toString()); } }); if (LogUtil.getCoreLog().isDebugEnabled()) LogUtil.getCoreLog().debug("get names size:{} values:{}", names.size(), names.toString()); //?service? for (int i = 0; i < a.length; i++) { ObjectInstance oi = (ObjectInstance) a[i]; // service?,??? HashMap<String, Object> service = new HashMap<String, Object>(); service.put(oi.getObjectName().toString(), service); service.put("serviceName", service); try { Map<String, Object> map = jmxSrv.getAttributesValues(oi.getObjectName().toString()); if (map.size() <= 0) { map.put("serviceName", oi.getObjectName().toString()); LogUtil.getCoreLog().warn("jmxSrv.getAttributesValues is null ,ObjectName {}", oi.getObjectName().toString()); result.add(map); } else { result.add(map); } } catch (Exception e) { LogUtil.getCoreLog().error("jmxSrv.getAttributesValues is null ,ObjectName {},error:{}", oi.getObjectName().toString(), e); } } LinkedHashMap<String, HashMap<String, Object>> rs = (LinkedHashMap<String, HashMap<String, Object>>) get( CommandMeta.LIST_SERVICES); if (rs == null) rs = new LinkedHashMap<String, HashMap<String, Object>>(); for (Map<String, Object> map : result) { // ? HashMap<String, Object> service = rs.get(map.get("serviceName")); if (service == null) { service = new HashMap<String, Object>(); } service.putAll(map); // ? rs.put((String) map.get("serviceName"), service); } // ws?? put(CommandMeta.LIST_SERVICES, rs); if (!result.isEmpty()) return result.toString(); return "no services"; }
From source file:de.alpharogroup.io.annotations.ImportResourcesExtensions.java
/** * Gets a {@link Map} with {@link ImportResource} objects and the corresponding to the found * class from the given package Name. The search is made recursive. The key from an entry of the * map is the class where the {@link ImportResource} objects found and the value is an Array of * the {@link ImportResource} objects that contains in the class. * * @param packageName/*w w w. j a va 2s . c o m*/ * the package name * @return the import resources * @throws ClassNotFoundException * occurs if a given class cannot be located by the specified class loader * @throws IOException * Signals that an I/O exception has occurred. */ public static Map<Class<?>, ImportResource[]> getImportResources(final String packageName) throws ClassNotFoundException, IOException { final Map<Class<?>, ImportResource[]> resourcesMap = new LinkedHashMap<>(); final Class<ImportResources> importResourcesClass = ImportResources.class; final Class<ImportResource> importResourceClass = ImportResource.class; final Set<Class<?>> importResourcesClasses = AnnotationExtensions.getAllAnnotatedClasses(packageName, importResourcesClass); final Set<Class<?>> importResourceClasses = AnnotationExtensions.getAllAnnotatedClasses(packageName, importResourceClass); importResourcesClasses.addAll(importResourceClasses); for (final Class<?> annotatedClass : importResourcesClasses) { final ImportResources importResources = annotatedClass.getAnnotation(ImportResources.class); ImportResource[] importResourcesArray = null; ImportResource[] importResourceArray = null; if (importResources != null) { importResourcesArray = importResources.resources(); } final ImportResource importResource = annotatedClass.getAnnotation(ImportResource.class); if (importResource != null) { importResourceArray = new ImportResource[1]; importResourceArray[0] = importResource; } final ImportResource[] array = (ImportResource[]) ArrayUtils.addAll(importResourceArray, importResourcesArray); Arrays.sort(array, new ImportResourceComparator()); resourcesMap.put(annotatedClass, array); } return resourcesMap; }
From source file:de.tuberlin.uebb.jdae.llmsl.Block.java
public Block(double[][] data, DataLayout layout, Set<GlobalVariable> variables, Set<DerivedEquation> equations, SimulationOptions options) {//from w ww .j av a 2 s . c om this.options = options; this.variables = variables.toArray(new GlobalVariable[variables.size()]); Arrays.sort(this.variables, Ordering.natural()); this.view = new ExecutionContext(0, this.variables, data); final Map<Integer, Integer> gvIndex = Maps.newTreeMap(); for (int i = 0; i < this.variables.length; i++) { if (!gvIndex.containsKey(this.variables[i].index)) gvIndex.put(this.variables[i].index, i); } final Map<GlobalVariable, BlockVariable> blockVars = makeBlockVars(layout, equations, gvIndex); this.views = new ExecutionContext[equations.size()]; this.equations = new Residual[equations.size()]; this.residuals = new TDNumber[equations.size()]; int index = 0; for (DerivedEquation e : equations) { this.equations[index] = new Residual(e.eqn.bind(blockVars), e.minOrder, e.maxOrder); views[index++] = view.derived(e.maxOrder); } jacobianMatrix = new DenseMatrix64F(this.variables.length, this.variables.length); residual = new DenseMatrix64F(this.variables.length, 1); x = new DenseMatrix64F(this.variables.length); solver = LinearSolverFactory.linear(this.variables.length); this.point = new double[this.variables.length]; }
From source file:info.servertools.core.util.FileUtils.java
/** * Retrieve the oldest file in a directory * * @param directory/* www. j a v a 2s. co m*/ * the directory to check * * @return the oldest file */ public static File getOldestFile(File directory) { File[] files = directory.listFiles((FileFilter) FileFileFilter.FILE); Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); return files.length > 0 ? files[0] : null; }
From source file:azkaban.flow.GroupedExecutableFlow.java
public GroupedExecutableFlow(String id, ExecutableFlow... flows) { this.id = id; this.flows = flows; this.sortedFlows = Arrays.copyOf(this.flows, this.flows.length); Arrays.sort(this.sortedFlows, new Comparator<ExecutableFlow>() { @Override/*from www. j a v a 2s.c o m*/ public int compare(ExecutableFlow o1, ExecutableFlow o2) { return o1.getName().compareTo(o2.getName()); } }); String[] names = new String[flows.length]; for (int i = 0; i < flows.length; i++) { names[i] = flows[i].getName(); } name = StringUtils.join(names, " + "); jobState = Status.READY; updateState(); callbacksToCall = new ArrayList<FlowCallback>(); theGroupCallback = new GroupedFlowCallback(); switch (jobState) { case SUCCEEDED: case COMPLETED: case FAILED: DateTime theStartTime = new DateTime(); DateTime theEndTime = new DateTime(0); for (ExecutableFlow flow : flows) { final DateTime subFlowStartTime = flow.getStartTime(); if (theStartTime.isAfter(subFlowStartTime)) { theStartTime = subFlowStartTime; } final DateTime subFlowEndTime = flow.getEndTime(); if (subFlowEndTime != null && subFlowEndTime.isAfter(theEndTime)) { theEndTime = subFlowEndTime; } } setAndVerifyParentProps(); startTime = theStartTime; endTime = theEndTime; break; default: // Check for Flows that are "RUNNING" boolean allRunning = true; List<ExecutableFlow> runningFlows = new ArrayList<ExecutableFlow>(); DateTime thisStartTime = null; for (ExecutableFlow flow : flows) { if (flow.getStatus() != Status.RUNNING) { allRunning = false; final DateTime subFlowStartTime = flow.getStartTime(); if (subFlowStartTime != null && subFlowStartTime.isBefore(thisStartTime)) { thisStartTime = subFlowStartTime; } } else { runningFlows.add(flow); } } if (allRunning) { jobState = Status.RUNNING; } for (ExecutableFlow runningFlow : runningFlows) { final DateTime subFlowStartTime = runningFlow.getStartTime(); if (subFlowStartTime != null && subFlowStartTime.isBefore(thisStartTime)) { thisStartTime = subFlowStartTime; } } setAndVerifyParentProps(); startTime = thisStartTime; endTime = null; // Make sure everything is initialized before leaking the pointer to "this". // This is just installing the callback in an already running flow. for (ExecutableFlow runningFlow : runningFlows) { runningFlow.execute(parentProps, theGroupCallback); } } }
From source file:com.linkedin.pinot.core.indexsegment.utils.MmapMemoryManagerTest.java
@Test public void testLargeBlocks() throws Exception { final String segmentName = "someSegment"; PinotDataBufferMemoryManager memoryManager = new MmapMemoryManager(_tmpDir, segmentName); final long s1 = 2 * MmapMemoryManager.getDefaultFileLength(); final long s2 = 1000; final String col1 = "col1"; final String col2 = "col2"; final byte value = 34; PinotDataBuffer buf1 = memoryManager.allocate(s1, col1); // Verify that we can write to and read from the buffer ByteBuffer b1 = buf1.toDirectByteBuffer(0, (int) s1); b1.putLong(0, s1);/*from w w w . j ava 2 s. co m*/ Assert.assertEquals(b1.getLong(0), s1); b1.put((int) s1 - 1, value); Assert.assertEquals(b1.get((int) s1 - 1), value); PinotDataBuffer buf2 = memoryManager.allocate(s2, col2); ByteBuffer b2 = buf2.toDirectByteBuffer(0, (int) s2); b2.putLong(0, s2); Assert.assertEquals(b2.getLong(0), s2); File dir = new File(_tmpDir); File[] files = dir.listFiles(); Assert.assertEquals(files.length, 2); Arrays.sort(files, new Comparator<File>() { @Override public int compare(File o1, File o2) { return o1.getName().compareTo(o2.getName()); } }); String fileName = files[0].getName(); Assert.assertTrue(fileName.contains(segmentName)); fileName = files[1].getName(); Assert.assertTrue(fileName.contains(segmentName)); buf1.close(); buf2.close(); memoryManager.close(); List<Pair<MmapUtils.AllocationContext, Integer>> allocationContexts = MmapUtils.getAllocationsAndSizes(); Assert.assertEquals(allocationContexts.size(), 0); Assert.assertEquals(new File(_tmpDir).listFiles().length, 0); }
From source file:com.acceleratedio.pac_n_zoom.FindTagsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_find_tags); req_str = getIntent().getExtras().getString("requestString"); fil_tags = getIntent().getExtras().getString("tagString").split("(\\s*,\\s*)|(\\s* \\s*)"); Arrays.sort(fil_tags, String.CASE_INSENSITIVE_ORDER); dsply_tags();//from w w w . j ava 2s. c o m tgTxtBar = (EditText) findViewById(R.id.ed_tgs); tgTxtBar.setOnClickListener(this); tgTxtBar.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence key_sqnc, int start, int before, int count) { final StringBuilder strBldr = new StringBuilder(key_sqnc.length()); strBldr.append(key_sqnc); srch_str = strBldr.toString(); dsply_tags(); } @Override public void afterTextChanged(Editable s) { } }); }
From source file:de.tudarmstadt.lt.n2n.utilities.PatternGenerator.java
public static int[][] comb(int k, int n, int[] fixed, boolean sort) { int[][] s = new int[0][]; for (int u = 0; u < 1 << n; u++) if (bitcount(u) == k) { int[] c = bitadd(u, k); boolean add = true; for (int f : fixed) add &= !ArrayUtils.contains(c, f); if (add) s = (int[][]) ArrayUtils.add(s, c); }/*from www. j a v a 2s . c om*/ if (sort) Arrays.sort(s, new Comparator<int[]>() { @Override public int compare(int[] o1, int[] o2) { for (int i = 0; i < o1.length; i++) { int r = o2[i] - o1[i]; if (r != 0) return r; } return 0; } }); return s; }
From source file:com.rapidminer.operator.learner.tree.SelectionCreator.java
/** * Creates an example index start selection for each numerical attribute, or if there is none, * only one.//www. j a v a2s . c o m * * @return a map containing for each numerical attribute an example index array such that the * associated attribute values are in ascending order. */ public Map<Integer, int[]> getStartSelection() { Map<Integer, int[]> selection = new HashMap<>(); if (columnTable.getNumberOfRegularNumericalAttributes() == 0) { selection.put(0, createFullArray(columnTable.getNumberOfExamples())); } else { Integer[] bigSelectionArray = createFullBigArray(columnTable.getNumberOfExamples()); for (int j = columnTable.getNumberOfRegularNominalAttributes(); j < columnTable .getTotalNumberOfRegularAttributes(); j++) { final double[] attributeColumn = columnTable.getNumericalAttributeColumn(j); Integer[] startSelection = Arrays.copyOf(bigSelectionArray, bigSelectionArray.length); Arrays.sort(startSelection, new Comparator<Integer>() { @Override public int compare(Integer a, Integer b) { return Double.compare(attributeColumn[a], attributeColumn[b]); } }); selection.put(j, ArrayUtils.toPrimitive(startSelection)); } } return selection; }