Example usage for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList

List of usage examples for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList

Introduction

In this page you can find the example usage for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList.

Prototype

public CopyOnWriteArrayList() 

Source Link

Document

Creates an empty list.

Usage

From source file:lineage2.gameserver.model.Player.java

/**
 * Method restoreTradeList.// w w  w.  ja  v  a  2 s  .  c  o m
 */
public void restoreTradeList() {
    String var;
    var = getVar("selllist");
    if (var != null) {
        _sellList = new CopyOnWriteArrayList<TradeItem>();
        String[] items = var.split(":");
        for (String item : items) {
            if (item.equals("")) {
                continue;
            }
            String[] values = item.split(";");
            if (values.length < 3) {
                continue;
            }
            int oId = Integer.parseInt(values[0]);
            long count = Long.parseLong(values[1]);
            long price = Long.parseLong(values[2]);
            ItemInstance itemToSell = getInventory().getItemByObjectId(oId);
            if ((count < 1) || (itemToSell == null)) {
                continue;
            }
            if (count > itemToSell.getCount()) {
                count = itemToSell.getCount();
            }
            TradeItem i = new TradeItem(itemToSell);
            i.setCount(count);
            i.setOwnersPrice(price);
            _sellList.add(i);
        }
        var = getVar("sellstorename");
        if (var != null) {
            setSellStoreName(var);
        }
    }
    var = getVar("packageselllist");
    if (var != null) {
        _packageSellList = new CopyOnWriteArrayList<TradeItem>();
        String[] items = var.split(":");
        for (String item : items) {
            if (item.equals("")) {
                continue;
            }
            String[] values = item.split(";");
            if (values.length < 3) {
                continue;
            }
            int oId = Integer.parseInt(values[0]);
            long count = Long.parseLong(values[1]);
            long price = Long.parseLong(values[2]);
            ItemInstance itemToSell = getInventory().getItemByObjectId(oId);
            if ((count < 1) || (itemToSell == null)) {
                continue;
            }
            if (count > itemToSell.getCount()) {
                count = itemToSell.getCount();
            }
            TradeItem i = new TradeItem(itemToSell);
            i.setCount(count);
            i.setOwnersPrice(price);
            _packageSellList.add(i);
        }
        var = getVar("sellstorename");
        if (var != null) {
            setSellStoreName(var);
        }
    }
    var = getVar("buylist");
    if (var != null) {
        _buyList = new CopyOnWriteArrayList<TradeItem>();
        String[] items = var.split(":");
        for (String item : items) {
            if (item.equals("")) {
                continue;
            }
            String[] values = item.split(";");
            if (values.length < 3) {
                continue;
            }
            TradeItem i = new TradeItem();
            i.setItemId(Integer.parseInt(values[0]));
            i.setCount(Long.parseLong(values[1]));
            i.setOwnersPrice(Long.parseLong(values[2]));
            _buyList.add(i);
        }
        var = getVar("buystorename");
        if (var != null) {
            setBuyStoreName(var);
        }
    }
    var = getVar("createlist");
    if (var != null) {
        _createList = new CopyOnWriteArrayList<ManufactureItem>();
        String[] items = var.split(":");
        for (String item : items) {
            if (item.equals("")) {
                continue;
            }
            String[] values = item.split(";");
            if (values.length < 2) {
                continue;
            }
            int recId = Integer.parseInt(values[0]);
            long price = Long.parseLong(values[1]);
            if (findRecipe(recId)) {
                _createList.add(new ManufactureItem(recId, price));
            }
        }
        var = getVar("manufacturename");
        if (var != null) {
            setManufactureName(var);
        }
    }
}

From source file:l2next.gameserver.model.Player.java

public void restoreTradeList() {
    String var;
    var = getVar("selllist");
    if (var != null) {
        _sellList = new CopyOnWriteArrayList<TradeItem>();
        String[] items = var.split(":");
        for (String item : items) {
            if (item.equals("")) {
                continue;
            }//from   w  w w  .ja  v  a  2 s. co m
            String[] values = item.split(";");
            if (values.length < 3) {
                continue;
            }

            int oId = Integer.parseInt(values[0]);
            long count = Long.parseLong(values[1]);
            long price = Long.parseLong(values[2]);

            ItemInstance itemToSell = getInventory().getItemByObjectId(oId);

            if (count < 1 || itemToSell == null) {
                continue;
            }

            if (count > itemToSell.getCount()) {
                count = itemToSell.getCount();
            }

            TradeItem i = new TradeItem(itemToSell);
            i.setCount(count);
            i.setOwnersPrice(price);

            _sellList.add(i);
        }
        var = getVar("sellstorename");
        if (var != null) {
            setSellStoreName(var);
        }
    }
    var = getVar("packageselllist");
    if (var != null) {
        _packageSellList = new CopyOnWriteArrayList<TradeItem>();
        String[] items = var.split(":");
        for (String item : items) {
            if (item.equals("")) {
                continue;
            }
            String[] values = item.split(";");
            if (values.length < 3) {
                continue;
            }

            int oId = Integer.parseInt(values[0]);
            long count = Long.parseLong(values[1]);
            long price = Long.parseLong(values[2]);

            ItemInstance itemToSell = getInventory().getItemByObjectId(oId);

            if (count < 1 || itemToSell == null) {
                continue;
            }

            if (count > itemToSell.getCount()) {
                count = itemToSell.getCount();
            }

            TradeItem i = new TradeItem(itemToSell);
            i.setCount(count);
            i.setOwnersPrice(price);

            _packageSellList.add(i);
        }
        var = getVar("sellstorename");
        if (var != null) {
            setSellStoreName(var);
        }
    }
    var = getVar("buylist");
    if (var != null) {
        _buyList = new CopyOnWriteArrayList<TradeItem>();
        String[] items = var.split(":");
        for (String item : items) {
            if (item.equals("")) {
                continue;
            }
            String[] values = item.split(";");
            if (values.length < 3) {
                continue;
            }
            TradeItem i = new TradeItem();
            i.setItemId(Integer.parseInt(values[0]));
            i.setCount(Long.parseLong(values[1]));
            i.setOwnersPrice(Long.parseLong(values[2]));
            _buyList.add(i);
        }
        var = getVar("buystorename");
        if (var != null) {
            setBuyStoreName(var);
        }
    }
    var = getVar("createlist");
    if (var != null) {
        _createList = new CopyOnWriteArrayList<ManufactureItem>();
        String[] items = var.split(":");
        for (String item : items) {
            if (item.equals("")) {
                continue;
            }
            String[] values = item.split(";");
            if (values.length < 2) {
                continue;
            }
            int recId = Integer.parseInt(values[0]);
            long price = Long.parseLong(values[1]);
            if (findRecipe(recId)) {
                _createList.add(new ManufactureItem(recId, price));
            }
        }
        var = getVar("manufacturename");
        if (var != null) {
            setManufactureName(var);
        }
    }
}