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:com.aionemu.gameserver.controllers.ObserveController.java

/**
 * /*from w  w  w.  jav  a  2s.  co m*/
 * @param observer
 */
public void removeAttackCalcObserver(AttackCalcObserver observer) {
    synchronized (attackCalcObservers) {
        attackCalcObservers = (AttackCalcObserver[]) ArrayUtils.removeElement(attackCalcObservers, observer);
    }
}

From source file:com.icantrap.collections.dawg.Dawg.java

/**
 * Given a subset of source letters and a possible pattern, find words that would satisfy the conditions.
 *
 * @param letters Confining set of letters to choose from. Use ? for wildcards
 * @param pattern Pattern for words. Use '?' for single letter wildcard. Use '*' for multiple letter wildcard.
 * @return An array of letters./*from   w w  w.ja va2 s  .c  o  m*/
 */
public Result[] subwords(String letters, String pattern)
// yes, there's a lot of repeated code here.  it might get cleaned up at the end.
{
    if (!lettersValid(letters))
        return null;

    if (!patternValid(pattern))
        return null;

    List<PatternToken> patternTokens = processPattern(pattern);
    int tokenCount = patternTokens.size();

    Set<Result> results = new HashSet<Result>(); // the running list of subwords

    Stack<StackEntry> stack = new Stack<StackEntry>(); // a stack of paths to traverse. This prevents the StackOverflowException.
    stack.push(new StackEntry(nodes[0], letters.toUpperCase().toCharArray(), "", 0));

    while (!stack.empty()) {
        StackEntry entry = stack.pop();
        int patternIndex = entry.patternIndex;
        char[] chars = entry.chars;

        int node = entry.node;
        char nodeValue = getChar(node);

        if (patternIndex < tokenCount) // match the pattern
        {
            PatternToken patternToken = patternTokens.get(patternIndex);
            if (patternToken.required) {
                StringBuilder nextSubwordBuilder = new StringBuilder(entry.subword.length() + 1)
                        .append(entry.subword);
                List<Integer> nextWildcardPositions = entry.wildcardPositions;
                switch (patternToken.letter) {
                case '?': // the node value needs to be in the letters
                    if (ArrayUtils.contains(chars, nodeValue))
                        chars = ArrayUtils.removeElement(chars, nodeValue);
                    else if (ArrayUtils.contains(chars, '?')) {
                        chars = ArrayUtils.removeElement(chars, '?');
                        if (nextWildcardPositions == null)
                            nextWildcardPositions = new ArrayList<Integer>();
                        else
                            nextWildcardPositions = new ArrayList<Integer>(entry.wildcardPositions);
                        nextWildcardPositions.add(entry.subword.length());
                    } else
                        continue;

                    nextSubwordBuilder.append(nodeValue);
                    break;
                case (char) -1:
                    if (canTerminate(node))
                        results.add(new Result(entry.subword, nextWildcardPositions));
                    continue;
                default:
                    if (nodeValue != patternToken.letter)
                        continue;
                    if (0 != nodeValue)
                        nextSubwordBuilder.append(nodeValue);
                    break;
                }
                ++patternIndex;

                // if we just fulfilled the last token, see if the subword can terminate
                if ((patternIndex == tokenCount) && canTerminate(node))
                    results.add(new Result(nextSubwordBuilder.toString(), nextWildcardPositions));

                // lookahead to the next token and put a candidate on the stack
                addCandidates(stack, patternTokens, patternIndex, node, chars, nextSubwordBuilder.toString(),
                        nextWildcardPositions);
            } else // optional pattern match
            {
                if (node == nodes[0]) {
                    addCandidates(stack, patternTokens, patternIndex, node, chars, entry.subword,
                            entry.wildcardPositions);
                } else if ('?' == patternToken.letter) {
                    // whether we match the pattern or not, it must be in the letters
                    List<Integer> nextWildcardPositions = entry.wildcardPositions;
                    StringBuilder nextSubwordBuilder = new StringBuilder(entry.subword.length() + 1)
                            .append(entry.subword).append(nodeValue);
                    char[] nextChars;

                    if (ArrayUtils.contains(chars, nodeValue))
                        nextChars = ArrayUtils.removeElement(chars, nodeValue);
                    else if (ArrayUtils.contains(chars, '?')) {
                        nextChars = ArrayUtils.removeElement(chars, '?');
                        if (nextWildcardPositions == null)
                            nextWildcardPositions = new ArrayList<Integer>();
                        else
                            nextWildcardPositions = new ArrayList<Integer>(entry.wildcardPositions);
                        nextWildcardPositions.add(entry.subword.length());
                    } else
                        continue;

                    // match the pattern
                    {
                        int nextPatternIndex = patternIndex + 1;

                        // if we just fulfilled the last token, see if the subword can terminate
                        if ((nextPatternIndex == tokenCount) && canTerminate(node))
                            results.add(new Result(nextSubwordBuilder.toString(), nextWildcardPositions));

                        // lookahead to the next token and put a candidate on the stack
                        addCandidates(stack, patternTokens, nextPatternIndex, node, nextChars,
                                nextSubwordBuilder.toString(), nextWildcardPositions);
                    }

                    // don't match the pattern
                    // lookahead to the next token and put a candidate on the stack
                    addCandidates(stack, patternTokens, patternIndex, node, nextChars,
                            nextSubwordBuilder.toString(), nextWildcardPositions);
                } else {
                    StringBuilder nextSubwordBuilder = new StringBuilder(entry.subword.length() + 1)
                            .append(entry.subword).append(nodeValue);

                    // match the letters, not the pattern
                    {
                        List<Integer> nextWildcardPositions = entry.wildcardPositions;
                        char[] nextChars = null;
                        boolean found = true;

                        if (ArrayUtils.contains(chars, nodeValue))
                            nextChars = ArrayUtils.removeElement(chars, nodeValue);
                        else if (ArrayUtils.contains(chars, '?')) {
                            nextChars = ArrayUtils.removeElement(chars, '?');
                            if (nextWildcardPositions == null)
                                nextWildcardPositions = new ArrayList<Integer>();
                            else
                                nextWildcardPositions = new ArrayList<Integer>(entry.wildcardPositions);
                            nextWildcardPositions.add(entry.subword.length());
                        } else
                            found = false;

                        if (found)
                            // lookahead to the next token and put a candidate on the stack
                            addCandidates(stack, patternTokens, patternIndex, node, nextChars,
                                    nextSubwordBuilder.toString(), nextWildcardPositions);
                    }

                    // match the pattern, not the letters
                    if (nodeValue == patternToken.letter) {
                        int nextPatternIndex = patternIndex + 1;

                        // if we just fulfilled the last token, see if the subword can terminate
                        if ((nextPatternIndex == tokenCount) && canTerminate(node))
                            results.add(new Result(nextSubwordBuilder.toString(), entry.wildcardPositions));

                        // lookahead to the next token and put a candidate on the stack
                        addCandidates(stack, patternTokens, nextPatternIndex, node, chars,
                                nextSubwordBuilder.toString(), entry.wildcardPositions);
                    }
                }
            }
        } else // no pattern to match
        {
            StringBuilder nextSubwordBuilder = new StringBuilder(entry.subword.length() + 1)
                    .append(entry.subword);
            List<Integer> nextWildcardPositions = entry.wildcardPositions;
            char[] nextChars = entry.chars;

            if (node != nodes[0]) {
                if (ArrayUtils.contains(chars, nodeValue))
                    nextChars = ArrayUtils.removeElement(chars, nodeValue);
                else if (ArrayUtils.contains(chars, '?')) {
                    nextChars = ArrayUtils.removeElement(chars, '?');
                    if (nextWildcardPositions == null)
                        nextWildcardPositions = new ArrayList<Integer>();
                    else
                        nextWildcardPositions = new ArrayList<Integer>(entry.wildcardPositions);
                    nextWildcardPositions.add(entry.subword.length());
                } else
                    continue;

                if (0 != nodeValue)
                    nextSubwordBuilder.append(nodeValue);

                if (canTerminate(node))
                    results.add(new Result(nextSubwordBuilder.toString(), nextWildcardPositions));
            }

            // find the next candidate from the letters
            addCandidatesFromLetters(stack, node, nextChars, nextSubwordBuilder.toString(),
                    nextWildcardPositions, patternIndex);
        }
    }
    return results.toArray(new Result[results.size()]);
}

