List of usage examples for java.util Arrays sort
public static void sort(Object[] a)
From source file:generators.ExpressionMetaValidator.java
public static void main(String[] args) { ClassicEngineBoot.getInstance().start(); int invalidExpressionsCounter = 0; int deprecatedExpressionsCounter = 0; final HashNMap expressionsByGroup = new HashNMap(); ExpressionRegistry expressionRegistry = ExpressionRegistry.getInstance(); final ExpressionMetaData[] allExpressions = expressionRegistry.getAllExpressionMetaDatas(); for (int i = 0; i < allExpressions.length; i++) { final ExpressionMetaData expression = allExpressions[i]; if (expression == null) { logger.warn("Null Expression encountered"); continue; }//from w w w.j av a 2 s. com missingProperties.clear(); final Class type = expression.getExpressionType(); if (type == null) { logger.warn("Expression class is null"); } logger.debug("Processing " + type); final Class resultType = expression.getResultType(); if (resultType == null) { logger.warn("Expression '" + expression.getExpressionType() + " is null"); } try { final BeanInfo beanInfo = expression.getBeanDescriptor(); if (beanInfo == null) { logger.warn( "Expression '" + expression.getExpressionType() + ": Cannot get BeanDescriptor: Null"); } } catch (IntrospectionException e) { logger.warn("Expression '" + expression.getExpressionType() + ": Cannot get BeanDescriptor", e); } final Locale locale = Locale.getDefault(); final String displayName = expression.getDisplayName(locale); if (isValid(displayName, expression.getName()) == false) { logger.warn("Expression '" + expression.getExpressionType() + ": No valid display name"); } if (expression.isDeprecated()) { deprecatedExpressionsCounter += 1; final String deprecateMessage = expression.getDeprecationMessage(locale); if (isValid(deprecateMessage, "Use a Formula instead") == false) { logger.warn("Expression '" + expression.getExpressionType() + ": No valid deprecate message"); } } final String grouping = expression.getGrouping(locale); if (isValid(grouping, "Group") == false) { logger.warn("Expression '" + expression.getExpressionType() + ": No valid grouping message"); } expressionsByGroup.add(grouping, expression); final ExpressionPropertyMetaData[] properties = expression.getPropertyDescriptions(); for (int j = 0; j < properties.length; j++) { final ExpressionPropertyMetaData propertyMetaData = properties[j]; final String name = propertyMetaData.getName(); if (StringUtils.isEmpty(name)) { logger.warn("Expression '" + expression.getExpressionType() + ": Property without a name"); } final String propertyDisplayName = propertyMetaData.getDisplayName(locale); if (isValid(propertyDisplayName, name) == false) { logger.warn("Expression '" + expression.getExpressionType() + ": Property " + propertyMetaData.getName() + ": No DisplayName"); } final String propertyGrouping = propertyMetaData.getGrouping(locale); if (isValid(propertyGrouping, "Group") == false) { logger.warn("Expression '" + expression.getExpressionType() + ": Property " + propertyMetaData.getName() + ": Grouping is not valid"); } final int groupingOrdinal = propertyMetaData.getGroupingOrdinal(locale); if (groupingOrdinal == Integer.MAX_VALUE) { if (propertyMetaData instanceof DefaultExpressionMetaData) { final DefaultExpressionPropertyMetaData demd = (DefaultExpressionPropertyMetaData) propertyMetaData; missingProperties.add(demd.getKeyPrefix() + "grouping.ordinal=1000"); } logger.warn("Expression '" + expression.getExpressionType() + ": Property " + propertyMetaData.getName() + ": Grouping ordinal is not valid"); } final int ordinal = propertyMetaData.getItemOrdinal(locale); if (groupingOrdinal == Integer.MAX_VALUE) { if (propertyMetaData instanceof DefaultExpressionMetaData) { final DefaultExpressionPropertyMetaData demd = (DefaultExpressionPropertyMetaData) propertyMetaData; missingProperties.add(demd.getKeyPrefix() + "ordinal=1000"); } logger.warn("Expression '" + expression.getExpressionType() + ": Property " + propertyMetaData.getName() + ": Ordinal is not valid"); } final String propertyDescription = propertyMetaData.getDescription(locale); if (isValid(propertyDescription, "") == false) { logger.warn("Expression '" + expression.getExpressionType() + ": Property " + propertyMetaData.getName() + ": Description is not valid"); } final String propertyDeprecated = propertyMetaData.getDeprecationMessage(locale); if (isValid(propertyDeprecated, "") == false) { logger.warn("Expression '" + expression.getExpressionType() + ": Property " + propertyMetaData.getName() + ": Deprecation is not valid"); } final String role = propertyMetaData.getPropertyRole(); if (isValid(role, "Value") == false) { logger.warn("Expression '" + expression.getExpressionType() + ": Property " + propertyMetaData.getName() + ": Role is not valid"); } final Class propertyType = propertyMetaData.getPropertyType(); if (propertyType == null) { logger.warn("Expression '" + expression.getExpressionType() + ": Property " + propertyMetaData.getName() + ": Property Type is not valid"); } // should not crash! final PropertyDescriptor propertyDescriptor = propertyMetaData.getBeanDescriptor(); if (propertyMetaData.isDeprecated()) { final String deprecateMessage = propertyMetaData.getDeprecationMessage(locale); if (isValid(deprecateMessage, "Deprecated") == false) { logger.warn("Expression '" + expression.getExpressionType() + ": Property " + propertyMetaData.getName() + ": No valid deprecate message"); } } } try { final BeanInfo beanInfo = Introspector.getBeanInfo(expression.getExpressionType()); final PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors(); for (int propIdx = 0; propIdx < descriptors.length; propIdx++) { final PropertyDescriptor descriptor = descriptors[propIdx]; final String key = descriptor.getName(); if ("runtime".equals(key)) { continue; } if ("active".equals(key)) { continue; } if ("preserve".equals(key)) { continue; } if (descriptor.getReadMethod() == null || descriptor.getWriteMethod() == null) { continue; } if (expression.getPropertyDescription(key) == null) { logger.warn("Expression '" + expression.getExpressionType() + ": No property definition for " + key); missingPropertyDefs.add(" <property name=\"" + key + "\" mandatory=\"false\" preferred=\"false\" value-role=\"Value\" expert=\"false\" hidden=\"false\"/>"); } } } catch (Throwable e) { logger.warn("Expression '" + expression.getExpressionType() + ": Cannot get BeanDescriptor", e); } System.err.flush(); try { Thread.sleep(25); } catch (InterruptedException e) { } for (int x = 0; x < missingProperties.size(); x++) { final String property = (String) missingProperties.get(x); System.out.println(property); } for (int j = 0; j < missingPropertyDefs.size(); j++) { final String def = (String) missingPropertyDefs.get(j); System.out.println(def); } if (missingProperties.isEmpty() == false || missingPropertyDefs.isEmpty() == false) { invalidExpressionsCounter += 1; missingProperties.clear(); missingPropertyDefs.clear(); } System.out.flush(); try { Thread.sleep(25); } catch (InterruptedException e) { } } logger.info("Validated " + allExpressions.length + " expressions. Invalid: " + invalidExpressionsCounter + " Deprecated: " + deprecatedExpressionsCounter); final Object[] keys = expressionsByGroup.keySet().toArray(); Arrays.sort(keys); for (int i = 0; i < keys.length; i++) { final Object key = keys[i]; logger.info("Group: '" + key + "' Size: " + expressionsByGroup.getValueCount(key)); final Object[] objects = expressionsByGroup.toArray(key); for (int j = 0; j < objects.length; j++) { ExpressionMetaData metaData = (ExpressionMetaData) objects[j]; logger.info(" " + metaData.getExpressionType()); } } }
From source file:com.mycompany.monroelabsm.B58.java
public static String encode(byte[] toEncode, byte prefix) { //TODO:validate toEncode for correct size //TODO:implement an enum for this parameter instead. //validate prefix against known prefixes byte[] validPrefixes = { 0, //Bitcoin pubkey hash 5, //Bitcoin script hash 21, //Bitcoin (compact) public key (proposed) 52, //Namecoin pubkey hash -128, //Private key 111, //Bitcoin testnet pubkey hash -60, //Bitcoin testnet script hash -17 //Testnet Private key };//from ww w.j a v a 2 s . com Arrays.sort(validPrefixes); if (Arrays.binarySearch(validPrefixes, prefix) < 0) {//not found. see https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html return "Base58 error: Invalid address prefix byte specified."; } int size = 21; if (prefix == (byte) -128) { size = 33; } byte[] step1 = new byte[size]; step1[0] = prefix; for (int i = 1; i < size; i++) { step1[i] = toEncode[i - 1]; } byte[] step2 = new byte[4]; byte[] step2a = DigestUtils.sha256(DigestUtils.sha256(step1)); step2[0] = step2a[0]; step2[1] = step2a[1]; step2[2] = step2a[2]; step2[3] = step2a[3]; byte[] step3 = new byte[size + 4]; for (int i = 0; i < size; i++) { step3[i] = step1[i]; } step3[size] = step2[0]; step3[size + 1] = step2[1]; step3[size + 2] = step2[2]; step3[size + 3] = step2[3]; String output = Base58.encode(step3); return output; }
From source file:com.l2jfree.gameserver.model.skills.conditions.ConditionPlayerInstanceId.java
public ConditionPlayerInstanceId(List<Integer> instanceIds) { _instanceIds = ArrayUtils.toPrimitive(instanceIds.toArray(new Integer[instanceIds.size()]), 0); Arrays.sort(_instanceIds); }
From source file:azkaban.utils.PropsUtils.java
/** * Load job schedules from the given directories * * @param parent The parent properties for these properties * @param dir The directory to look in//from ww w . jav a2 s. co m * @param suffixes File suffixes to load * @return The loaded set of schedules */ public static Props loadPropsInDir(Props parent, File dir, String... suffixes) { try { Props props = new Props(parent); File[] files = dir.listFiles(); Arrays.sort(files); if (files != null) { for (File f : files) { if (f.isFile() && endsWith(f, suffixes)) { props.putAll(new Props(null, f.getAbsolutePath())); } } } return props; } catch (IOException e) { throw new RuntimeException("Error loading properties.", e); } }
From source file:arena.validation.EnumerationValidation.java
public ValidationFailure validate(Object value) { String enumeration[] = (String[]) getExtraInfo(); Arrays.sort(enumeration); log.debug("Validating enum: " + value + " enum=" + enumeration + " size=" + enumeration.length); if ((value == null) || value.equals("")) { return null; // check elsewhere }/*from w w w . ja v a 2 s .c o m*/ // Note enums are always arrays of strings else { for (String item : enumeration) { if (item.equals("" + value)) { return null; } } return new ValidationFailure(getFieldName(), Validation.ENUMERATION, value, enumeration); } }
From source file:hudson.init.InitScriptsExecutor.java
@Initializer(after = JOB_LOADED) public static void init(Hudson hudson) throws IOException { URL bundledInitScript = hudson.servletContext.getResource("/WEB-INF/init.groovy"); if (bundledInitScript != null) { logger.info("Executing bundled init script: " + bundledInitScript); InputStream in = bundledInitScript.openStream(); try {/*from w ww. ja v a2s .c om*/ String script = IOUtils.toString(in); logger.info(new Script(script).execute()); } finally { IOUtils.closeQuietly(in); } } File initScript = new File(hudson.getRootDir(), "init.groovy"); if (initScript.exists()) { execute(initScript); } File initScriptD = new File(hudson.getRootDir(), "init.groovy.d"); if (initScriptD.isDirectory()) { File[] scripts = initScriptD.listFiles(new FileFilter() { @Override public boolean accept(File f) { return f.getName().endsWith(".groovy"); } }); if (scripts != null) { // sort to run them in a deterministic order Arrays.sort(scripts); for (File f : scripts) { execute(f); } } } }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Sort.java
/** * Sorts values statelessly in ascending order * @param v1 the values to sort (a native backed array) * @return tmp the sorted values// w ww . j a v a 2 s . c o m */ public static double[] stateless(double[] v1) { Validate.notNull(v1); double[] tmp = Arrays.copyOf(v1, v1.length); Arrays.sort(tmp); return tmp; }
From source file:com.opengamma.analytics.math.statistics.descriptive.PercentileCalculator.java
/** * @param x The data, not null or empty//from w w w. j av a 2 s . c o m * @return The percentile */ @Override public Double evaluate(final double[] x) { Validate.notNull(x, "x"); Validate.isTrue(x.length > 0, "x cannot be empty"); final int length = x.length; final double[] copy = Arrays.copyOf(x, length); Arrays.sort(copy); final double n = _percentile * (length - 1) + 1; if (Math.round(n) == 1) { return copy[0]; } if (Math.round(n) == length) { return copy[length - 1]; } final double d = n % 1; final int k = (int) Math.round(n - d); return copy[k - 1] + d * (copy[k] - copy[k - 1]); }
From source file:com.opengamma.strata.math.impl.rootfinding.EigenvaluePolynomialRootFinderTest.java
@Test public void test() { final double[] r = new double[] { -RANDOM.nextDouble(), -RANDOM.nextDouble(), RANDOM.nextDouble(), RANDOM.nextDouble() };/*from w w w . jav a 2s . c o m*/ final double a0 = r[0] * r[1] * r[2] * r[3]; final double a1 = r[0] * r[1] * r[2] + r[0] * r[1] * r[3] + r[0] * r[2] * r[3] + r[1] * r[2] * r[3]; final double a2 = r[0] * r[1] + r[0] * r[2] + r[0] * r[3] + r[1] * r[2] + r[1] * r[3] + r[2] * r[3]; final double a3 = r[0] + r[1] + r[2] + r[3]; final double a4 = 1; final RealPolynomialFunction1D f = new RealPolynomialFunction1D(new double[] { a0, a1, a2, a3, a4 }); final Double[] roots = FINDER.getRoots(f); Arrays.sort(roots); final double[] expected = new double[r.length]; for (int i = 0; i < r.length; i++) { expected[i] = -r[i]; } Arrays.sort(expected); for (int i = 0; i < roots.length; i++) { assertEquals(roots[i], expected[i], 1e-12); } }
From source file:com.zte.ums.zenap.itm.agent.plugin.linux.util.Calculator.java
public String calculateItem(Map variables, String formula) throws MonitorException { Set vKeySet = variables.keySet(); Object[] keys = vKeySet.toArray(); Arrays.sort(keys); JexlContext jexlContext = new MapContext(); for (int i = keys.length - 1; i >= 0; i--) { String s = keys[i].toString(); String s1 = s.replace('.', 'a'); formula = formula.replaceAll(s, s1); jexlContext.set(s1, variables.get(s)); }/*from w ww .ja v a 2 s. c o m*/ try { while (true) { int eIndex = formula.indexOf("E"); if (eIndex == -1) { break; } int startIndex = getBackwardNumIndex(formula, eIndex); int endIndex = getForwardNumIndex(formula, eIndex); String eNum = formula.substring(eIndex + 1, endIndex); String tenNumString = null; int num = Integer.parseInt(eNum); if (num > 5) { int tenNum = 1; for (int i = 0; i < (num - 5); i++) { tenNum = tenNum * 10; } tenNumString = "100000.0 * " + Integer.toString(tenNum); } else if (num > 0) { int tenNum = 1; for (int i = 0; i < num; i++) { tenNum = tenNum * 10; } tenNumString = Integer.toString(tenNum); } else if (num < 0) { double tenNum = 1; for (int i = 0; i > num; i--) { tenNum = tenNum * 0.1; } tenNumString = Double.toString(tenNum); } String variable = formula.substring(startIndex, endIndex); String headVariable = formula.substring(startIndex, eIndex); formula = formula.replaceFirst(variable, "(" + headVariable + " * " + tenNumString + ")"); } JexlEngine jexlEngine = new JexlEngine(); Expression expression = jexlEngine.createExpression(formula); Object result = expression.evaluate(jexlContext); if (result instanceof Double) { Double dd = (Double) result; NumberFormat formater = new DecimalFormat("#.00"); formater.setRoundingMode(RoundingMode.HALF_UP); return formater.format(dd); } return result.toString(); } catch (Exception e) { throw new MonitorException("Error!Something wrong happened! ", e); } }