本文整理汇总了Java中java.util.Arrays.sort方法的典型用法代码示例。如果您正苦于以下问题:Java Arrays.sort方法的具体用法?Java Arrays.sort怎么用?Java Arrays.sort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Arrays
的用法示例。
在下文中一共展示了Arrays.sort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SerializablePrincipal
import java.util.Arrays; //导入方法依赖的package包/类
/**
* Construct a new Principal, associated with the specified Realm, for the
* specified username and password, with the specified role names (as
* Strings).
*
* @param name
* The username of the user represented by this Principal
* @param password
* Credentials used to authenticate this user
* @param roles
* List of roles (must be Strings) possessed by this user
* @param userPrincipal
* The user principal to be exposed to applications
*/
public SerializablePrincipal(String name, String password, List<String> roles, Principal userPrincipal) {
super();
this.name = name;
this.password = password;
if (roles != null) {
this.roles = new String[roles.size()];
this.roles = roles.toArray(this.roles);
if (this.roles.length > 1)
Arrays.sort(this.roles);
}
if (userPrincipal instanceof Serializable) {
this.userPrincipal = userPrincipal;
}
}
示例2: doTestSetTextNonContiguous
import java.util.Arrays; //导入方法依赖的package包/类
public void doTestSetTextNonContiguous() {
System.err.println("testSetTextNonContiguous");
String[] names = new String [5];
int[] indices = new int[] {22,11,15,8,3};
for (int i=0; i < names.length; i++) {
names[i] = mdl.getTab(indices[i]).getText();
}
noEvent = true;
//should produce no event since the names haven't changed
mdl.setText(indices, names);
noEvent = false;
String[] s = new String[names.length];
for (int i=0; i < s.length; i++) {
s[i] = names[i] + "modified";
}
mdl.setText(indices, s);
for (int i=0; i < s.length; i++) {
assertText(s[i], indices[i]);
}
Arrays.sort (indices);
assertEventIndices(indices);
assertListenerCall("contentsChanged");
assertWidthChanged();
//restore the original text
mdl.setText(indices, names);
}
示例3: sortRowWhite
import java.util.Arrays; //导入方法依赖的package包/类
static int[] sortRowWhite(int[] pixels, int currentRow, int width) {
int y = currentRow;
int x = 0;
int xe = 0;
while (xe < width - 1) {
x = White.getFirstNotWhiteX(pixels, x, y, width);
xe = White.getNextWhiteX(pixels, x, y, width);
if (x < 0) {
break;
}
int sortedLength = xe - x;
int[] sorted = new int[sortedLength];
for (int i = 0; i < sortedLength; i++) {
sorted[i] = pixels[x + i + y * width];
}
Arrays.sort(sorted);
for (int i = 0; i < sortedLength; i++) {
pixels[x + i + y * width] = sorted[i];
}
x = xe + 1;
}
return pixels;
}
示例4: retainAll
import java.util.Arrays; //导入方法依赖的package包/类
/** {@inheritDoc} */
public boolean retainAll( int[] array ) {
boolean changed = false;
Arrays.sort( array );
int[] set = _set;
byte[] states = _states;
_autoCompactTemporaryDisable = true;
for ( int i = set.length; i-- > 0; ) {
if ( states[i] == FULL && ( Arrays.binarySearch( array, set[i] ) < 0) ) {
removeAt( i );
changed = true;
}
}
_autoCompactTemporaryDisable = false;
return changed;
}
示例5: sortConstructors
import java.util.Arrays; //导入方法依赖的package包/类
/**
* Sort the given constructors, preferring public constructors and "greedy" ones with
* a maximum number of arguments. The result will contain public constructors first,
* with decreasing number of arguments, then non-public constructors, again with
* decreasing number of arguments.
* @param constructors the constructor array to sort
*/
public static void sortConstructors(Constructor<?>[] constructors) {
Arrays.sort(constructors, new Comparator<Constructor<?>>() {
@Override
public int compare(Constructor<?> c1, Constructor<?> c2) {
boolean p1 = Modifier.isPublic(c1.getModifiers());
boolean p2 = Modifier.isPublic(c2.getModifiers());
if (p1 != p2) {
return (p1 ? -1 : 1);
}
int c1pl = c1.getParameterTypes().length;
int c2pl = c2.getParameterTypes().length;
return (new Integer(c1pl)).compareTo(c2pl) * -1;
}
});
}
示例6: toArray
import java.util.Arrays; //导入方法依赖的package包/类
@Test
public void toArray() throws Exception {
TreeMap<CartesianPoint, String> map = new TreeMap<>(TreeMap.Space2D);
for (int i = 0; i < 50; i++) {
map.put(new CartesianPoint(i, i), Integer.toString(i * i));
}
Object[] objects = map.values().toArray();
Arrays.sort(objects);
for (int i = 0; i < 50; i++) {
assertTrue(Arrays.binarySearch(objects, Integer.toString(i * i)) >= 0);
}
}
示例7: checkRange
import java.util.Arrays; //导入方法依赖的package包/类
private static void checkRange(int[] a, int m) {
try {
Arrays.sort(a, m + 1, m);
failed("Sort does not throw IllegalArgumentException " +
" as expected: fromIndex = " + (m + 1) +
" toIndex = " + m);
}
catch (IllegalArgumentException iae) {
try {
Arrays.sort(a, -m, a.length);
failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: fromIndex = " + (-m));
}
catch (ArrayIndexOutOfBoundsException aoe) {
try {
Arrays.sort(a, 0, a.length + m);
failed("Sort does not throw ArrayIndexOutOfBoundsException " +
" as expected: toIndex = " + (a.length + m));
}
catch (ArrayIndexOutOfBoundsException aie) {
return;
}
}
}
}
示例8: sortStringArray
import java.util.Arrays; //导入方法依赖的package包/类
/**
* Turn given source {@code String} array into sorted array.
* @param array the source array
* @return the sorted array (never {@code null})
*/
public static String[] sortStringArray(String[] array) {
if (ObjectUtils.isEmpty(array)) {
return new String[0];
}
Arrays.sort(array);
return array;
}
示例9: commandLineRunner
import java.util.Arrays; //导入方法依赖的package包/类
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:\n");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
System.out.println("---");
};
}
示例10: maybeSort
import java.util.Arrays; //导入方法依赖的package包/类
/** Clone and sort the array, if not already sorted. */
private static
int[] maybeSort(int[] values) {
if (!isSorted(values, 0, false)) {
values = values.clone();
Arrays.sort(values);
}
return values;
}
示例11: arraysSortNoComparator
import java.util.Arrays; //导入方法依赖的package包/类
@Benchmark int arraysSortNoComparator(int reps) {
int tmp = 0;
for (int i = 0; i < reps; i++) {
Integer[] copy = inputArrays[i & 0xFF].clone();
Arrays.sort(copy);
tmp += copy[0];
}
return tmp;
}
示例12: testDescendingToArray
import java.util.Arrays; //导入方法依赖的package包/类
/**
* toArray contains all elements
*/
public void testDescendingToArray() {
NavigableSet q = populatedSet(SIZE);
Object[] o = q.toArray();
Arrays.sort(o);
for (int i = 0; i < o.length; i++)
assertEquals(o[i], q.pollFirst());
}
示例13: remove
import java.util.Arrays; //导入方法依赖的package包/类
/**
* Removes the.
*
* @param maxFileCount
* the max file count
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private void remove(int maxFileCount) throws IOException {
File dir = new File(metricPath);
FilenameFilter promFileFilter = (f, s) -> s.endsWith(".prom");
File[] directoryListing = dir.listFiles(promFileFilter);
if (directoryListing != null) {
Arrays.sort(directoryListing);
for (int i = 0; i < directoryListing.length - maxFileCount; i++) {
directoryListing[i].delete();
}
} else {
throw new IOException("Directory not listable: " + metricPath);
}
}
示例14: sort
import java.util.Arrays; //导入方法依赖的package包/类
private void sort() {
for (int i = 0; i < vectorBuff.size(); i++)
data.add(vectorBuff.get(i));
buff = data.toArray();
Arrays.sort(buff);
vectorBuff.clear();
}
示例15: calculateMeanSigma
import java.util.Arrays; //导入方法依赖的package包/类
private HashMap<String, Tupel<Double, Double>> calculateMeanSigma(ExampleSet exampleSet) {
HashMap<String, Tupel<Double, Double>> attributeMeanSigmaMap = new HashMap<String, Tupel<Double, Double>>();
for (Attribute attribute : exampleSet.getAttributes()) {
if (attribute.isNumerical()) {
double values[] = new double[exampleSet.size()];
int i = 0;
for (Example example : exampleSet) {
values[i++] = example.getValue(attribute);
}
Arrays.sort(values);
int lowerQuart = (int) (((values.length + 1) * 0.25) - 1);
int upperQuart = (int) (((values.length + 1) * 0.75) - 1);
double iqSigma = (values[upperQuart] - values[lowerQuart]) / 1.349;
double median = 0;
if (0 == (exampleSet.size() % 2)) {
if (exampleSet.size() > 1) {
median = (values[exampleSet.size() / 2] + values[(exampleSet.size() / 2) - 1]) / 2;
}
} else {
median = values[exampleSet.size() / 2];
}
attributeMeanSigmaMap.put(attribute.getName(), new Tupel<Double, Double>(median, iqSigma));
}
}
return attributeMeanSigmaMap;
}