From source file:com.exoplatform.social.activity.storage.cache.CachedActivityStorage.java

private String[] add(String[] mentionerIds, String mentionStr, List<String> addedOrRemovedIds) {
    if (ArrayUtils.toString(mentionerIds).indexOf(mentionStr) == -1) { // the first mention
        addedOrRemovedIds.add(mentionStr.replace(MENTION_CHAR, ""));
        return (String[]) ArrayUtils.add(mentionerIds, mentionStr + 1);
    }/*from  w w w  .j a  va2 s  .c o m*/

    String storedId = null;
    for (String mentionerId : mentionerIds) {
        if (mentionerId.indexOf(mentionStr) != -1) {
            mentionerIds = (String[]) ArrayUtils.removeElement(mentionerIds, mentionerId);
            storedId = mentionStr + (Integer.parseInt(mentionerId.split(MENTION_CHAR)[1]) + 1);
            break;
        }
    }

    addedOrRemovedIds.add(mentionStr.replace(MENTION_CHAR, ""));
    mentionerIds = (String[]) ArrayUtils.add(mentionerIds, storedId);
    return mentionerIds;
}

From source file:com.exoplatform.social.activity.storage.cache.CachedActivityStorage.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  ww .  j  a  va 2  s  .  c o  m*/

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

From source file:com.healthcit.cacure.businessdelegates.GeneratedModuleDataManager.java

