Example usage for org.apache.commons.collections CollectionUtils size

List of usage examples for org.apache.commons.collections CollectionUtils size

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils size.

Prototype

public static int size(Object object) 

Source Link

Document

Gets the size of the collection/iterator specified.

Usage

From source file:org.apache.ranger.plugin.store.file.TagFileStore.java

@Override
public RangerTag getTagByGuid(String guid) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> TagFileStore.getTagByGuid(" + guid + ")");
    }//from   w w  w .ja  v a  2s  . com

    RangerTag ret = null;

    if (guid != null) {
        SearchFilter filter = new SearchFilter(SearchFilter.TAG_GUID, guid);

        List<RangerTag> tags = getTags(filter);

        if (CollectionUtils.isNotEmpty(tags) && CollectionUtils.size(tags) == 1) {
            ret = tags.get(0);
        }
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== TagFileStore.getTagByGuid(" + guid + "): " + ret);
    }

    return ret;
}

From source file:org.apache.ranger.plugin.store.TestTagStore.java

@Test
public void testTagStore_tagResourceMap() throws Exception {

    String tagType = "ssn";

    String resourceGuid = "GUID_SERVICERESOURCE_TEST";
    String tagGuid = "GUID_TAG_TEST";

    List<RangerTag> tags = tagStore.getTags(filter);

    int initTagCount = tags == null ? 0 : tags.size();

    RangerTag tag = new RangerTag(tagType, new HashMap<String, String>());
    tag.setGuid(tagGuid);/*from   w  ww  . jav  a  2 s.  c  o m*/

    validator.preCreateTag(tag);
    RangerTag createdTag = tagStore.createTag(tag);

    assertNotNull("createTag() failed", createdTag);
    tags = tagStore.getTags(filter);

    assertEquals("createTag() failed", initTagCount + 1, tags == null ? 0 : tags.size());

    Map<String, RangerPolicyResource> resourceElements = new HashMap<String, RangerPolicyResource>();

    RangerPolicyResource resource = new RangerPolicyResource();
    resource.setValue("*");
    resourceElements.put("database", resource);

    List<RangerServiceResource> serviceResources = tagStore.getServiceResources(filter);

    int initServiceResourceCount = serviceResources == null ? 0 : serviceResources.size();

    RangerServiceResource serviceResource = new RangerServiceResource();
    serviceResource.setServiceName(serviceName);
    serviceResource.setResourceElements(resourceElements);

    serviceResource.setGuid(resourceGuid);
    validator.preCreateServiceResource(serviceResource);
    RangerServiceResource createdServiceResource = tagStore.createServiceResource(serviceResource);

    assertNotNull("createServiceResource() failed", createdServiceResource);

    serviceResources = tagStore.getServiceResources(filter);

    assertEquals("createServiceResource() failed", initServiceResourceCount + 1,
            serviceResources == null ? 0 : serviceResources.size());

    // Now create map

    RangerTagResourceMap tagResourceMap = validator.preCreateTagResourceMap(tagGuid, resourceGuid);

    RangerTagResourceMap createdTagResourceMap = tagStore.createTagResourceMap(tagResourceMap);

    assertNotNull("createTagResourceMap() failed", createdTagResourceMap);

    ServiceTags serviceTags = tagStore.getServiceTagsIfUpdated(serviceName, -1L);
    List<RangerServiceResource> resourceList = serviceTags.getServiceResources();

    assertTrue("No tagged resources found!",
            CollectionUtils.isNotEmpty(resourceList) && CollectionUtils.size(resourceList) == 1);

    // Delete all created entities
    RangerTagResourceMap map = validator.preDeleteTagResourceMap(tagGuid, resourceGuid);
    tagStore.deleteTagResourceMap(map.getId());

    validator.preDeleteServiceResource(createdServiceResource.getId());
    tagStore.deleteServiceResource(createdServiceResource.getId());

    // private tags are deleted when TagResourceMap is deleted.. No need for deleting it here
    //validator.preDeleteTag(createdTag.getId());
    //tagStore.deleteTag(createdTag.getId());

}

