List of usage examples for org.apache.commons.lang ArrayUtils lastIndexOf
public static int lastIndexOf(boolean[] array, boolean valueToFind)
Finds the last index of the given value within the array.
From source file:Main.java
public static void main(String[] args) { String[] colours = { "Red", "Orange", "Yellow", "Green", "Blue", "Violet", "Orange", "Blue" }; boolean contains = ArrayUtils.contains(colours, "Blue"); System.out.println("Contains Blue? " + contains); int indexOfYellow = ArrayUtils.indexOf(colours, "Yellow"); System.out.println("indexOfYellow = " + indexOfYellow); int indexOfOrange = ArrayUtils.indexOf(colours, "Orange"); System.out.println("indexOfOrange = " + indexOfOrange); int lastIndexOfOrange = ArrayUtils.lastIndexOf(colours, "Orange"); System.out.println("lastIndexOfOrange = " + lastIndexOfOrange); }
From source file:com.redhat.rhn.common.messaging.SmtpMail.java
private boolean verifyAddress(InternetAddress addr) { log.debug("verifyAddress called ..."); boolean retval = true; String domain = addr.getAddress(); int domainStart = domain.indexOf('@'); if (domainStart > -1 && domainStart + 1 < domain.length()) { domain = domain.substring(domainStart + 1); }//from www.ja va 2 s . c o m if (log.isDebugEnabled()) { log.debug("Restricted domains: " + StringUtils.join(restrictedDomains, " | ")); log.debug("disallowedDomains domains: " + StringUtils.join(disallowedDomains, " | ")); } if (restrictedDomains != null && restrictedDomains.length > 0) { if (ArrayUtils.lastIndexOf(restrictedDomains, domain) == -1) { log.warn("Address " + addr.getAddress() + " not in restricted domains list"); retval = false; } } if (retval && disallowedDomains != null && disallowedDomains.length > 0) { if (ArrayUtils.lastIndexOf(disallowedDomains, domain) > -1) { log.warn("Address " + addr.getAddress() + " in disallowed domains list"); retval = false; } } log.debug("verifyAddress returning: " + retval); return retval; }
From source file:fr.inria.atlanmod.neoemf.map.datastore.estores.impl.DirectWriteMapResourceEStoreImpl.java
@Override public int lastIndexOf(InternalEObject object, EStructuralFeature feature, Object value) { PersistentEObject neoEObject = NeoEObjectAdapterFactoryImpl.getAdapter(object, PersistentEObject.class); Object[] array = (Object[]) getFromMap(neoEObject, feature); if (array == null) { return -1; }//from ww w.j a va 2 s . co m if (feature instanceof EAttribute) { return ArrayUtils.lastIndexOf(array, serializeToMapValue((EAttribute) feature, value)); } else { PersistentEObject childEObject = NeoEObjectAdapterFactoryImpl.getAdapter(value, PersistentEObject.class); return ArrayUtils.lastIndexOf(array, childEObject.id()); } }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.datastore.estores.impl.DirectWriteBlueprintsResourceEStoreImpl.java
@Override public int lastIndexOf(InternalEObject object, EStructuralFeature feature, Object value) { if (feature instanceof EAttribute) { return ArrayUtils.lastIndexOf(toArray(object, feature), value); } else if (feature instanceof EReference) { if (value == null) { return ArrayUtils.INDEX_NOT_FOUND; }/*from w w w . ja v a2 s . c om*/ Vertex inVertex = graph.getVertex(object); Vertex outVertex = graph.getVertex((EObject) value); Iterator<Edge> iterator = outVertex.getEdges(Direction.IN, feature.getName()).iterator(); Edge lastPositionEdge = null; while (iterator.hasNext()) { Edge e = iterator.next(); if (e.getVertex(Direction.OUT).equals(inVertex)) { if (lastPositionEdge == null || ((int) e.getProperty(POSITION)) > (int) lastPositionEdge.getProperty(POSITION)) { lastPositionEdge = e; } } } return (lastPositionEdge == null ? ArrayUtils.INDEX_NOT_FOUND : (int) lastPositionEdge.getProperty(POSITION)); } else { throw new IllegalArgumentException(feature.toString()); } }
From source file:fr.inria.atlanmod.neoemf.datastore.estores.impl.ReadOnlyHbaseResourceEStoreImpl.java
@Override public int lastIndexOf(InternalEObject object, EStructuralFeature feature, Object value) { NeoEMFEObject neoEMFEObject = NeoEMFEObjectAdapterFactoryImpl.getAdapter(object, NeoEMFEObject.class); String[] array = (String[]) getFromTableIfNotExisting(neoEMFEObject, feature); if (array == null) { return -1; }/*w w w.ja va 2 s. c om*/ if (feature instanceof EAttribute) { return ArrayUtils.lastIndexOf(array, serializeValue((EAttribute) feature, value)); } else { NeoEMFEObject childEObject = NeoEMFEObjectAdapterFactoryImpl.getAdapter(value, NeoEMFEObject.class); return ArrayUtils.lastIndexOf(array, childEObject.neoemfId()); } }
From source file:fr.inria.atlanmod.neoemf.datastore.estores.impl.DirectWriteHbaseResourceEStoreImpl.java
@Override public int lastIndexOf(InternalEObject object, EStructuralFeature feature, Object value) { NeoEMFEObject neoEMFEObject = NeoEMFEObjectAdapterFactoryImpl.getAdapter(object, NeoEMFEObject.class); String[] array = (String[]) getFromTable(neoEMFEObject, feature); if (array == null) { return -1; }/*from www. ja v a 2 s. c o m*/ if (feature instanceof EAttribute) { return ArrayUtils.lastIndexOf(array, serializeValue((EAttribute) feature, value)); } else { NeoEMFEObject childEObject = NeoEMFEObjectAdapterFactoryImpl.getAdapter(value, NeoEMFEObject.class); return ArrayUtils.lastIndexOf(array, childEObject.neoemfId()); } }
From source file:org.apache.mahout.df.builder.DefaultTreeBuilderTest.java
/** * make sure that DefaultTreeBuilder.randomAttributes() returns the correct number of attributes, that have not been * selected yet/*from ww w . j a v a2 s . c o m*/ * * @throws Exception */ public void testRandomAttributes() throws Exception { Random rng = RandomUtils.getRandom(); int nbAttributes = rng.nextInt(100) + 1; boolean[] selected = new boolean[nbAttributes]; for (int nloop = 0; nloop < 100; nloop++) { Arrays.fill(selected, false); // randomly select some attributes int nbSelected = rng.nextInt(nbAttributes - 1); for (int index = 0; index < nbSelected; index++) { int attr; do { attr = rng.nextInt(nbAttributes); } while (selected[attr]); selected[attr] = true; } int m = rng.nextInt(nbAttributes); int[] attrs = DefaultTreeBuilder.randomAttributes(rng, selected, m); assertEquals(Math.min(m, nbAttributes - nbSelected), attrs.length); for (int attr : attrs) { // the attribute should not be already selected assertFalse("an attribute has already been selected", selected[attr]); // each attribute should be in the range [0, nbAttributes[ assertTrue(attr >= 0); assertTrue(attr < nbAttributes); // each attribute should appear only once assertEquals(ArrayUtils.indexOf(attrs, attr), ArrayUtils.lastIndexOf(attrs, attr)); } } }
From source file:org.openengsb.core.test.ServiceList.java
@Override public int lastIndexOf(Object o) { return ArrayUtils.lastIndexOf(tracker.getServices(), o); }
From source file:padl.creator.classfile.AbstractClassFileCreator.java
private void createEntities(final ICodeLevelModel aCodeLevelModel, final List listOfSourceConstituents, final ConstituentsRepository constituentsRepository, final ClassFile[] listOfEntities) { // Yann 2006/02/03: Spring cleaning. // Handling member classes makes it harder and harder to // analyse entities using the legacy code below. I rewrite // this algorithm to perform the creation of entities // (including membre entitie) and their connection // (inheritance and implementation) in two pass: // 1. I create all the entities, including member entities. // I put the entities in the right packages. // 2. I connect the entities with one another through // inheritance and implementation, as appropriate. // 1.//from w w w. j a v a2 s. c om Iterator iterator = listOfSourceConstituents.iterator(); while (iterator.hasNext()) { final ClassFile classFile = (ClassFile) iterator.next(); final String entityDisplayID = classFile.getName(); char[] entityID = entityDisplayID.toCharArray(); // I assume that the classfiles are sorted such as member // entities appear *after* their containing entities. // Yann 2011/10/01: Local entity! // There is an entity with ID: // javax.swing.JSlider$1$SmartHashtable$LabelUIResource // that must be dealt with as a local entity. if (!Utils.isAnonymousOrLocalEntity(entityID) && !Utils.isLocalOrLocalMemberEntity(entityID)) { if (!Utils.isMemberEntity(entityID)) { final IFirstClassEntity firstClassEntity; if (Utils.isClass(classFile)) { firstClassEntity = aCodeLevelModel.getFactory().createClass(entityID, Utils.computeSimpleName(entityID)); } else { firstClassEntity = aCodeLevelModel.getFactory().createInterface(entityID, Utils.computeSimpleName(entityID)); } firstClassEntity.setVisibility(classFile.getAccess()); final IPackage enclosingPackage = Utils.getPackage(this.mapOfPackageNamesPackages, entityID); enclosingPackage.addConstituent(firstClassEntity); this.mapOfIDsEntities.put(entityDisplayID, firstClassEntity); } else { final IFirstClassEntity memberEntity; if (Utils.isClass(classFile)) { memberEntity = aCodeLevelModel.getFactory().createMemberClass(entityID, Utils.computeSimpleName(entityID)); } else { memberEntity = aCodeLevelModel.getFactory().createMemberInterface(entityID, Utils.computeSimpleName(entityID)); } memberEntity.setVisibility(classFile.getAccess()); final char[] enclosingEntityID = ArrayUtils.subarray(entityID, 0, ArrayUtils.lastIndexOf(entityID, '$')); Utils.searchForEntity(aCodeLevelModel, enclosingEntityID) .addConstituent((IConstituentOfEntity) memberEntity); this.mapOfIDsEntities.put(entityDisplayID, memberEntity); } } } // 2. At this point, all missing entities must be ghosts! iterator = listOfSourceConstituents.iterator(); while (iterator.hasNext()) { final ClassFile classFile = (ClassFile) iterator.next(); final String entityDisplayName = classFile.getName(); final char[] entityName = entityDisplayName.toCharArray(); if (!Utils.isAnonymousOrLocalEntity(entityName) && !Utils.isLocalOrLocalMemberEntity(entityName)) { // Yann 2008/11/06: Performance. // To increase the performance when building a model // from Java code, I maintain internally a map of // IDs and entities. final IFirstClassEntity firstClassEntity = Utils.getEntityOrCreateGhost(aCodeLevelModel, entityName, this.mapOfIDsEntities); // Yann 2006/02/09: java.lang.Object // The java.lang.Object class does not have a superclass. // Hence, its superclass name would be "" but I don't // want to create a Ghost with no name... // Yann 2014/04/11: Object! // Wow, for the longest time, I was not adding Object // as super-entity for interfaces: weird that it never // caused problem before??? if (!(firstClassEntity.equals(Factory.getInstance().createHierarchyRoot()))) { final String superClassDisplayName = classFile.getSuperName(); final char[] superClassName = superClassDisplayName.toCharArray(); final IFirstClassEntity superEntity = Utils.getEntityOrCreateGhost(aCodeLevelModel, superClassName, this.mapOfIDsEntities); ((IFirstClassEntity) firstClassEntity).addInheritedEntity(superEntity); } final InterfaceList interfaceList = classFile.getInterfaces(); for (int i = 0; i < interfaceList.length(); i++) { final String superInterfaceDisplayName = interfaceList.get(i); final char[] superInterfaceName = superInterfaceDisplayName.toCharArray(); final IFirstClassEntity superEntity = Utils.getEntityOrCreateGhost(aCodeLevelModel, superInterfaceName, this.mapOfIDsEntities); if (firstClassEntity instanceof IClass) { ((IClass) firstClassEntity).addImplementedInterface((IInterfaceActor) superEntity); } else { ((IInterfaceActor) firstClassEntity).addInheritedEntity(superEntity); } } } } }
From source file:padl.creator.classfile.util.Utils.java
public static char[] computeSimpleName(final char[] aJVMClassName) { int index = ArrayUtils.lastIndexOf(aJVMClassName, '$'); if (index == -1) { index = ArrayUtils.lastIndexOf(aJVMClassName, '.'); if (index == -1) { return aJVMClassName; }/* w w w .j ava2 s .c om*/ } return ArrayUtils.subarray(aJVMClassName, index + 1, aJVMClassName.length); }