Example usage for java.util.concurrent CopyOnWriteArrayList contains

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

Introduction

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

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this list contains the specified element.

Usage

From source file:com.l2jfree.gameserver.model.entity.events.TvT.java

public static boolean addPlayerOk(String teamName, L2Player eventPlayer) {
    if (GlobalRestrictions.isRestricted(eventPlayer, TvTRestriction.class)) {
        // TODO: msg
        return false;
    }/*from  www . j a  v a2s.  c  o  m*/

    try {
        if (checkShufflePlayers(eventPlayer) || eventPlayer.isInEvent(TvTPlayerInfo.class)) {
            eventPlayer.sendMessage("You are already participating in the event!");
            return false;
        }

        for (L2Player player : _players) {
            if (player.getObjectId() == eventPlayer.getObjectId()) {
                eventPlayer.sendMessage("You are already participating in the event!");
                return false;
            } else if (player.getName() == eventPlayer.getName()) {
                eventPlayer.sendMessage("You are already participating in the event!");
                return false;
            }
        }
        if (_players.contains(eventPlayer)) {
            eventPlayer.sendMessage("You are already participating in the event!");
            return false;
        }
        if (CTF._savePlayers.contains(eventPlayer.getName())) {
            eventPlayer.sendMessage("You are already participating in another event!");
            return false;
        }
    } catch (Exception e) {
        _log.warn("TvT Engine exception: ", e);
    }

    if (Config.TVT_EVEN_TEAMS.equals("NO"))
        return true;
    else if (Config.TVT_EVEN_TEAMS.equals("BALANCE")) {
        boolean allTeamsEqual = true;
        int countBefore = -1;

        for (int playersCount : _teamPlayersCount) {
            if (countBefore == -1)
                countBefore = playersCount;

            if (countBefore != playersCount) {
                allTeamsEqual = false;
                break;
            }

            countBefore = playersCount;
        }

        if (allTeamsEqual)
            return true;

        countBefore = Integer.MAX_VALUE;

        for (int teamPlayerCount : _teamPlayersCount) {
            if (teamPlayerCount < countBefore)
                countBefore = teamPlayerCount;
        }

        CopyOnWriteArrayList<String> joinableTeams = new CopyOnWriteArrayList<String>();

        for (String team : _teams) {
            if (teamPlayersCount(team) == countBefore)
                joinableTeams.add(team);
        }

        if (joinableTeams.contains(teamName))
            return true;
    } else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
        return true;

    eventPlayer.sendMessage("Too many players in team \"" + teamName + "\"");
    return false;
}

From source file:com.l2jfree.gameserver.model.entity.events.CTF.java

public static boolean addPlayerOk(String teamName, L2Player eventPlayer) {
    if (GlobalRestrictions.isRestricted(eventPlayer, CTFRestriction.class)) {
        // TODO: msg
        return false;
    }//from w  w  w .  j av  a  2s.c  om

    try {
        if (checkShufflePlayers(eventPlayer) || eventPlayer.isInEvent(CTFPlayerInfo.class)) {
            eventPlayer.sendMessage("You are already participating in the event!");
            return false;
        }

        for (L2Player player : _players) {
            if (player.getObjectId() == eventPlayer.getObjectId()) {
                eventPlayer.sendMessage("You are already participating in the event!");
                return false;
            } else if (player.getName() == eventPlayer.getName()) {
                eventPlayer.sendMessage("You are already participating in the event!");
                return false;
            }
        }
        if (_players.contains(eventPlayer)) {
            eventPlayer.sendMessage("You are already participating in the event!");
            return false;
        }
        if (TvT._savePlayers.contains(eventPlayer.getName())) {
            eventPlayer.sendMessage("You are already participating in another event!");
            return false;
        }
    } catch (Exception e) {
        _log.warn("CTF Siege Engine exception: ", e);
    }

    if (Config.CTF_EVEN_TEAMS.equals("NO"))
        return true;
    else if (Config.CTF_EVEN_TEAMS.equals("BALANCE")) {
        boolean allTeamsEqual = true;
        int countBefore = -1;

        for (int playersCount : _teamPlayersCount) {
            if (countBefore == -1)
                countBefore = playersCount;

            if (countBefore != playersCount) {
                allTeamsEqual = false;
                break;
            }

            countBefore = playersCount;
        }

        if (allTeamsEqual)
            return true;

        countBefore = Integer.MAX_VALUE;

        for (int teamPlayerCount : _teamPlayersCount) {
            if (teamPlayerCount < countBefore)
                countBefore = teamPlayerCount;
        }

        CopyOnWriteArrayList<String> joinableTeams = new CopyOnWriteArrayList<String>();

        for (String team : _teams) {
            if (teamPlayersCount(team) == countBefore)
                joinableTeams.add(team);
        }

        if (joinableTeams.contains(teamName))
            return true;
    } else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
        return true;

    eventPlayer.sendMessage("Too many players in team \"" + teamName + "\"");
    return false;
}

From source file:com.app.server.util.ClassLoaderUtil.java

