Example usage for org.apache.commons.lang ArrayUtils isSameLength

List of usage examples for org.apache.commons.lang ArrayUtils isSameLength

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils isSameLength.

Prototype

public static boolean isSameLength(boolean[] array1, boolean[] array2) 

Source Link

Document

Checks whether two arrays are the same length, treating null arrays as length 0.

Usage

From source file:org.esco.grouperui.services.grouper.internal.escoaddons.GrouperServiceApi.java

/**
 * {@inheritDoc}//from  w w  w  .  j  a  v a 2  s .co  m
 */
@SuppressWarnings("unchecked")
public void groupUpdate(final Person thePerson, final Group theGroupToUpdate) throws ESCOGroupNotSaveException,
        ESCOGroupNotFoundException, ESCOAttributeException, ESCOInsufficientPrivilegesException {
    Validate.notNull(thePerson, ServiceConstants.THE_PERSON_MUST_BE_DEFINED);
    Validate.notNull(theGroupToUpdate, ServiceConstants.THE_GROUP_MUST_BE_DEFINED);

    GrouperSession grouperSession = null;
    GrouperSession rootSession = null;
    Subject subject = null;

    try {
        rootSession = GrouperSession.startRootSession();
        subject = SubjectFinder.findById(thePerson.getId(), true);
        grouperSession = GrouperSession.start(subject);
    } catch (SessionException e) {
        throw new ESCOTechnicalException(ServiceConstants.SESSION_CANNOT_BE_CREATE, e);
    } catch (SubjectNotFoundException e) {//
    } catch (SubjectNotUniqueException e) {//
    }
    edu.internet2.middleware.grouper.Group theGroupUpdated = null;
    try {
        theGroupUpdated = GroupFinder.findByUuid(grouperSession, theGroupToUpdate.getIdGroup(), true);
        if (theGroupUpdated == null) {
            GrouperSession.stopQuietly(grouperSession);
            GrouperSession.stopQuietly(rootSession);
            throw new ESCOGroupNotFoundException(ServiceConstants.GROUP_NOT_FOUND);
        }
    } catch (ESCOGroupNotFoundException e) {
        GrouperSession.stopQuietly(grouperSession);
        GrouperSession.stopQuietly(rootSession);
        throw new ESCOGroupNotFoundException(ServiceConstants.GROUP_NOT_FOUND, e);
    }

    try {
        GroupSave myGroup = new GroupSave(grouperSession);
        myGroup.assignGroupNameToEdit(theGroupUpdated.getName());
        myGroup.assignUuid(theGroupToUpdate.getIdGroup());
        myGroup.assignDescription(theGroupToUpdate.getDescription());
        myGroup.assignDisplayExtension(theGroupToUpdate.getDisplayExtension());
        myGroup.assignDisplayName(theGroupToUpdate.getDisplayName());
        myGroup.assignName(theGroupToUpdate.getName());
        myGroup.assignSaveMode(SaveMode.UPDATE);
        theGroupUpdated = myGroup.save();
        // pl
        GrouperHelper egh = grouperHelperFactory.get(grouperSession);
        egh.clearCache();

    } catch (GroupNotFoundException e) {
        GrouperSession.stopQuietly(grouperSession);
        GrouperSession.stopQuietly(rootSession);
        throw new ESCOGroupNotFoundException(ServiceConstants.GROUP_NOT_FOUND, e);
    } catch (InsufficientPrivilegeException e) {
        GrouperSession.stopQuietly(grouperSession);
        GrouperSession.stopQuietly(rootSession);
        throw new ESCOInsufficientPrivilegesException(ServiceConstants.INSUFFICIENT_PRIVILEGES, e);
    } catch (GroupModifyException e) {
        GrouperSession.stopQuietly(grouperSession);
        GrouperSession.stopQuietly(rootSession);
        throw new ESCOGroupNotSaveException(ServiceConstants.GROUP_CANNOT_BE_SAVED, e);
    } catch (Exception e) {
        throw new ESCOGroupNotSaveException(ServiceConstants.GROUP_CANNOT_BE_SAVED, e);
    }
    if (theGroupUpdated != null) {
        // Manage of the group details.
        GroupDetail details = theGroupToUpdate.getDetail();
        GroupDAO dao = GrouperDAOFactory.getFactory().getGroup();

        if (details != null) {

            // Manage the group attributes.
            if (details.getAttributeNames() != null && details.getAttributeValues() != null
                    && ArrayUtils.isSameLength(details.getAttributeNames(), details.getAttributeValues())) {
                for (int i = 0; i < details.getAttributeNames().length; i++) {
                    theGroupUpdated.setAttribute(details.getAttributeNames()[i],
                            details.getAttributeValues()[i]);
                }
                try {
                    dao.update(theGroupUpdated);
                } catch (Exception e) {//
                }
            }

            if (details.getTypeNames() != null) {
                List<String> typeNames = Arrays.asList(details.getTypeNames());
                // Add some type.
                for (String type : typeNames) {
                    try {
                        edu.internet2.middleware.grouper.GroupType aux = GroupTypeFinder.find(type, true);
                        if (!theGroupUpdated.getTypes().contains(aux)) {
                            dao.addType(theGroupUpdated, aux);
                        }
                    } catch (Exception e) {//
                    }
                }
                // Remove some type.
                Set<edu.internet2.middleware.grouper.GroupType> originalGroupDetails = dao
                        ._findAllTypesByGroup(theGroupToUpdate.getIdGroup());

                for (edu.internet2.middleware.grouper.GroupType type : originalGroupDetails) {
                    try {
                        if (!typeNames.contains(type.getName())
                                && !type.getName().equals(ESCOConstantes.BASE_TYPE)) {
                            dao.deleteType(theGroupUpdated, type);
                        }
                    } catch (Exception e) {//
                    }
                }
            }

        }
    }
    GrouperSession.stopQuietly(grouperSession);
    GrouperSession.stopQuietly(rootSession);
}

