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

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

Introduction

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

Prototype

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

Source Link

Document

Removes the first occurrence of the specified element from the specified array.

Usage

From source file:org.exoplatform.platform.portlet.juzu.calendar.CalendarPortletController.java

@Ajax
@Resource//  w w  w.j  a  va2  s.c  om
public Response.Content addCalendar(String calendarId) throws Exception {

    StringBuilder cals = new StringBuilder();
    int i = 0;
    nonDisplayedCalendarList = (String[]) ArrayUtils.removeElement(nonDisplayedCalendarList, calendarId);
    while (i < nonDisplayedCalendarList.length) {
        if (!nonDisplayedCalendarList[i].equals(calendarId))
            cals.append(nonDisplayedCalendarList[i]).append(",");
        i++;
    }
    settingService_.remove(Context.USER, Scope.APPLICATION, CalendarPortletUtils.HOME_PAGE_CALENDAR_SETTINGS);
    settingService_.set(Context.USER, Scope.APPLICATION, CalendarPortletUtils.HOME_PAGE_CALENDAR_SETTINGS,
            SettingValue.create("NonDisplayedCalendar:" + cals.toString()));
    return setting();
}

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

@Override
public boolean remove(Object o) {
    if (o instanceof ExoSocialActivity) {
        ExoSocialActivity a = (ExoSocialActivity) o;
        ids = (String[]) ArrayUtils.removeElement(ids, a.getId());
        return gotList.remove(o);
    }/*ww  w.  ja  v  a  2s  .  c  om*/

    //
    return false;
}

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

/**
 * {@inheritDoc}//from w  w  w .ja  v a2s  . c  o m
 */
public void deleteLike(ExoSocialActivity activity, Identity identity) {
    activity.setTitle(null);
    activity.setBody(null);
    String[] identityIds = activity.getLikeIdentityIds();
    if (ArrayUtils.contains(identityIds, identity.getId())) {
        identityIds = (String[]) ArrayUtils.removeElement(identityIds, identity.getId());
        activity.setLikeIdentityIds(identityIds);
        updateActivity(activity);
    } else {
        LOG.warn("activity is not liked by identity: " + identity);
    }
}

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

/**
 * {@inheritDoc}/*from   www.j ava 2 s  . c o m*/
 */
@Override
public void removeLike(ExoSocialActivity activity, Identity identity) throws ActivityStorageException {
    String[] identityIds = activity.getLikeIdentityIds();
    if (ArrayUtils.contains(identityIds, identity.getId())) {
        identityIds = (String[]) ArrayUtils.removeElement(identityIds, identity.getId());
        activity.setLikeIdentityIds(identityIds);
        saveActivity(activity);
        activityCache.remove(activity.getId());
    } else {
        LOG.warn("activity is not liked by identity: " + identity);
    }
}

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

/**
 * {@inheritDoc}//w  ww  .  j a va2  s. c o m
 */
public List<ExoSocialActivity> getComments(ExoSocialActivity activity) throws ActivityStorageException {
    String activityId = activity.getId();
    List<ExoSocialActivity> cachedComments = commentsCache.get(activityId);
    if (cachedComments == null) {
        // reload activity to make sure to have the most update activity
        activity = getActivity(activityId);
        cachedComments = new ArrayList<ExoSocialActivity>();
        String rawCommentIds = activity.getReplyToId();
        // rawCommentIds can be: null || ,a,b,c,d
        if (rawCommentIds != null) {
            String[] commentIds = rawCommentIds.split(",");
            commentIds = (String[]) ArrayUtils.removeElement(commentIds, "");

            for (String commentId : commentIds) {
                ExoSocialActivity comment = this.getStorage().getActivity(commentId);
                processActivitiy(comment);
                cachedComments.add(comment);
            }
            if (cachedComments.size() > 0) {
                commentsCache.put(activityId, cachedComments);
            }
        }
    }
    return cachedComments;
}

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