public static boolean cleanupJarFileFactory(CopyOnWriteArrayList setJarFileNames2Close) {
    boolean res = false;
    Class classJarURLConnection = null;
    try {/*from   ww w.j  a  v  a2s .c  o  m*/
        classJarURLConnection = Class.forName("sun.net.www.protocol.jar.JarURLConnection");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    if (classJarURLConnection == null) {
        return res;
    }
    Field f = null;
    try {
        f = classJarURLConnection.getDeclaredField("factory");
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    }
    if (f == null) {
        return res;
    }
    f.setAccessible(true);
    Object obj = null;
    try {
        obj = f.get(null);
    } catch (IllegalAccessException e) {
        // ignore
    }
    if (obj == null) {
        return res;
    }
    Class classJarFileFactory = obj.getClass();
    //
    HashMap fileCache = null;
    try {
        f = classJarFileFactory.getDeclaredField("fileCache");
        f.setAccessible(true);
        obj = f.get(null);
        if (obj instanceof HashMap) {
            fileCache = (HashMap) obj;
        }
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    HashMap urlCache = null;
    try {
        f = classJarFileFactory.getDeclaredField("urlCache");
        f.setAccessible(true);
        obj = f.get(null);
        if (obj instanceof HashMap) {
            urlCache = (HashMap) obj;
        }
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    if (urlCache != null) {
        HashMap urlCacheTmp = (HashMap) urlCache.clone();
        Iterator it = urlCacheTmp.keySet().iterator();
        while (it.hasNext()) {
            obj = it.next();
            if (!(obj instanceof JarFile)) {
                continue;
            }
            JarFile jarFile = (JarFile) obj;
            if (setJarFileNames2Close.contains(jarFile.getName().trim().toUpperCase())) {
                try {
                    jarFile.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (fileCache != null) {
                    fileCache.remove(jarFile);
                }
                urlCache.remove(jarFile);
            }
        }
        res = true;
    } else if (fileCache != null) {
        // urlCache := null
        HashMap fileCacheTmp = (HashMap) fileCache.clone();
        Iterator it = fileCacheTmp.keySet().iterator();
        while (it.hasNext()) {
            Object key = it.next();
            obj = fileCache.get(key);
            if (!(obj instanceof JarFile)) {
                continue;
            }
            JarFile jarFile = (JarFile) obj;

            try {
                jarFile.close();
            } catch (IOException e) {
                // ignore
            }
            fileCache.remove(key);

        }
        res = true;
    }
    setJarFileNames2Close.clear();
    return res;
}

From source file:com.l2jfree.gameserver.model.entity.events.CTF.java

public static void CheckRestoreFlags() {
    CopyOnWriteArrayList<Integer> teamsTakenFlag = new CopyOnWriteArrayList<Integer>();
    try {//from w w  w .j  a v  a  2s  .  c  o  m
        for (L2Player player : _players) { //if there's a player with a flag
                                           //add the index of the team who's FLAG WAS TAKEN to the list
            if (player != null) {
                final CTFPlayerInfo info = player.as(CTFPlayerInfo.class);

                if (player.isOnline() == 0 && info._haveFlagCTF)// logged off with a flag in his hands
                {
                    AnnounceToPlayers(false,
                            _eventName + "(CTF): " + player.getName() + " logged off with a CTF flag!");
                    info._haveFlagCTF = false;
                    if (_teams.indexOf(info._teamNameHaveFlagCTF) >= 0) {
                        if (_flagsTaken.get(_teams.indexOf(info._teamNameHaveFlagCTF))) {
                            _flagsTaken.set(_teams.indexOf(info._teamNameHaveFlagCTF), false);
                            spawnFlag(info._teamNameHaveFlagCTF);
                            AnnounceToPlayers(false, _eventName + "(CTF): " + info._teamNameHaveFlagCTF
                                    + " flag now returned to place.");
                        }
                    }
                    removeFlagFromPlayer(player);
                    info._teamNameHaveFlagCTF = null;
                    return;
                } else if (info._haveFlagCTF)
                    teamsTakenFlag.add(_teams.indexOf(info._teamNameHaveFlagCTF));
            }
        }
        //Go over the list of ALL teams
        for (String team : _teams) {
            if (team == null)
                continue;
            int index = _teams.indexOf(team);
            if (!teamsTakenFlag.contains(index)) {
                if (_flagsTaken.get(index)) {
                    _flagsTaken.set(index, false);
                    spawnFlag(team);
                    AnnounceToPlayers(false,
                            _eventName + "(CTF): " + team + " flag returned due to player error.");
                }
            }
        }
        //Check if a player ran away from the event holding a flag:
        for (L2Player player : _players) {
            if (player == null)
                continue;

            final CTFPlayerInfo info = player.as(CTFPlayerInfo.class);

            if (info._haveFlagCTF) {
                if (isOutsideCTFArea(player)) {
                    AnnounceToPlayers(false, _eventName + "(CTF): " + player.getName()
                            + " escaped from the event holding a flag!");
                    info._haveFlagCTF = false;
                    if (_teams.indexOf(info._teamNameHaveFlagCTF) >= 0) {
                        if (_flagsTaken.get(_teams.indexOf(info._teamNameHaveFlagCTF))) {
                            _flagsTaken.set(_teams.indexOf(info._teamNameHaveFlagCTF), false);
                            spawnFlag(info._teamNameHaveFlagCTF);
                            AnnounceToPlayers(false, _eventName + "(CTF): " + info._teamNameHaveFlagCTF
                                    + " flag now returned to place.");
                        }
                    }
                    removeFlagFromPlayer(player);
                    info._teamNameHaveFlagCTF = null;
                    player.teleToLocation(_teamsX.get(_teams.indexOf(info._teamNameCTF)),
                            _teamsY.get(_teams.indexOf(info._teamNameCTF)),
                            _teamsZ.get(_teams.indexOf(info._teamNameCTF)));
                    player.sendMessage("You have been returned to your team spawn");
                    return;
                }
            }
        }
    } catch (Exception e) {
        _log.info("CTF.restoreFlags() Error:", e);
    }
}

From source file:org.apache.bval.jsr.xml.ValidationParser.java

private static void applyExecutableValidation(final ValidationConfigType xmlConfig,
        final ConfigurationImpl targetConfig) {
    final CopyOnWriteArrayList<ExecutableType> executableTypes = new CopyOnWriteArrayList<ExecutableType>();
    if (xmlConfig.getExecutableValidation() != null && xmlConfig.getExecutableValidation().getEnabled()
            && xmlConfig.getExecutableValidation().getDefaultValidatedExecutableTypes() != null) {
        executableTypes.addAll(/*from   w  ww  .j  av a 2  s.  c  om*/
                xmlConfig.getExecutableValidation().getDefaultValidatedExecutableTypes().getExecutableType());
    }

    if (executableTypes.contains(ExecutableType.ALL)) {
        executableTypes.clear();
        executableTypes.add(ExecutableType.CONSTRUCTORS);
        executableTypes.add(ExecutableType.NON_GETTER_METHODS);
        executableTypes.add(ExecutableType.GETTER_METHODS);
    } else if (executableTypes.contains(ExecutableType.NONE)) { // if both are present ALL gains
        executableTypes.clear();
    }

    targetConfig.setExecutableValidation(executableTypes);
}

From source file:org.opendaylight.controller.sal.implementation.internal.DataPacketService.java

void setListenDataPacket(Map props, IListenDataPacket s) {
    if (this.listenDataPacket == null || this.indexDataPacket == null) {
        logger.error("data structure to store data is NULL");
        return;//from  w  w w  .j a v  a2 s  .  c  om
    }
    logger.trace("Received setListenDataPacket request");
    for (Object e : props.entrySet()) {
        Map.Entry entry = (Map.Entry) e;
        logger.trace("Prop key:({}) value:({})", entry.getKey(), entry.getValue());
    }

    String listenerName = null;
    String listenerDependency = null;
    Match filter = null;
    Object value;
    // Read the listenerName
    value = props.get("salListenerName");
    if (value instanceof String) {
        listenerName = (String) value;
    }

    if (listenerName == null) {
        logger.error("Trying to set a listener without a Name");
        return;
    }

    //Read the dependency
    value = props.get("salListenerDependency");
    if (value instanceof String) {
        listenerDependency = (String) value;
    }

    //Read match filter if any
    value = props.get("salListenerFilter");
    if (value instanceof Match) {
        filter = (Match) value;
    }

    DataPacketListener l = new DataPacketListener(listenerName, s, listenerDependency, filter);

    DataPacketListener lDependency = new DataPacketListener(listenerDependency, null, null, null);

    // Now let see if there is any dependency
    if (listenerDependency == null) {
        logger.debug("listener without any dependency");
        if (this.indexDataPacket.contains(l)) {
            logger.error("trying to add an existing element");
        } else {
            logger.debug("adding listener: {}", listenerName);
            CopyOnWriteArrayList<DataPacketListener> serialListeners = new CopyOnWriteArrayList<DataPacketListener>();
            serialListeners.add(l);
            this.listenDataPacket.add(serialListeners);
            this.indexDataPacket.add(l);
        }
    } else {
        logger.debug("listener with dependency");
        // Now search for the dependency and put things in order
        if (this.indexDataPacket.contains(l)) {
            logger.error("trying to add an existing element");
        } else {
            logger.debug("adding listener: {}", listenerName);
            // Lets find the set with the dependency in it, if we
            // find it lets just add our dependency at the end of
            // the list.
            for (List<DataPacketListener> serialListeners : this.listenDataPacket) {
                int i = 0;
                boolean done = false;
                if (serialListeners.contains(lDependency)) {
                    serialListeners.add(l);
                    done = true;
                }
                // If we did fine the element, lets break early
                if (done) {
                    break;
                }
            }

            this.indexDataPacket.add(l);
        }
    }
}