From source file:org.esco.grouperui.services.grouper.internal.GrouperServiceApi.java

/**
 * {@inheritDoc}/*from   w  w w.ja  v  a2 s.c o  m*/
 */
public void groupUpdate(final Person thePerson, final Group theGroupToUpdate) throws ESCOGroupNotSaveException,
        ESCOGroupNotFoundException, ESCOAttributeException, ESCOInsufficientPrivilegesException {
    Validate.notNull(thePerson, ServiceConstants.THE_PERSON_MUST_BE_DEFINED);
    Validate.notNull(theGroupToUpdate, ServiceConstants.THE_GROUP_MUST_BE_DEFINED);

    GrouperSession grouperSession = null;
    Subject subject = null;

    try {
        subject = SubjectFinder.findById(thePerson.getId(), true);
        grouperSession = GrouperSession.start(subject);
    } catch (SessionException e) {
        throw new ESCOTechnicalException(ServiceConstants.SESSION_CANNOT_BE_CREATE, e);
    } catch (SubjectNotFoundException e) {
    } catch (SubjectNotUniqueException e) {
    }
    edu.internet2.middleware.grouper.Group theGroupUpdated = null;
    try {
        theGroupUpdated = GroupFinder.findByUuid(grouperSession, theGroupToUpdate.getIdGroup(), true);
        if (theGroupUpdated == null) {
            GrouperSession.stopQuietly(grouperSession);
            throw new ESCOGroupNotFoundException(ServiceConstants.GROUP_NOT_FOUND);
        }
    } catch (ESCOGroupNotFoundException e) {
        GrouperSession.stopQuietly(grouperSession);
        throw new ESCOGroupNotFoundException(ServiceConstants.GROUP_NOT_FOUND, e);
    }

    try {
        GroupSave myGroup = new GroupSave(grouperSession);
        myGroup.assignGroupNameToEdit(theGroupUpdated.getName());
        myGroup.assignUuid(theGroupToUpdate.getIdGroup());
        myGroup.assignDescription(theGroupToUpdate.getDescription());
        myGroup.assignDisplayExtension(theGroupToUpdate.getDisplayExtension());
        myGroup.assignDisplayName(theGroupToUpdate.getDisplayName());
        myGroup.assignName(theGroupToUpdate.getName());
        myGroup.assignSaveMode(SaveMode.UPDATE);
        theGroupUpdated = myGroup.save();
    } catch (GroupNotFoundException e) {
        GrouperSession.stopQuietly(grouperSession);
        throw new ESCOGroupNotFoundException(ServiceConstants.GROUP_NOT_FOUND, e);
    } catch (InsufficientPrivilegeException e) {
        GrouperSession.stopQuietly(grouperSession);
        throw new ESCOInsufficientPrivilegesException(ServiceConstants.INSUFFICIENT_PRIVILEGES, e);
    } catch (GroupModifyException e) {
        GrouperSession.stopQuietly(grouperSession);
        throw new ESCOGroupNotSaveException(ServiceConstants.GROUP_CANNOT_BE_SAVED, e);
    } catch (Exception e) {
        throw new ESCOGroupNotSaveException(ServiceConstants.GROUP_CANNOT_BE_SAVED, e);
    }
    if (theGroupUpdated != null) {
        // Manage of the group details.
        GroupDetail details = theGroupToUpdate.getDetail();
        GroupDAO dao = GrouperDAOFactory.getFactory().getGroup();

        if (details != null) {

            // Manage the group attributes.
            if (details.getAttributeNames() != null && details.getAttributeValues() != null
                    && ArrayUtils.isSameLength(details.getAttributeNames(), details.getAttributeValues())) {
                for (int i = 0; i < details.getAttributeNames().length; i++) {
                    theGroupUpdated.setAttribute(details.getAttributeNames()[i],
                            details.getAttributeValues()[i]);
                }
                try {
                    dao.update(theGroupUpdated);
                } catch (Exception e) {
                }
            }

            if (details.getTypeNames() != null) {
                List<String> typeNames = Arrays.asList(details.getTypeNames());
                // Add some type.
                for (String type : typeNames) {
                    try {
                        edu.internet2.middleware.grouper.GroupType aux = GroupTypeFinder.find(type, true);
                        if (!theGroupUpdated.getTypes().contains(aux)) {
                            dao.addType(theGroupUpdated, aux);
                        }
                    } catch (Exception e) {
                    }
                }
                // Remove some type.
                Set<edu.internet2.middleware.grouper.GroupType> originalGroupDetails = dao
                        ._findAllTypesByGroup(theGroupToUpdate.getIdGroup());

                for (edu.internet2.middleware.grouper.GroupType type : originalGroupDetails) {
                    try {
                        if (!typeNames.contains(type.getName())
                                && !type.getName().equals(ESCOConstantes.BASE_TYPE)) {
                            dao.deleteType(theGroupUpdated, type);
                        }
                    } catch (Exception e) {
                    }
                }
            }

        }
    }
    GrouperSession.stopQuietly(grouperSession);
}