private JSONArray generateFormDocuments(JSONArray modules, GeneratedModuleDataDetail moduleDetail) {
    log.debug("In generateFormDocuments method...");
    log.debug("..................................");
    log.debug("..................................");

    // metadata associated with the module
    Map<String, String> metadata = getMetadataForModule(moduleDetail.getModuleId(), false);

    // number of documents to be generated per module
    int numFormsPerModule = moduleDetail.getActualNumberOfCouchDbDocuments()
            / moduleDetail.getActualNumberOfModules();

    JSONObject[] documentArray = new JSONObject[moduleDetail.getActualNumberOfCouchDbDocuments()];

    JSONArray documentJSONArray = new JSONArray();

    log.debug("Number of modules generated: " + modules.size());
    log.debug(/*from w  w w. ja  v  a2  s.  c o  m*/
            "Number of CouchDB documents to be generated: " + moduleDetail.getActualNumberOfCouchDbDocuments());

    // Generate the documents in a multithreaded fashion
    List<Callable<Object>> tasks = new ArrayList<Callable<Object>>();

    for (int index = 0; index < modules.size(); ++index) {
        Callable<Object> task = new GenerateCouchDbDocumentCommand(modules, index, numFormsPerModule,
                documentArray, metadata);

        tasks.add(task);
    }

    ConcurrentUtils.invokeBulkActions(tasks);

    // remove any null entries from the documentArray
    while (ArrayUtils.contains(documentArray, null)) {
        documentArray = (JSONObject[]) ArrayUtils.removeElement(documentArray, null);
    }

    // add the documents to the JSON array
    documentJSONArray.addAll(Arrays.asList(documentArray));

    documentArray = null;

    //debugging
    log.debug("Number of documents actually generated and ready to save: " + documentJSONArray.size());
    if (documentJSONArray.size() > 0)
        log.debug("First document to be saved: " + documentJSONArray.getJSONObject(0));

    // return the JSON array
    return documentJSONArray;
}

From source file:com.taobao.itest.listener.ITestDataSetListener.java

/**
 * Supports two methods of multiple data sources can only use one
 * //ww w . j a va  2 s . c om
 * @param testContext
 * @return
 * @throws Exception
 */
