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

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

Introduction

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

Prototype

public static short[] add(short[] array, short element) 

Source Link

Document

Copies the given array and adds the given element at the end of the new array.

Usage

From source file:org.exoplatform.social.core.activity.filter.ActivityCounter.java

@Override
public boolean add(ExoSocialActivity e) {
    if (contains(e)) {
        return false;
    }//w w w .  j  ava2s.  com

    //
    ids = (String[]) ArrayUtils.add(ids, e.getId());
    gotList.add(e);
    return true;
}

From source file:org.exoplatform.social.core.activity.filter.ActivityIterator.java

@Override
public boolean add(ExoSocialActivity e) {
    if (contains(e)) {
        return false;
    }//w  ww . java 2s . c  o m

    //
    if (skip++ < offset) {
        return false;
    }

    //
    ids = (String[]) ArrayUtils.add(ids, e.getId());
    gotList.add(e);
    return true;
}

From source file:org.exoplatform.social.core.activity.filter.ActivityUpdateFilter.java

public void addExcludedActivities(String... activityIds) {
    if (activityIds == null)
        return;//from ww w. ja va 2s  .c o  m

    //
    for (String id : activityIds) {
        if (ArrayUtils.contains(excludedActivities, id) == false) {
            excludedActivities = (String[]) ArrayUtils.add(excludedActivities, id);
        }
    }

}

From source file:org.exoplatform.social.core.feature.CommentedAndLikedActivitiesTest.java

@MaxQueryNumber(5)
public void testGetLikedActivities() throws Exception {
    // root post one activity on his stream
    ExoSocialActivity rootActivity = new ExoSocialActivityImpl();
    rootActivity.setTitle("Hello");
    activityStorage.saveActivity(rootIdentity, rootActivity);

    List<ExoSocialActivity> rootActivities = activityStorage.getUserActivities(rootIdentity, 0, 5);
    assertEquals(1, rootActivities.size());

    List<ExoSocialActivity> maryActivities = activityStorage.getUserActivities(maryIdentity, 0, 5);
    assertEquals(0, maryActivities.size());

    // mary like root's activity
    ExoSocialActivity gotActivity = activityStorage.getUserActivities(rootIdentity, 0, 5).get(0);
    String[] likeIdentityIds = gotActivity.getLikeIdentityIds();
    likeIdentityIds = (String[]) ArrayUtils.add(likeIdentityIds, maryIdentity.getId());
    gotActivity.setLikeIdentityIds(likeIdentityIds);
    activityStorage.updateActivity(gotActivity);

    maryActivities = activityStorage.getUserActivities(maryIdentity, 0, 5);
    assertEquals(1, maryActivities.size());

    rootActivity = activityStorage.getUserActivities(rootIdentity, 0, 5).get(0);

    rootActivity.setLikeIdentityIds(new String[] {});

    activityStorage.updateActivity(rootActivity);

    maryActivities = activityStorage.getUserActivities(maryIdentity, 0, 5);
    assertEquals(0, maryActivities.size());

    tearDownActivityList.add(gotActivity);
}

From source file:org.exoplatform.social.core.identity.IdentityResult.java

@Override
public boolean add(Identity e) {
    if (contains(e)) {
        return false;
    }//  w  ww  . j  a va2s . c  om

    //
    if (++skip <= offset) {
        return false;
    }

    //
    ids = (String[]) ArrayUtils.add(ids, e.getId());
    gotList.add(e);
    return true;
}

From source file:org.exoplatform.social.core.manager.ActivityManagerImpl.java

/**
 * {@inheritDoc}//  ww w  .  j av a  2s  .com
 */
public void saveLike(ExoSocialActivity existingActivity, Identity identity) {

    existingActivity.setTitle(null);
    existingActivity.setBody(null);

    String[] identityIds = existingActivity.getLikeIdentityIds();
    if (ArrayUtils.contains(identityIds, identity.getId())) {
        LOG.warn("activity is already liked by identity: " + identity);
        return;
    }
    identityIds = (String[]) ArrayUtils.add(identityIds, identity.getId());
    existingActivity.setLikeIdentityIds(identityIds);
    updateActivity(existingActivity);
}

From source file:org.exoplatform.social.core.manager.CachingActivityManager.java