From source file:org.cruxframework.mediamanager.core.service.impl.AbstractLoginService.java

public Boolean login(String login, String password) {
    List<Filter> filters = new ArrayList<Filter>(2);
    filters.add(new Filter("login", login));
    filters.add(new Filter("password", password));
    List<AbstractEntity<UserDTO>> result = getUserDao().search(filters, null);

    if (CollectionUtils.size(result) != 1) {
        return false;
    }/*from  w ww .j  a v  a2s  . c  o m*/

    httpServletRequest.getSession(true).setAttribute(LOGIN, login);
    return true;
}

From source file:org.cruxframework.mediamanager.core.utils.EntityUtils.java

public static <D extends AbstractDTO, E extends AbstractEntity<D>> List<D> convert(List<E> entities) {
    List<D> dtoResultList = new ArrayList<D>(CollectionUtils.size(entities));
    for (E entity : entities) {
        dtoResultList.add(entity.getDTORepresentation());
    }//from w w w.j av  a 2s  .  c o m

    return dtoResultList;
}

From source file:org.dspace.authenticate.OpenAMAuthentication.java

protected void loadGroups(Context context, Collection<String> roles, HttpServletRequest request, String email)
        throws SQLException, AuthorizeException {

    ArrayList<Integer> currentGroups = new ArrayList<>();

    log.info("Number of OpenAM roles received for user " + email + " is " + CollectionUtils.size(roles));

    for (String role : roles) {
        log.info("User " + email + " has OpenAM role " + role);

        if (dSpaceAdminRole.equals(role)) {
            final Group admins = Group.findByName(context, ADMINISTRATOR_GROUP);

            if (admins != null) {
                currentGroups.add(admins.getID());

                if (log.isDebugEnabled()) {
                    log.debug("User " + email + " was added to the " + admins.getName() + " group");
                }//from w ww .  j a  v a2  s.co  m

            } else {
                log.warn(LogManager.getHeader(context, "login",
                        "Could not add user as administrator (group not found)!"));
            }
        } else if (role.startsWith(dSpaceRolePrefix)) {
            final String groupName = role.replaceAll(dSpaceRolePrefix, "");
            final Group group = Group.findByName(context, groupName);
            if (group != null) {
                currentGroups.add(group.getID());
                if (log.isDebugEnabled()) {
                    log.debug("User " + email + " was added to the " + group.getName() + " group");
                }
            } else {
                log.warn(LogManager.getHeader(context, "login",
                        "Could not add user to group:" + groupName + " (group not found)!"));
            }
        }
    }

    if (CollectionUtils.isNotEmpty(currentGroups)) {
        int[] groupIdArray = ArrayUtils.toPrimitive(currentGroups.toArray(new Integer[currentGroups.size()]));
        request.getSession().setAttribute(SPECIAL_GROUP_REQUEST_ATTRIBUTE, groupIdArray);
    }
}

From source file:org.finra.herd.service.BusinessObjectDataServiceUpdateBusinessObjectDataParentsTest.java

