List of usage examples for org.apache.commons.lang ArrayUtils reverse
public static void reverse(boolean[] array)
Reverses the order of the given array.
From source file:org.opentestsystem.shared.search.SearchTest.java
@Test public void testNumericSorting() { String[] stringvals = new String[] { "Foo", "Bar", "Alpha", "Beta" }; Integer[] intValues = new Integer[] { 3, 11, 12, 14 }; initializeSortObjects(stringvals, intValues); List<TestDomain> allValues = mongoTemplate.findAll(TestDomain.class); for (int i = 0; i < intValues.length; i++) { assertFalse("id order, for: " + i, intValues[i].equals(allValues.get(i).getIntValue())); }/* www . jav a2 s . co m*/ Map<String, String[]> requestMap = new HashMap<String, String[]>(); requestMap.put(PAGE_SIZE, new String[] { ONE_HUNDRED }); requestMap.put(CURRENT_PAGE, new String[] { "0" }); requestMap.put(SORT_DIR, new String[] { ASC }); requestMap.put(SORT_KEY, new String[] { "intValue" }); TestDomainSearchRequest searchRequest = new TestDomainSearchRequest(requestMap); List<TestDomain> results = mongoTemplate.find(searchRequest.buildQuery(), TestDomain.class); assertEquals("wrong number of results finding true", 4, results.size()); checkIntOrder(intValues, results); requestMap.put(SORT_DIR, new String[] { DESC }); searchRequest = new TestDomainSearchRequest(requestMap); results = mongoTemplate.find(searchRequest.buildQuery(), TestDomain.class); ArrayUtils.reverse(intValues); checkIntOrder(intValues, results); }
From source file:org.opentestsystem.shared.search.SearchTest.java
@Test public void testMultiSorting() { String[] stringvals = new String[] { "Alpha", "Alpha", "Alpha", "Beta" }; Integer[] intValues = new Integer[] { 3, 11, 12, 14 }; initializeSortObjects(stringvals, intValues); List<TestDomain> allValues = mongoTemplate.findAll(TestDomain.class); for (int i = 0; i < intValues.length; i++) { assertFalse("id order, for: " + i, intValues[i].equals(allValues.get(i).getIntValue())); }/*from w ww . j a va2 s . c om*/ Map<String, String[]> requestMap = new HashMap<String, String[]>(); requestMap.put(PAGE_SIZE, new String[] { ONE_HUNDRED }); requestMap.put(CURRENT_PAGE, new String[] { "0" }); requestMap.put(SORT_DIR, new String[] { ASC }); requestMap.put(SORT_KEY, new String[] { "stringValue", "intValue" }); TestDomainSearchRequest searchRequest = new TestDomainSearchRequest(requestMap); List<TestDomain> results = mongoTemplate.find(searchRequest.buildQuery(), TestDomain.class); assertEquals("wrong number of results finding true", 4, results.size()); checkIntOrder(intValues, results); requestMap.put(SORT_DIR, new String[] { DESC, DESC }); searchRequest = new TestDomainSearchRequest(requestMap); results = mongoTemplate.find(searchRequest.buildQuery(), TestDomain.class); ArrayUtils.reverse(intValues); checkIntOrder(intValues, results); requestMap.put(SORT_DIR, new String[] { ASC }); searchRequest = new TestDomainSearchRequest(requestMap); results = mongoTemplate.find(searchRequest.buildQuery(), TestDomain.class); ArrayUtils.reverse(intValues); checkIntOrder(intValues, results); requestMap.put(SORT_DIR, new String[] { DESC, DESC }); searchRequest = new TestDomainSearchRequest(requestMap); results = mongoTemplate.find(searchRequest.buildQuery(), TestDomain.class); Integer[] newVals = new Integer[] { 14, 12, 11, 3 }; checkIntOrder(newVals, results); requestMap.put(SORT_DIR, new String[] { ASC, DESC }); searchRequest = new TestDomainSearchRequest(requestMap); results = mongoTemplate.find(searchRequest.buildQuery(), TestDomain.class); newVals = new Integer[] { 12, 11, 3, 14 }; checkIntOrder(newVals, results); requestMap.put(SORT_DIR, new String[] { ASC, ASC }); searchRequest = new TestDomainSearchRequest(requestMap); results = mongoTemplate.find(searchRequest.buildQuery(), TestDomain.class); newVals = new Integer[] { 3, 11, 12, 14 }; checkIntOrder(newVals, results); requestMap.put(SORT_DIR, new String[] { ASC }); searchRequest = new TestDomainSearchRequest(requestMap); results = mongoTemplate.find(searchRequest.buildQuery(), TestDomain.class); newVals = new Integer[] { 3, 11, 12, 14 }; checkIntOrder(newVals, results); requestMap.put(SORT_DIR, new String[] { DESC, ASC }); searchRequest = new TestDomainSearchRequest(requestMap); results = mongoTemplate.find(searchRequest.buildQuery(), TestDomain.class); newVals = new Integer[] { 14, 3, 11, 12 }; checkIntOrder(newVals, results); requestMap.put(SORT_DIR, new String[] { DESC }); searchRequest = new TestDomainSearchRequest(requestMap); results = mongoTemplate.find(searchRequest.buildQuery(), TestDomain.class); newVals = new Integer[] { 14, 3, 11, 12 }; checkIntOrder(newVals, results); }
From source file:org.projectforge.test.PluginTestBase.java
public static void init(final String[] additionalContextFiles, final AbstractPlugin... plugins) throws BeansException, IOException { final List<String> persistentEntries = new ArrayList<String>(); final PluginsRegistry pluginsRegistry = PluginsRegistry.instance(); for (final AbstractPlugin plugin : plugins) { pluginsRegistry.register(plugin); for (final Class<?> persistentEntry : plugin.getPersistentEntities()) { persistentEntries.add(persistentEntry.getName()); }/* ww w .j av a 2s . c o m*/ } preInit(additionalContextFiles); pluginsRegistry.set(getTestConfiguration().getBean("systemUpdater", SystemUpdater.class)); pluginsRegistry.set(getTestConfiguration().getBeanFactory(), Mockito.mock(IResourceSettings.class)); pluginsRegistry.initialize(); if (tablesToDeleteAfterTests == null && CollectionUtils.isNotEmpty(persistentEntries) == true) { // Put the persistent entries in reverse order to delete: final String[] entries = persistentEntries.toArray(new String[0]); ArrayUtils.reverse(entries); tablesToDeleteAfterTests = entries; } init(true); }
From source file:org.sonar.batch.scan.ProjectReactorBuilder.java
private static void extractPropertiesByModule(Map<String, Map<String, String>> propertiesByModuleIdPath, String currentModuleId, String currentModuleIdPath, Map<String, String> parentProperties) { if (propertiesByModuleIdPath.containsKey(currentModuleIdPath)) { throw new IllegalStateException(String.format( "Two modules have the same id: '%s'. Each module must have a unique id.", currentModuleId)); }/*from w ww . j ava 2 s . com*/ Map<String, String> currentModuleProperties = new HashMap<>(); String prefix = !currentModuleId.isEmpty() ? (currentModuleId + ".") : ""; int prefixLength = prefix.length(); // By default all properties starting with module prefix belong to current module Iterator<Entry<String, String>> it = parentProperties.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> e = it.next(); String key = e.getKey(); if (key.startsWith(prefix)) { currentModuleProperties.put(key.substring(prefixLength), e.getValue()); it.remove(); } } String[] moduleIds = getListFromProperty(currentModuleProperties, PROPERTY_MODULES); // Sort module by reverse lexicographic order to avoid issue when one module id is a prefix of another one Arrays.sort(moduleIds); ArrayUtils.reverse(moduleIds); propertiesByModuleIdPath.put(currentModuleIdPath, currentModuleProperties); for (String moduleId : moduleIds) { String subModuleIdPath = currentModuleIdPath.isEmpty() ? moduleId : (currentModuleIdPath + "." + moduleId); extractPropertiesByModule(propertiesByModuleIdPath, moduleId, subModuleIdPath, currentModuleProperties); } }
From source file:org.sonar.java.ast.parser.JavaGrammar.java
private static void keywords(LexerlessGrammarBuilder b) { b.rule(LETTER_OR_DIGIT).is(javaIdentifierPart(b)); for (JavaKeyword tokenType : JavaKeyword.values()) { b.rule(tokenType).is(tokenType.getValue(), b.nextNot(LETTER_OR_DIGIT), SPACING); }//w w w. j a v a2 s . co m String[] keywords = JavaKeyword.keywordValues(); Arrays.sort(keywords); ArrayUtils.reverse(keywords); b.rule(KEYWORD).is(b.firstOf(keywords[0], keywords[1], ArrayUtils.subarray(keywords, 2, keywords.length)), b.nextNot(LETTER_OR_DIGIT)); }
From source file:org.sonar.plugins.qualityprofileprogression.batch.ProfileProgressionDecorator.java
protected String[] getProfileHierchy(String languageKey, String lastProfileName) throws ProfileProgressionException { // collect profile hierarchy List<String> profiles = new ArrayList<String>(); profiles.add(lastProfileName);/* ww w . ja v a 2 s .c om*/ // get last profile in hierarchy RulesProfile profile = profilesDao.getProfile(languageKey, lastProfileName); // check we can find the specified profile for the current project's // language if (profile == null) { throw new ProfileProgressionException( "Unable to find \"" + lastProfileName + "\" quality profile for language: " + languageKey); } // navigate up profile hierarchy while (profile != null && profile.getParentName() != null) { profiles.add(profile.getParentName()); profile = profilesDao.getProfile(languageKey, profile.getParentName()); } // convert List to String[] String[] profileHierarchy = profiles.toArray(new String[profiles.size()]); // make lastProfileName last ArrayUtils.reverse(profileHierarchy); return profileHierarchy; }
From source file:org.sonar.scanner.scan.ProjectReactorBuilder.java
private static void extractPropertiesByModule(Map<String, Map<String, String>> propertiesByModuleIdPath, String currentModuleId, String currentModuleIdPath, Map<String, String> parentProperties) { if (propertiesByModuleIdPath.containsKey(currentModuleIdPath)) { throw MessageException.of(String.format( "Two modules have the same id: '%s'. Each module must have a unique id.", currentModuleId)); }//from ww w. j av a 2 s. c o m Map<String, String> currentModuleProperties = new HashMap<>(); String prefix = !currentModuleId.isEmpty() ? (currentModuleId + ".") : ""; int prefixLength = prefix.length(); // By default all properties starting with module prefix belong to current module Iterator<Entry<String, String>> it = parentProperties.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> e = it.next(); String key = e.getKey(); if (key.startsWith(prefix)) { currentModuleProperties.put(key.substring(prefixLength), e.getValue()); it.remove(); } } String[] moduleIds = getListFromProperty(currentModuleProperties, PROPERTY_MODULES); // Sort modules by reverse lexicographic order to avoid issue when one module id is a prefix of another one Arrays.sort(moduleIds); ArrayUtils.reverse(moduleIds); propertiesByModuleIdPath.put(currentModuleIdPath, currentModuleProperties); for (String moduleId : moduleIds) { if ("sonar".equals(moduleId)) { throw MessageException .of("'sonar' is not a valid module id. Please check property '" + PROPERTY_MODULES + "'."); } String subModuleIdPath = currentModuleIdPath.isEmpty() ? moduleId : (currentModuleIdPath + "." + moduleId); extractPropertiesByModule(propertiesByModuleIdPath, moduleId, subModuleIdPath, currentModuleProperties); } }
From source file:org.sonatype.nexus.util.NumberSequenceTest.java
@Test public void testFibonacciSequenceBackAndForth() { int[] fibonacciNumbers = new int[] { 10, 10, 20, 30, 50, 80, 130, 210, 340, 550, 890, 1440, 2330 }; FibonacciNumberSequence fs = new FibonacciNumberSequence(10); for (int f : fibonacciNumbers) { Assert.assertEquals(f, fs.next()); }//from w w w . j a va2s .c o m fs.reset(); for (int f : fibonacciNumbers) { Assert.assertEquals(f, fs.next()); } ArrayUtils.reverse(fibonacciNumbers); for (int f : fibonacciNumbers) { Assert.assertEquals(f, fs.prev()); } }
From source file:org.springframework.ldap.support.LdapUtils.java
/** * Converts the given number to a binary representation of the specified * length and "endian-ness"./*from w ww .jav a2 s. c o m*/ * * @param number String with number to convert * @param length How long the resulting binary array should be * @param bigEndian <code>true</code> if big endian (5=0005), or * <code>false</code> if little endian (5=5000) * @return byte array containing the binary result in the given order */ static byte[] numberToBytes(String number, int length, boolean bigEndian) { BigInteger bi = new BigInteger(number); byte[] bytes = bi.toByteArray(); int remaining = length - bytes.length; if (remaining < 0) { bytes = ArrayUtils.subarray(bytes, -remaining, bytes.length); } else { byte[] fill = new byte[remaining]; bytes = ArrayUtils.addAll(fill, bytes); } if (!bigEndian) { ArrayUtils.reverse(bytes); } return bytes; }
From source file:org.wso2.carbon.governance.api.common.GovernanceArtifactManager.java
/** * Adds the given artifact to the registry. Please do not use this method to update an existing * artifact use the update method instead. If this method is used to update an existing * artifact, all existing properties (such as lifecycle details) will be removed from the * existing artifact.//w w w .j a va2 s . c om * * @param artifact the artifact. * * @throws GovernanceException if the operation failed. */ public void addGovernanceArtifact(GovernanceArtifact artifact) throws GovernanceException { // adding the attributes for name, namespace + artifact if (artifact.getQName() == null || artifact.getQName().getLocalPart() == null) { String msg = "A valid qualified name was not set for this artifact"; log.error(msg); throw new GovernanceException(msg); } String artifactName = artifact.getQName().getLocalPart(); if (artifactNameAttribute != null) { if (StringUtils.isNotEmpty(artifactName)) { artifact.setAttributes(artifactNameAttribute, new String[] { artifactName }); } } String namespace = artifact.getQName().getNamespaceURI(); if (artifactNamespaceAttribute != null && StringUtils.isNotEmpty(namespace)) { artifact.setAttributes(artifactNamespaceAttribute, new String[] { namespace }); } else if (artifactNamespaceAttribute != null) { namespace = artifact.getAttribute(artifactNamespaceAttribute); } setQName(artifact, artifactName, namespace); validateArtifact(artifact); ((GovernanceArtifactImpl) artifact).associateRegistry(registry); boolean succeeded = false; Resource resource = null; String path = null; try { registry.beginTransaction(); resource = registry.newResource(); resource.setMediaType(mediaType); setContent(artifact, resource); // the artifact will not actually stored in the tmp path. path = GovernanceUtils.getPathFromPathExpression(pathExpression, artifact); if (registry.resourceExists(path)) { throw new GovernanceException("Governance artifact " + artifactName + " already exists at " + path); } String artifactId = artifact.getId(); resource.setUUID(artifactId); registry.put(path, resource); String updatedPath = GovernanceUtils.getArtifactPath(registry, artifactId); if (updatedPath != null && !path.equals(updatedPath)) { path = updatedPath; } if (lifecycle != null) { String[] lifeCycles = lifecycle.split(","); ArrayUtils.reverse(lifeCycles); for (String attachingLifeCycle : lifeCycles) { if (StringUtils.isNotEmpty(attachingLifeCycle)) { registry.associateAspect(path, attachingLifeCycle); } } } ((GovernanceArtifactImpl) artifact).updatePath(); // artifact.setId(resource.getUUID()); //This is done to get the UUID of a existing resource. addRelationships(path, artifact); succeeded = true; } catch (RegistryException e) { String msg; if (artifact.getPath() != null) { msg = "Failed to add artifact: artifact id: " + artifact.getId() + ", path: " + artifact.getPath() + ". " + e.getMessage(); } else { msg = "Failed to add artifact: artifact id: " + artifact.getId() + ". " + e.getMessage(); } log.error(msg, e); throw new GovernanceException(msg, e); } finally { if (succeeded) { try { registry.commitTransaction(); } catch (RegistryException e) { String msg; if (artifact.getPath() != null) { msg = "Error in committing transactions. Failed to add artifact: artifact " + "id: " + artifact.getId() + ", path: " + artifact.getPath() + "."; } else { msg = "Error in committing transactions. Failed to add artifact: artifact " + "id: " + artifact.getId() + "."; } log.error(msg, e); } } else { try { registry.rollbackTransaction(); } catch (RegistryException e) { String msg = "Error in rolling back transactions. Failed to add artifact: " + "artifact id: " + artifact.getId() + ", path: " + artifact.getPath() + "."; log.error(msg, e); } } } }