List<DatasetConfig> getDatasetConfigs(TestContext testContext) throws Exception {
    ITestDataSet annotation = findAnnotation(testContext.getTestInstance().getClass(),
            testContext.getTestMethod());
    if (annotation == null)
        return null;

    String[] locations = determineLocations(testContext, annotation);
    String[] dsNames = determineDsNames(testContext, annotation);
    if (dsNames.length > 1 && locations.length != dsNames.length) {
        String errorMsg = format("dsNames number '%s' does'nt matchs the locations number '%s'.",
                dsNames.length, locations.length);
        log.error(errorMsg);
        throw new RuntimeException(errorMsg);
    }

    List<DatasetConfig> datasetConfigs = Collections.synchronizedList(new LinkedList<DatasetConfig>());

    // ========add by junliang, deal tddl begin========
    int ruleIndex = indexOfAppRule(dsNames);
    if (ruleIndex != -1) {
        AppRule rootRule = (AppRule) SpringContextManager.getApplicationContext().getBean(dsNames[ruleIndex]);
        String location = locations[ruleIndex];
        String fileType = location.substring(location.lastIndexOf(".") + 1);
        if (!XLS.equalsIgnoreCase(fileType)) {
            String errMsg = "Invalid file type [" + fileType
                    + "], only XLS file supported if you want to use tddl features";
            throw new RuntimeException(errMsg);
        }
        locations = removeStringFromArray(locations, ruleIndex);
        dsNames = removeStringFromArray(dsNames, ruleIndex);
        HSSFWorkbook workbook = new HSSFWorkbook(
                new DefaultResourceLoader().getResource(location).getInputStream());
        Map<String, HSSFWorkbook> tddlMap = RuleCalUtil.calDataSet(rootRule, workbook, null);// null
        // now
        // means
        // use
        // local
        // machine
        // current
        // time
        String autoGenFilePath = location.substring(0, location.lastIndexOf("/") + 1) + "autoGen/";
        Set<Entry<String, HSSFWorkbook>> entries = tddlMap.entrySet();
        String writeFilePath = null;
        for (Entry<String, HSSFWorkbook> entry : entries) {
            String autoGenLocation = autoGenFilePath + entry.getKey() + ".xls";
            writeFilePath = autoGenLocation.replaceAll("classpath:", "").replaceAll("[\\\\]", "/");
            writeFilePath = "target/test-classes" + writeFilePath;
            String directory = writeFilePath.substring(0, writeFilePath.lastIndexOf("/"));
            File dir = new File(directory);
            if (!dir.isDirectory()) {
                dir.mkdir();
            }
            File destFile = new File(writeFilePath);
            XlsDataSet.write(new XlsDataSet(entry.getValue()), new FileOutputStream(destFile));
            locations = addString2Array(locations, autoGenLocation);
            dsNames = addString2Array(dsNames, entry.getKey());
        }
    }
    // ========deal tddl end========

    for (int i = 0; i < locations.length; i++) {
        String location = locations[i];
        String fileType = location.substring(location.lastIndexOf(".") + 1);
        String dsName = dsNames.length == 1 ? dsNames[0] : dsNames[i];
        // build dataSet begin
        ReplacementDataSet dataSet;
        if (XLS.equalsIgnoreCase(fileType)) {
            XlsDataSet xlsDataSet = new XlsDataSet(
                    new DefaultResourceLoader().getResource(location).getInputStream());
            // if(annotation.dsNames().length==0){//DataSource name maybe
            // defined in xls sheet
            String[] sheetNames = xlsDataSet.getTableNames();
            for (String sheetName : sheetNames) {
                String[] temp = pattern.split(sheetName);
                String tableName = sheetName;
                if (temp.length == 2) {
                    // add by qixiu, remove sheets that has define the
                    // dsnames,use different datasets
                    sheetNames = (String[]) ArrayUtils.removeElement(sheetNames, sheetName);
                    String dsNameTmp = temp[0];
                    tableName = temp[1];
                    dataSet = new ReplacementDataSet(
                            new DefaultDataSet(new XlsTableWrapper(tableName, xlsDataSet.getTable(sheetName))));
                    buildDataBaseConfig(testContext, annotation, datasetConfigs, location, dsNameTmp, dataSet);
                }
            }
            // add by qixiu, for normal sheets use one dataset
            int sheetCounts = sheetNames.length;
            ITable[] tables = new ITable[sheetCounts];
            for (int j = 0; j <= sheetCounts - 1; j++) {
                tables[j] = new XlsTableWrapper(sheetNames[j], xlsDataSet.getTable(sheetNames[j]));
            }
            dataSet = new ReplacementDataSet(new DefaultDataSet(tables));
            buildDataBaseConfig(testContext, annotation, datasetConfigs, location, dsName, dataSet);
            /*
             * }else{ dataSet = new ReplacementDataSet(xlsDataSet);
             * buildDataBaseConfig(testContext, annotation, datasetConfigs,
             * location, dsName, dataSet); }
             */

        } else if (XML.equalsIgnoreCase(fileType)) {
            dataSet = new ReplacementDataSet(
                    new FlatXmlDataSet(new DefaultResourceLoader().getResource(location).getInputStream()));
            dataSet.addReplacementObject("[NULL]", null);
            buildDataBaseConfig(testContext, annotation, datasetConfigs, location, dsName, dataSet);
        } else {
            String errorMsg = format("Unsupported file type,file '%s' must be xls or xml.", location);
            log.error(errorMsg);
            throw new RuntimeException(errorMsg);
        }

        // build dataSet end
    }
    return datasetConfigs;
}

