List of usage examples for java.util.concurrent CopyOnWriteArrayList addAll
public boolean addAll(Collection<? extends E> c)
From source file:com.starit.diamond.client.impl.DefaultSubscriberListener.java
/** * DataIDManagerListener//w w w. ja va 2 s. co m * * @param dataId * @param addListeners */ public void addManagerListeners(String dataId, String group, String instanceId, List<ManagerListener> addListeners) { if (null == dataId || null == addListeners || null == instanceId) { return; } if (addListeners.size() == 0) { return; } String key = makeKey(dataId, group); ConcurrentMap<String, CopyOnWriteArrayList<ManagerListener>> map = allListeners.get(key); if (map == null) { map = new ConcurrentHashMap<String, CopyOnWriteArrayList<ManagerListener>>(); ConcurrentMap<String, CopyOnWriteArrayList<ManagerListener>> oldMap = allListeners.putIfAbsent(key, map); if (oldMap != null) { map = oldMap; } } CopyOnWriteArrayList<ManagerListener> listenerList = map.get(instanceId); if (listenerList == null) { listenerList = new CopyOnWriteArrayList<ManagerListener>(); CopyOnWriteArrayList<ManagerListener> oldList = map.putIfAbsent(instanceId, listenerList); if (oldList != null) { listenerList = oldList; } } listenerList.addAll(addListeners); }
From source file:eu.tango.energymodeller.datasourceclient.WattsUpMeterDataSourceAdaptor.java
@Override public synchronized double getCpuUtilisation(Host host, int lastNSeconds) { double count = 0.0; double sumOfUtil = 0.0; GregorianCalendar cal = new GregorianCalendar(); long now = TimeUnit.MILLISECONDS.toSeconds(cal.getTimeInMillis()); long nowMinustime = now - lastNSeconds; CopyOnWriteArrayList<CPUUtilisation> list = new CopyOnWriteArrayList<>(); list.addAll(cpuMeasure); for (Iterator<CPUUtilisation> it = list.iterator(); it.hasNext();) { CPUUtilisation util = it.next(); if (util.isOlderThan(nowMinustime)) { list.remove(util);// w ww.ja v a2 s.co m cpuMeasure.remove(util); } else { sumOfUtil = sumOfUtil + util.getCpuBusy(); count = count + 1; } } if (count == 0) { return 0.0; } return sumOfUtil / count; }
From source file:Ternary.java
public void shiftLeft(int num) { CopyOnWriteArrayList<Trit> newTrits = new CopyOnWriteArrayList<Trit>(); for (int i = 0; i < num; i++) newTrits.add(Trit.NEUTRAL);/*from w w w . java2 s .com*/ newTrits.addAll(trits); trits = newTrits; }
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( xmlConfig.getExecutableValidation().getDefaultValidatedExecutableTypes().getExecutableType()); }//from w w w .ja v a 2 s. com 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:ypcnv.converter.mainFrame.MainFrame.java
/** * Check configurations for nulls, arrange them, etc. * @param confsList - configurations to be processed. *///from w w w. ja v a 2 s. c o m private void refactorConfigurations(ArrayList<DataSourceConf> confsList) { CopyOnWriteArrayList<DataSourceConf> confs = new CopyOnWriteArrayList<DataSourceConf>(); confs.addAll(confsList); srcObjectConfig = null; dstObjectConfig = null; for (DataSourceConf config : confs) { Side side = config.getSide(); if (side == null) { side = Side.heath; } switch (side) { case source: srcObjectConfig = new DataSourceConf(config); confsList.remove(config); break; case destination: dstObjectConfig = new DataSourceConf(config); confsList.remove(config); break; } } int quantityOfWantedDataSources = 2; for (int idx = 0; idx < confs.size() && idx < quantityOfWantedDataSources && confs.size() > 0; idx++) { Iterator<DataSourceConf> iter = confs.iterator(); while (iter.hasNext()) { DataSourceConf conf = iter.next(); if (srcObjectConfig == null) { srcObjectConfig = conf; confsList.remove(conf); } else if (dstObjectConfig == null) { dstObjectConfig = conf; confsList.remove(conf); } } } if (srcObjectConfig == null) { srcObjectConfig = new DataSourceConf(null, null, null); } if (dstObjectConfig == null) { dstObjectConfig = new DataSourceConf(null, null, null); } confsList = new ArrayList<DataSourceConf>(); confsList.add(srcObjectConfig); confsList.add(dstObjectConfig); }