/**
 * {@inheritDoc}//from ww w  . j  a  v a 2 s.  c  o m
 */
@Override
public void saveLike(ExoSocialActivity activity, Identity identity) throws ActivityStorageException {
    String[] identityIds = activity.getLikeIdentityIds();
    if (ArrayUtils.contains(identityIds, identity.getId())) {
        LOG.warn("activity is already liked by identity: " + identity);
        return;
    }
    identityIds = (String[]) ArrayUtils.add(identityIds, identity.getId());
    activity.setLikeIdentityIds(identityIds);
    saveActivity(activity);
    activityCache.remove(activity.getId());
}

From source file:org.exoplatform.social.core.manager.memory.InMemoryActivityManagerImpl.java

@Override
public void saveLike(ExoSocialActivity existingActivity, Identity identity) {

    existingActivity.setTitle(null);/*from  w  w  w .  j  ava  2  s.  c om*/
    existingActivity.setBody(null);

    String[] identityIds = existingActivity.getLikeIdentityIds();
    if (ArrayUtils.contains(identityIds, identity.getId())) {
        LOG.warn("activity is already liked by identity: " + identity);
        return;
    }
    identityIds = (String[]) ArrayUtils.add(identityIds, identity.getId());
    existingActivity.setLikeIdentityIds(identityIds);
    activityListener.onLikeActivity(existingActivity);
    activityLifeCycle.likeActivity(existingActivity);
}

From source file:org.exoplatform.social.core.mysql.storage.ActivityMysqlStorageImpl.java

private void updateMention(StreamItem entity, String mentionId, ExoSocialActivity comment) {
    ///*from  w  w w.  j  a v a 2 s . c  o m*/
    String mentionType = ViewerType.MENTIONER.getType();
    int mentionNum = 1;
    String viewerTypes = null;
    String viewerId = null;
    if (StringUtils.isBlank(entity.getViewerType())) {
        //viewerType = MENTIONER + commenter = 1 + viewerId = mentionId
        viewerTypes = ViewerType.MENTIONER.getType();
        viewerId = mentionId;
    } else {
        viewerId = entity.getViewerId();

        String[] arrViewTypes = entity.getViewerType().split(",");

        if (ArrayUtils.contains(arrViewTypes, mentionType)) {
            // increase number by 1
            mentionNum = entity.getMentioner() + 1;
            viewerTypes = entity.getViewerType();
        } else {
            // add new type MENTIONER to arrViewTypes
            arrViewTypes = (String[]) ArrayUtils.add(arrViewTypes, mentionType);
            viewerTypes = StringUtils.join(arrViewTypes, ",");
        }

        // update mentioner
    }

    //update time comment.getUpdated().getTime()
    updateStreamItem(entity.getId(), viewerTypes, viewerId, entity.getCommenter(), mentionNum,
            comment.getUpdated().getTime());
}

From source file:org.exoplatform.social.core.mysql.storage.ActivityMysqlStorageImpl.java

private void like(ExoSocialActivity activity, String userId) throws ActivityStorageException {
    ///*  w  w  w.  j  av  a2 s. co m*/
    String likeType = ViewerType.LIKER.getType();
    StreamItem o = getStreamItem(activity.getId(), userId);

    if (o == null) {
        // create new stream item for LIKER
        createStreamItem(activity.getId(), activity.getStreamOwner(),
                activity.getUserId() != null ? activity.getUserId() : activity.getPosterId(), userId,
                ViewerType.LIKER.getType(), activity.isHidden(), activity.isLocked(),
                activity.getUpdated().getTime());
    } else {
        // update LIKER
        String[] viewTypes = o.getViewerType().split(",");

        if (ArrayUtils.contains(viewTypes, likeType)) {
            updateStreamItem(o.getId(), o.getViewerType(), o.getViewerId(), o.getCommenter(), o.getMentioner(),
                    activity.getUpdated().getTime());
        } else {
            String newViewTypes = StringUtils.join(ArrayUtils.add(viewTypes, likeType), ",");
            updateStreamItem(o.getId(), newViewTypes, o.getViewerId(), o.getCommenter(), o.getMentioner(),
                    activity.getUpdated().getTime());
        }
    }
}