Example usage for java.util.concurrent CopyOnWriteArrayList clear

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

Introduction

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

Prototype

public void clear() 

Source Link

Document

Removes all of the elements from this list.

Usage

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

private static boolean startEventOk() {
    if (_joining || !_teleport || _started)
        return false;

    if (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE")) {
        if (_teamPlayersCount.contains(0))
            return false;
    } else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE")) {
        CopyOnWriteArrayList<L2Player> playersShuffleTemp = new CopyOnWriteArrayList<L2Player>();
        int loopCount = 0;

        loopCount = _playersShuffle.size();

        for (int i = 0; i < loopCount; i++) {
            if (_playersShuffle != null)
                playersShuffleTemp.add(_playersShuffle.get(i));
        }/*from   w w  w .ja  v a  2 s.c  om*/

        _playersShuffle = playersShuffleTemp;
        playersShuffleTemp.clear();

        //  if (_playersShuffle.size() < (_teams.size()*2)){
        //     return false;
        //  }
    }

    return true;
}

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

private static boolean startEventOk() {
    if (_joining || !_teleport || _started)
        return false;

    if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE")) {
        if (_teamPlayersCount.contains(0))
            return false;
    } else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE")) {
        CopyOnWriteArrayList<L2Player> playersShuffleTemp = new CopyOnWriteArrayList<L2Player>();
        int loopCount = 0;

        loopCount = _playersShuffle.size();

        for (int i = 0; i < loopCount; i++) {
            if (_playersShuffle != null)
                playersShuffleTemp.add(_playersShuffle.get(i));
        }//  ww w  .j a  v  a2 s  . com

        _playersShuffle = playersShuffleTemp;
        playersShuffleTemp.clear();

        //  if (_playersShuffle.size() < (_teams.size()*2)){
        //     return false;
        //  }
    }

    return true;
}

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

public static boolean cleanupJarFileFactory(CopyOnWriteArrayList setJarFileNames2Close) {
    boolean res = false;
    Class classJarURLConnection = null;
    try {//ww  w .j  a  v a 2  s  .  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: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(//  ww w .  j  a v  a  2 s .  co  m
                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);
}