@Test
public void testUpdateBusinessObjectDataParents() {
    // Create a business object data key for the first parent.
    BusinessObjectDataKey businessObjectDataParentOneKey = new BusinessObjectDataKey(NAMESPACE_2, BDEF_NAME_2,
            FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION, PARTITION_VALUE_2,
            SUBPARTITION_VALUES_2, DATA_VERSION);

    // Create a business object data key for the second parent.
    BusinessObjectDataKey businessObjectDataParentTwoKey = new BusinessObjectDataKey(NAMESPACE_3, BDEF_NAME_3,
            FORMAT_USAGE_CODE_3, FORMAT_FILE_TYPE_CODE_3, FORMAT_VERSION, PARTITION_VALUE_3,
            SUBPARTITION_VALUES_3, DATA_VERSION);

    // Create a business object data key for the child.
    BusinessObjectDataKey businessObjectDataChildKey = new BusinessObjectDataKey(NAMESPACE, BDEF_NAME,
            FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES,
            DATA_VERSION);//  w ww  .j a v  a 2s .  co m

    // Create the first business object data parent.
    BusinessObjectDataEntity businessObjectDataParentOneEntity = businessObjectDataDaoTestHelper
            .createBusinessObjectDataEntity(businessObjectDataParentOneKey, LATEST_VERSION_FLAG_SET,
                    BDATA_STATUS);

    // Create the first business object data parent.
    BusinessObjectDataEntity businessObjectDataParentTwoEntity = businessObjectDataDaoTestHelper
            .createBusinessObjectDataEntity(businessObjectDataParentTwoKey, LATEST_VERSION_FLAG_SET,
                    BDATA_STATUS);

    // Create a child business object data entity having a pre-registration status.
    BusinessObjectDataEntity businessObjectDataChildEntity = businessObjectDataDaoTestHelper
            .createBusinessObjectDataEntity(businessObjectDataChildKey, LATEST_VERSION_FLAG_SET,
                    BusinessObjectDataStatusEntity.UPLOADING);

    // Associate child and first parent business object data entities.
    businessObjectDataParentOneEntity.getBusinessObjectDataChildren().add(businessObjectDataChildEntity);
    businessObjectDataChildEntity.getBusinessObjectDataParents().add(businessObjectDataParentOneEntity);

    // Update parents for business object data.
    BusinessObjectData businessObjectData = businessObjectDataService.updateBusinessObjectDataParents(
            businessObjectDataChildKey, new BusinessObjectDataParentsUpdateRequest(
                    Collections.singletonList(businessObjectDataParentTwoKey)));

    // Validate the response.
    assertNotNull(businessObjectData);
    assertEquals(1, CollectionUtils.size(businessObjectData.getBusinessObjectDataParents()));
    assertEquals(businessObjectDataParentTwoKey, businessObjectData.getBusinessObjectDataParents().get(0));

    // Validate the parent entities.
    assertTrue(CollectionUtils.isEmpty(businessObjectDataParentOneEntity.getBusinessObjectDataChildren()));
    assertEquals(1, CollectionUtils.size(businessObjectDataParentTwoEntity.getBusinessObjectDataChildren()));
}

From source file:org.finra.herd.service.impl.BusinessObjectDataServiceImplTest.java