From source file:com.adobe.acs.commons.workflow.bulk.execution.model.Workspace.java

public void removeActivePayload(Payload payload) {
    if (ArrayUtils.contains(activePayloads, payload.getDereferencedPath())) {
        activePayloads = (String[]) ArrayUtils.removeElement(activePayloads, payload.getDereferencedPath());
        properties.put(PN_ACTIVE_PAYLOADS, activePayloads);
    }//w  w w . j  av a  2 s .co m
}

From source file:com.aionemu.gameserver.services.BrokerService.java

/**
 * /*from   w w w  .j  a  v  a2  s . c  om*/
 * @param player
 * @param itemUniqueId
 */
public void buyBrokerItem(Player player, int itemUniqueId) {
    if (player.getInventory().isFull()) {
        PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.MSG_FULL_INVENTORY);
        return;
    }

    boolean isEmptyCache = getFilteredItems(player).length == 0;
    Race playerRace = player.getCommonData().getRace();

    BrokerItem buyingItem = getRaceBrokerItems(playerRace).get(itemUniqueId);

    if (buyingItem == null)
        return; // TODO: Message "this item has already been bought, refresh page please."

    Item item = buyingItem.getItem();
    long price = buyingItem.getPrice();

    if (player.getInventory().getKinahItem().getItemCount() < price)
        return;

    getRaceBrokerItems(playerRace).remove(itemUniqueId);
    putToSettled(playerRace, buyingItem, true);

    if (!isEmptyCache) {
        BrokerItem[] newCache = (BrokerItem[]) ArrayUtils.removeElement(getFilteredItems(player), buyingItem);
        getPlayerCache(player).setBrokerListCache(newCache);
    }

    ItemService.decreaseKinah(player, price);
    ItemService.addFullItem(player, player.getInventory(), item);
    // create save task
    BrokerOpSaveTask bost = new BrokerOpSaveTask(buyingItem);
    saveManager.add(bost);

    showRequestedItems(player, getPlayerCache(player).getBrokerMaskCache(),
            getPlayerCache(player).getBrokerSortTypeCache(), getPlayerCache(player).getBrokerStartPageCache());
}

From source file:com.aionengine.gameserver.services.BrokerService.java

/**
 * @param player/*from   ww w .j ava  2s .c o m*/
 * @param itemUniqueId
 */