@Override
public void deleteLike(ExoSocialActivity activity, Identity identity) {
    activity.setTitle(null);//from   w  w  w . j av  a  2 s .c  o m
    activity.setBody(null);
    String[] identityIds = activity.getLikeIdentityIds();
    if (ArrayUtils.contains(identityIds, identity.getId())) {
        identityIds = (String[]) ArrayUtils.removeElement(identityIds, identity.getId());
        activity.setLikeIdentityIds(identityIds);
        activityListener.onLikeActivity(activity);
    } else {
        LOG.warn("activity is not liked by identity: " + identity);
    }
}

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

private void unLike(ExoSocialActivity activity, String userId) throws ActivityStorageException {
    StreamItem o = getStreamItem(activity.getId(), userId);

    if (o != null) {
        // update LIKER
        String[] viewTypes = o.getViewerType().split(",");
        String[] newViewTypes = (String[]) ArrayUtils.removeElement(viewTypes, ViewerType.LIKER.name());
        boolean removeable = userId.equals(o.getPosterId()) ? false : true;

        if (newViewTypes.length == 0 && removeable) {
            deleteStreamItem(o.getId());
        } else {/*from  w w  w .j  a  v  a2s .co m*/
            updateStreamItem(o.getId(), StringUtils.join(newViewTypes, ","), o.getViewerId(), o.getCommenter(),
                    o.getMentioner(), activity.getUpdated().getTime());
        }
    }
}

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

private void removeMentioner(String activityId, String[] mentionIds) {
    if (ArrayUtils.isEmpty(mentionIds)) {
        return;//from ww  w  .java2  s .c  o m
    }

    List<StreamItem> items = getStreamItem(activityId, mentionIds);
    if (CollectionUtils.isEmpty(items)) {
        return;
    }

    for (StreamItem it : items) {
        //update
        if (StringUtils.isNotBlank(it.getViewerType())) {
            String[] viewTypes = it.getViewerType().split(",");

            //if MENTIONER is Poster, don't remove stream item
            boolean removeable = ArrayUtils.contains(mentionIds, it.getPosterId()) ? false : true;

            if (it.getMentioner() > 0) {
                int number = it.getMentioner() - 1;
                if (number == 0) {
                    //remove Mentioner
                    String[] newViewTypes = (String[]) ArrayUtils.removeElement(viewTypes,
                            ViewerType.MENTIONER.name());
                    if (newViewTypes.length == 0 && removeable) {
                        //delete stream item
                        deleteStreamItem(it.getId());
                    } else {
                        //update number + viewType
                        updateStreamItem(it.getId(), StringUtils.join(newViewTypes, ","), it.getViewerId(),
                                it.getCommenter(), number, it.getTime());
                    }
                } else {
                    //update number
                    updateStreamItem(it.getId(), it.getViewerType(), it.getViewerId(), it.getCommenter(),
                            number, it.getTime());
                }
            }
        }
    }

}

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

private String[] remove(String[] mentionerIds, String mentionStr, List<String> addedOrRemovedIds) {
    for (String mentionerId : mentionerIds) {
        if (mentionerId.indexOf(mentionStr) != -1) {
            int numStored = Integer.parseInt(mentionerId.split(MENTION_CHAR)[1]) - 1;

            if (numStored == 0) {
                addedOrRemovedIds.add(mentionStr.replace(MENTION_CHAR, ""));
                return (String[]) ArrayUtils.removeElement(mentionerIds, mentionerId);
            }//from  w  w w.ja v  a  2 s  .c o  m

            mentionerIds = (String[]) ArrayUtils.removeElement(mentionerIds, mentionerId);
            mentionerIds = (String[]) ArrayUtils.add(mentionerIds, mentionStr + numStored);
            break;
        }
    }
    return mentionerIds;
}

From source file:org.exoplatform.social.core.space.impl.SpaceServiceImpl.java

/**
 * {@inheritDoc}/*w w w .ja  va 2s . c o m*/
 */
public void removeMember(Space space, String userId) {
    String[] members = space.getMembers();
    if (ArrayUtils.contains(members, userId)) {
        members = (String[]) ArrayUtils.removeElement(members, userId);
        space.setMembers(members);
        this.updateSpace(space);
        SpaceUtils.removeUserFromGroupWithMemberMembership(userId, space.getGroupId());
        spaceLifeCycle.memberLeft(space, userId);
    }
}