From source file:org.jdto.util.ClassUtils.java

/**
 * <p>Checks if an array of Classes can be assigned to another array of
 * Classes.</p>/*w  ww.j  a  va 2  s .  c om*/
 *
 * <p>This method calls {@link #isAssignable(Class, Class) isAssignable} for
 * each Class pair in the input arrays. It can be used to check if a set of
 * arguments (the first parameter) are suitably compatible with a set of
 * method parameter types (the second parameter).</p>
 *
 * <p>Unlike the {@link Class#isAssignableFrom(java.lang.Class)} method,
 * this method takes into account widenings of primitive classes and
 * <code>null</code>s.</p>
 *
 * <p>Primitive widenings allow an int to be assigned to a
 * <code>long</code>,
 * <code>float</code> or
 * <code>double</code>. This method returns the correct result for these
 * cases.</p>
 *
 * <p><code>Null</code> may be assigned to any reference type. This method
 * will return
 * <code>true</code> if
 * <code>null</code> is passed in and the toClass is non-primitive.</p>
 *
 * <p>Specifically, this method tests whether the type represented by the
 * specified
 * <code>Class</code> parameter can be converted to the type represented by
 * this
 * <code>Class</code> object via an identity conversion widening primitive
 * or widening reference conversion. See <em><a
 * href="http://java.sun.com/docs/books/jls/">The Java Language
 * Specification</a></em>, sections 5.1.1, 5.1.2 and 5.1.4 for details.</p>
 *
 * @param classArray the array of Classes to check, may be
 * <code>null</code>
 * @param toClassArray the array of Classes to try to assign into, may be
 * <code>null</code>
 * @param autoboxing whether to use implicit autoboxing/unboxing between
 * primitives and wrappers
 * @return
 * <code>true</code> if assignment possible
 * @since 2.5
 */
public static boolean isAssignable(Class[] classArray, Class[] toClassArray, boolean autoboxing) {
    if (ArrayUtils.isSameLength(classArray, toClassArray) == false) {
        return false;
    }
    if (classArray == null) {
        classArray = ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    if (toClassArray == null) {
        toClassArray = ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    for (int i = 0; i < classArray.length; i++) {
        if (isAssignable(classArray[i], toClassArray[i], autoboxing) == false) {
            return false;
        }
    }
    return true;
}

From source file:org.LexGrid.LexBIG.caCore.test.query.getAssociation.GetAssociationCodingScheme.java

public void testGetCodingSchemeAssociationsLocalNames() throws Exception {
    ApplicationService service = LexEVSServiceHolder.instance().getAppService();

    CodingScheme cs = new CodingScheme();
    cs.setCodingSchemeName(ServiceTestCase.THES_SCHEME);
    cs.setRepresentsVersion(ServiceTestCase.THES_VERSION);

    List<Object> val = service.getAssociation(cs, "_localNameList");

    assertTrue(val != null);

    //Should return one List of LocalNameLists
    assertTrue(val.size() == 1);

    //Should be a List
    assertTrue(val.get(0) instanceof List);

    List localNames = (List) val.get(0);
    String[] expectedLocalNames = new String[] { "NCI Thesaurus", "NCI_Thesaurus", "Thesaurus.owl",
            "ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl", "NCI", "urn:oid:2.16.840.1.113883.3.26.1.1" };

    Object[] foundLocalNames = (Object[]) localNames.toArray();

    assertTrue(ArrayUtils.isSameLength(expectedLocalNames, foundLocalNames));

    for (int i = 0; i < foundLocalNames.length; i++) {
        assertTrue(ArrayUtils.contains(expectedLocalNames, foundLocalNames[i]));
    }//from  w ww .  j  a  va  2 s.c  om

    for (int i = 0; i < expectedLocalNames.length; i++) {
        assertTrue(ArrayUtils.contains(foundLocalNames, expectedLocalNames[i]));
    }
}

From source file:org.nebularis.defproxy.introspection.ReflectionUtils.java

/**
 * For each member of both class arrays, returns <code>true</code> if the
 * type from the first array is assignable from the type taken from the second array.
 * @param classArray/*from  w  w  w.j  a v  a  2 s  .c  o  m*/
 * @param toClassArray
 * @return
 */
public static boolean isAssignable(Class[] classArray, Class[] toClassArray) {
    if (classArray == null) {
        classArray = ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    if (toClassArray == null) {
        toClassArray = ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    if (ArrayUtils.isSameLength(classArray, toClassArray) == false) {
        return false;
    }
    for (int i = 0; i < classArray.length; i++) {
        if (isAssignable(classArray[i], toClassArray[i]) == false) {
            return false;
        }
    }
    return true;
}

From source file:org.springframework.ldap.support.LdapUtilsTest.java

/**
 * Hand-crafted SID./* www .  ja v a 2s  . c  o  m*/
 */
@Test
public void testConvertHandCraftedStringSidToBinary() throws Exception {
    byte[] expectedSid = { (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x05, (byte) 0x15, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00,
            (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00,
            (byte) 0x00 };
    byte[] result = LdapUtils.convertStringSidToBinary("S-1-5-21-1-2-3-4");
    assertThat(ArrayUtils.isSameLength(expectedSid, result)).isTrue();
    for (int i = 0; i < result.length; i++) {
        assertThat(expectedSid[i]).isEqualTo(result[i]);
    }
}

From source file:org.springframework.ldap.support.LdapUtilsTest.java

/**
 * Example SID from "http://www.pcreview.co.uk/forums/thread-1458615.php".
 *///from  www  .  j  a v  a2 s.c  o m
@Test
public void testConvertStringSidToBinary() throws Exception {
    byte[] expectedSid = { (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x05, (byte) 0x15, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xe9,
            (byte) 0x67, (byte) 0xbb, (byte) 0x98, (byte) 0xd6, (byte) 0xb7, (byte) 0xd7, (byte) 0xbf,
            (byte) 0x82, (byte) 0x05, (byte) 0x1e, (byte) 0x6c, (byte) 0x28, (byte) 0x06, (byte) 0x00,
            (byte) 0x00 };
    byte[] result = LdapUtils.convertStringSidToBinary("S-1-5-21-2562418665-3218585558-1813906818-1576");
    assertThat(ArrayUtils.isSameLength(expectedSid, result)).as("incorrect length of array").isTrue();
    for (int i = 0; i < result.length; i++) {
        assertThat(expectedSid[i]).isEqualTo(result[i]);
    }
}