@Test
public void testUpdateBusinessObjectDataParents() {
    // Create a business object data key for the first parent.
    BusinessObjectDataKey businessObjectDataParentOneKey = new BusinessObjectDataKey(NAMESPACE_2, BDEF_NAME_2,
            FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION, PARTITION_VALUE_2,
            SUBPARTITION_VALUES_2, DATA_VERSION);

    // Create a business object data key for the second parent.
    BusinessObjectDataKey businessObjectDataParentTwoKey = new BusinessObjectDataKey(NAMESPACE_3, BDEF_NAME_3,
            FORMAT_USAGE_CODE_3, FORMAT_FILE_TYPE_CODE_3, FORMAT_VERSION, PARTITION_VALUE_3,
            SUBPARTITION_VALUES_3, DATA_VERSION);

    // Create a business object data key for the child.
    BusinessObjectDataKey businessObjectDataChildKey = new BusinessObjectDataKey(NAMESPACE, BDEF_NAME,
            FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES,
            DATA_VERSION);//  ww w  . j a  v a2s . c  o m

    // Create first business object data parent.
    BusinessObjectDataEntity businessObjectDataParentOneEntity = businessObjectDataDaoTestHelper
            .createBusinessObjectDataEntity(businessObjectDataParentOneKey, LATEST_VERSION_FLAG_SET,
                    BDATA_STATUS);

    // Create second business object data parent.
    BusinessObjectDataEntity businessObjectDataParentTwoEntity = businessObjectDataDaoTestHelper
            .createBusinessObjectDataEntity(businessObjectDataParentTwoKey, LATEST_VERSION_FLAG_SET,
                    BDATA_STATUS);

    // Create child business object data entity having a pre-registration status.
    BusinessObjectDataEntity businessObjectDataChildEntity = businessObjectDataDaoTestHelper
            .createBusinessObjectDataEntity(businessObjectDataChildKey, LATEST_VERSION_FLAG_SET,
                    BusinessObjectDataStatusEntity.UPLOADING);

    // Associate child and first parent business object data entities.
    businessObjectDataParentOneEntity.getBusinessObjectDataChildren().add(businessObjectDataChildEntity);
    businessObjectDataChildEntity.getBusinessObjectDataParents().add(businessObjectDataParentOneEntity);

    // Create a business object data parents update request.
    BusinessObjectDataParentsUpdateRequest businessObjectDataParentsUpdateRequest = new BusinessObjectDataParentsUpdateRequest(
            Collections.singletonList(businessObjectDataParentTwoKey));

    // Create a business object data.
    BusinessObjectData businessObjectData = new BusinessObjectData();
    businessObjectData.setId(ID);

    // Mock the external calls.
    when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataChildKey))
            .thenReturn(businessObjectDataChildEntity);
    when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataParentTwoKey))
            .thenReturn(businessObjectDataParentTwoEntity);
    when(businessObjectDataDao.saveAndRefresh(businessObjectDataChildEntity))
            .thenReturn(businessObjectDataChildEntity);
    when(businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataChildEntity))
            .thenReturn(businessObjectData);

    // Call the method under test.
    BusinessObjectData result = businessObjectDataServiceImpl.updateBusinessObjectDataParents(
            businessObjectDataChildKey, businessObjectDataParentsUpdateRequest);

    // Verify the external calls.
    verify(businessObjectDataHelper).validateBusinessObjectDataKey(businessObjectDataChildKey, true, true);
    verify(businessObjectDataDaoHelper).validateBusinessObjectDataKeys(
            businessObjectDataParentsUpdateRequest.getBusinessObjectDataParents());
    verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataChildKey);
    verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataParentTwoKey);
    verify(businessObjectDataDao).saveAndRefresh(businessObjectDataChildEntity);
    verify(businessObjectDataHelper).createBusinessObjectDataFromEntity(businessObjectDataChildEntity);
    verifyNoMoreInteractionsHelper();

    // Validate the results.
    assertEquals(businessObjectData, result);

    // Validate the list of parents on the business object data entity.
    assertEquals(1, CollectionUtils.size(businessObjectDataChildEntity.getBusinessObjectDataParents()));
    assertEquals(businessObjectDataParentTwoEntity,
            businessObjectDataChildEntity.getBusinessObjectDataParents().get(0));
}

From source file:org.finra.herd.service.impl.BusinessObjectDataServiceImplTest.java