public void buyBrokerItem(Player player, int itemUniqueId) {
    boolean isEmptyCache = getFilteredItems(player).length == 0;
    Race playerRace = player.getCommonData().getRace();

    BrokerItem buyingItem = getRaceBrokerItems(playerRace).get(itemUniqueId);

    if (player.getObjectId() == buyingItem.getSellerId()) {
        PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1400750));
        return;
    }

    if (player.getInventory().isFull()) {
        PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1300654));
        return;
    }

    if (buyingItem == null || buyingItem.isSold() || buyingItem.isSettled()) {
        PacketSendUtility.sendPacket(player,
                new SM_SYSTEM_MESSAGE(1300647, new DescriptionId(buyingItem.getItem().getNameID())));
        return; // TODO: Message "this item has already been bought, refresh page please."
    }

    long price = buyingItem.getPrice();

    if (player.getInventory().getKinahItem().getItemCount() < price) {
        PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1300759));
        return;
    }

    getRaceBrokerItems(playerRace).remove(itemUniqueId);
    putToSettled(playerRace, buyingItem, true);

    if (!isEmptyCache) {
        BrokerItem[] newCache = (BrokerItem[]) ArrayUtils.removeElement(getFilteredItems(player), buyingItem);
        getPlayerCache(player).setBrokerListCache(newCache);
    }

    player.getInventory().decreaseKinah(price);
    Item boughtItem = player.getInventory().putToBag(buyingItem.getItem());

    // create save task
    BrokerOpSaveTask bost = new BrokerOpSaveTask(buyingItem, boughtItem, player.getInventory().getKinahItem(),
            player.getObjectId());
    saveManager.add(bost);

    PacketSendUtility.sendPacket(player, new SM_INVENTORY_UPDATE(Collections.singletonList(boughtItem)));
    PacketSendUtility.sendPacket(player, new SM_BROKER_ITEMS(boughtItem, 2));

    showRequestedItems(player, getPlayerCache(player).getBrokerMaskCache(),
            getPlayerCache(player).getBrokerSortTypeCache(), getPlayerCache(player).getBrokerStartPageCache());
}

From source file:gameserver.services.BrokerService.java

/**
 * @param player/* w w w.  j  a va 2s  .co  m*/
 * @param itemUniqueId
 */
public void buyBrokerItem(Player player, int itemUniqueId) {
    boolean isEmptyCache = getFilteredItems(player).length == 0;
    Race playerRace = player.getCommonData().getRace();

    BrokerItem buyingItem = getRaceBrokerItems(playerRace).get(itemUniqueId);
    if (player.isTrading()) {
        PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1300355));
        return;
    }
    if (buyingItem == null) {
        log.warn("BrokerService.buyBrokerItem - getRaceBrokerItems(" + playerRace + ").get(" + itemUniqueId
                + ")" + ", playerId: " + player.getObjectId() + ", playerName: " + player.getName());
        return;
    }

    if (player.getObjectId() == buyingItem.getSellerId()) {
        PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1400750));
        return;
    }

    if (player.getInventory().isFull()) {
        PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1300654));
        return;
    }

    if (buyingItem == null || buyingItem.isSold() || buyingItem.isSettled()) {
        PacketSendUtility.sendPacket(player,
                new SM_SYSTEM_MESSAGE(1300647, new DescriptionId(buyingItem.getItem().getNameID())));
        return; // TODO: Message "this item has already been bought, refresh page please."
    }

    long price = buyingItem.getPrice();

    if (player.getInventory().getKinahItem().getItemCount() < price) {
        PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1300759));
        return;
    }

    getRaceBrokerItems(playerRace).remove(itemUniqueId);
    putToSettled(playerRace, buyingItem, true);

    if (!isEmptyCache) {
        BrokerItem[] newCache = (BrokerItem[]) ArrayUtils.removeElement(getFilteredItems(player), buyingItem);
        getPlayerCache(player).setBrokerListCache(newCache);
    }

    player.getInventory().decreaseKinah(price);
    Item boughtItem = player.getInventory().putToBag(buyingItem.getItem());

    // create save task
    BrokerOpSaveTask bost = new BrokerOpSaveTask(buyingItem, boughtItem, player.getInventory().getKinahItem(),
            player.getObjectId());
    saveManager.add(bost);

    PacketSendUtility.sendPacket(player, new SM_INVENTORY_UPDATE(Collections.singletonList(boughtItem)));
    PacketSendUtility.sendPacket(player, new SM_BROKER_ITEMS(boughtItem, 2));

    showRequestedItems(player, getPlayerCache(player).getBrokerMaskCache(),
            getPlayerCache(player).getBrokerSortTypeCache(), getPlayerCache(player).getBrokerStartPageCache());
}