Java Code Examples for org.apache.commons.lang.ArrayUtils.removeElement()

The following are Jave code examples for showing how to use removeElement() of the org.apache.commons.lang.ArrayUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: shop-manager   File: AuthAspect.java   View Source Code Vote up 5 votes
private Object[] ignoreHttpRequest(Object[] args) {
	if (args == null) return null;
	for (Object o : args) {
		if (o instanceof HttpServletRequest) {
			args = ArrayUtils.removeElement(args, o);
			return args;
		}
	}
	return args;
}
 
Example 2
Project: kaltura-ce-sakai-extension   File: MediaServiceTest.java   View Source Code Vote up 4 votes
public void testUpdateCollectionMediaItems() {
    MediaCollection coll;
    List<MediaItem> items;
    String[] kalturaIds;

    // SUPER ADMIN
    external.currentUserId = KalturaAPIServiceStub.ADMIN_USER_ID;

    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertNotNull(coll);
    assertTrue(coll.isAddItems());
    items = coll.getItems();
    assertEquals(5, items.size());
    kalturaIds = coll.getKalturaIds().toArray(new String[items.size()]);
    service.updateCollectionMediaItems(coll.getId(), kalturaIds);
    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertEquals(5, coll.getItems().size()); // no change in size

    // test adding one
    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertNotNull(coll);
    assertTrue(coll.isAddItems());
    items = coll.getItems();
    assertEquals(5, items.size());
    kalturaIds = coll.getKalturaIds().toArray(new String[items.size()]);
    kalturaIds = (String[]) ArrayUtils.add(kalturaIds, "kid7");
    service.updateCollectionMediaItems(coll.getId(), kalturaIds);
    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertEquals(6, coll.getItems().size()); // +1 size
    assertTrue(coll.getKalturaIds().contains("kid7"));

    // test removing one
    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertNotNull(coll);
    assertTrue(coll.isAddItems());
    items = coll.getItems();
    assertEquals(6, items.size());
    kalturaIds = coll.getKalturaIds().toArray(new String[items.size()]);
    kalturaIds = (String[]) ArrayUtils.removeElement(kalturaIds, "kid7");
    service.updateCollectionMediaItems(coll.getId(), kalturaIds);
    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertEquals(5, coll.getItems().size()); // -1 size
    assertFalse(coll.getKalturaIds().contains("kid7"));

    // testing adding and removing
    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertNotNull(coll);
    assertTrue(coll.isAddItems());
    items = coll.getItems();
    assertEquals(5, items.size());
    kalturaIds = coll.getKalturaIds().toArray(new String[items.size()]);
    kalturaIds = (String[]) ArrayUtils.removeElement(kalturaIds, "kid5");
    kalturaIds = (String[]) ArrayUtils.add(kalturaIds, "kidA");
    kalturaIds = (String[]) ArrayUtils.add(kalturaIds, "kidB");
    service.updateCollectionMediaItems(coll.getId(), kalturaIds);
    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertEquals(6, coll.getItems().size()); // -1 +2 size
    assertFalse(coll.getKalturaIds().contains("kid5"));
    assertTrue(coll.getKalturaIds().contains("kidA"));
    assertTrue(coll.getKalturaIds().contains("kidB"));
}