@Test
public void testUpdateBusinessObjectDataParentsBusinessObjectDataNotInPreRegistrationState() {
    // Create a business object data key for the first parent.
    BusinessObjectDataKey businessObjectDataParentOneKey = new BusinessObjectDataKey(NAMESPACE_2, BDEF_NAME_2,
            FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION, PARTITION_VALUE_2,
            SUBPARTITION_VALUES_2, DATA_VERSION);

    // Create a business object data key for the second parent.
    BusinessObjectDataKey businessObjectDataParentTwoKey = new BusinessObjectDataKey(NAMESPACE_3, BDEF_NAME_3,
            FORMAT_USAGE_CODE_3, FORMAT_FILE_TYPE_CODE_3, FORMAT_VERSION, PARTITION_VALUE_3,
            SUBPARTITION_VALUES_3, DATA_VERSION);

    // Create a business object data key for the child.
    BusinessObjectDataKey businessObjectDataChildKey = new BusinessObjectDataKey(NAMESPACE, BDEF_NAME,
            FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES,
            DATA_VERSION);/* w ww.j a v a  2 s. c om*/

    // Create first business object data parent.
    BusinessObjectDataEntity businessObjectDataParentOneEntity = businessObjectDataDaoTestHelper
            .createBusinessObjectDataEntity(businessObjectDataParentOneKey, LATEST_VERSION_FLAG_SET,
                    BDATA_STATUS);

    // Create a child business object data entity having a non pre-registration status.
    BusinessObjectDataEntity businessObjectDataChildEntity = businessObjectDataDaoTestHelper
            .createBusinessObjectDataEntity(businessObjectDataChildKey, LATEST_VERSION_FLAG_SET,
                    BusinessObjectDataStatusEntity.VALID);

    // Associate child and first parent business object data entities.
    businessObjectDataParentOneEntity.getBusinessObjectDataChildren().add(businessObjectDataChildEntity);
    businessObjectDataChildEntity.getBusinessObjectDataParents().add(businessObjectDataParentOneEntity);

    // Create a business object data parents update request.
    BusinessObjectDataParentsUpdateRequest businessObjectDataParentsUpdateRequest = new BusinessObjectDataParentsUpdateRequest(
            Collections.singletonList(businessObjectDataParentTwoKey));

    // Mock the external calls.
    when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataChildKey))
            .thenReturn(businessObjectDataChildEntity);

    // Try to call the method under test.
    try {
        businessObjectDataServiceImpl.updateBusinessObjectDataParents(businessObjectDataChildKey,
                businessObjectDataParentsUpdateRequest);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format(
                "Unable to update parents for business object data because it has \"%s\" status, which is not one of pre-registration statuses.",
                BusinessObjectDataStatusEntity.VALID), e.getMessage());
    }

    // Verify the external calls.
    verify(businessObjectDataHelper).validateBusinessObjectDataKey(businessObjectDataChildKey, true, true);
    verify(businessObjectDataDaoHelper).validateBusinessObjectDataKeys(
            businessObjectDataParentsUpdateRequest.getBusinessObjectDataParents());
    verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataChildKey);
    verifyNoMoreInteractionsHelper();

    // Validate the business object data entity.
    assertEquals(1, CollectionUtils.size(businessObjectDataChildEntity.getBusinessObjectDataParents()));
    assertEquals(businessObjectDataParentOneEntity,
            businessObjectDataChildEntity.getBusinessObjectDataParents().get(0));
}

From source file:org.goko.autoleveler.bean.GridElevationMap.java

/**
 * Generates the positions in this pattern
 *///w ww .  j a v a 2s .  c o m
private void generatePatternPositions() {
    positions = new ArrayList<Tuple6b>();

    double x = start.getX().doubleValue();
    for (int xi = 0; xi <= xAxisDivisionCount; xi++) {
        double y = start.getY().doubleValue();
        for (int yi = 0; yi <= yAxisDivisionCount; yi++) {
            Tuple6b pos = new Tuple6b(start);
            pos.setX(BigDecimal.valueOf(x));
            pos.setY(BigDecimal.valueOf(y));
            pos.setZ(BigDecimal.valueOf(zSafeHeight));
            vertices[xi][yi] = CollectionUtils.size(positions);
            positions.add(pos);
            y += yAxisStep;
        }
        x += xAxisStep;
    }
    //      for(double x = start.getX().doubleValue(); x <= end.getX().doubleValue(); x+= xAxisStep){
    //         yi = 0;
    //         for(double y = start.getY().doubleValue(); y <= end.getY().doubleValue(); y+= yAxisStep){
    //            Tuple6b pos = new Tuple6b(start);
    //            pos.setX(BigDecimal.valueOf(x));
    //            pos.setY(BigDecimal.valueOf(y));
    //            pos.setZ(BigDecimal.valueOf(zSafeHeight));
    //            vertices[xi][yi] = CollectionUtils.size(positions);
    //            positions.add( pos );
    //            yi += 1;
    //         }
    //         xi += 1;
    //      }

}

From source file:org.goko.controller.grbl.v08.GrblControllerService.java

/** (inheritDoc)
 * @see org.goko.controller.grbl.v08.IGrblControllerService#send(org.goko.core.gcode.element.GCodeLine)
 *///from  ww  w . j  a v  a 2 s  .c o m
@Override
public void send(GCodeLine gCodeLine) throws GkException {
    String cmd = gcodeService.render(gCodeLine);
    List<Byte> byteCommand = GkUtils.toBytesList(cmd);
    int usedBufferCount = CollectionUtils.size(byteCommand);
    communicator.send(byteCommand);
    incrementUsedBufferCount(usedBufferCount + 2); // Dirty hack for end of line chars
}