List of usage examples for java.util ArrayList isEmpty
public boolean isEmpty()
From source file:com.ebay.pulsar.sessionizer.cluster.SessionizerLoopbackRingListener.java
@Override public boolean isLeader() { if (shutdownFlag || leavingCluster) { return false; }//from w ww. j av a2 s . c o m lock.readLock().lock(); try { ArrayList<Long> copy = new ArrayList<Long>(activeConsumers); if (copy.isEmpty()) { return false; } Long maxConsumerId = Collections.max(copy); return maxConsumerId == getHostId(); } finally { lock.readLock().unlock(); } }
From source file:ai_coursework.HWState.java
/** * Finds all possible and valid successor states from this.state * @return A list of all valid successor states */// w w w .j a v a 2 s .c o m @Override public List<ActionStatePair> successor() { List<ActionStatePair> result = new ArrayList<>(); ArrayList<Person> bank = raftLocation == RiverBank.NORTH ? northBank : southBank; if (this.isInvalid()) // If the current state is invalid return result; // Return an emtpy set for (int i = 0; i <= HusbandWives.RAFTSIZE && i <= bank.size(); i++) { Combinations combo = new Combinations(bank.size(), i); Iterator<int[]> iterator = combo.iterator(); while (iterator.hasNext()) { int[] selected = iterator.next(); ArrayList<Person> raft = new ArrayList<>(); for (int index : selected) { raft.add(bank.get(index)); } if (raft.isEmpty()) break; HWAction action = new HWAction(raft, oppositeBank(raftLocation)); HWState nextState = this.applyAction(action); if (!nextState.isInvalid()) result.add(new ActionStatePair(action, nextState)); } } return result; }
From source file:org.khmeracademy.btb.auc.pojo.controller.User_controller.java
@RequestMapping(value = "/get", method = RequestMethod.GET, produces = "application/json") @ResponseBody/*from w ww . j av a 2 s .c om*/ public ResponseEntity<Map<String, Object>> getUser( @RequestParam(value = "page", required = false, defaultValue = "1") int page, @RequestParam(value = "limit", required = false, defaultValue = "12") int limit) { Map<String, Object> map = new HashMap<String, Object>(); try { Pagination pagination = new Pagination(); pagination.setLimit(limit); pagination.setPage(page); pagination.setTotalCount(usr_service.countUsers()); ArrayList<User> user = usr_service.getUsers(pagination); if (!user.isEmpty()) { map.put("DATA", user); map.put("STATUS", true); map.put("MESSAGE", "DATA FOUND!"); map.put("PAGINATION", pagination); } else { map.put("STATUS", true); map.put("MESSAGE", "DATA NOT FOUND"); } } catch (Exception e) { map.put("STATUS", false); map.put("MESSAGE", "Error!"); e.printStackTrace(); } return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK); }
From source file:cl.smartcities.isci.transportinspector.fragments.ReportMapFragment.java
/** * action when an event is reported//from w ww . j a va 2s . c o m * * @param events updated events * @param type type id (it can be BUS or BUS_TOP) * @param id license plate or bus-stop code * */ @Override public void update(ArrayList<Event> events, EventRequest.Type type, String id) { // send message to the current strategy if (events != null && !events.isEmpty()) { currentStrategy.updateElementById(events, type, id); } }
From source file:edu.fullerton.timeseriesapp.TimeSeriesApp.java
private int doPlot() throws SQLException, WebUtilException, LdvTableException, ViewConfigException { int ret;/*from ww w . j a v a2s.co m*/ HashSet<Integer> selections = getSelections(); ArrayList<TimeInterval> times = getTimes(); ArrayList<ChanDataBuffer> data = getData(selections, times); if (data.isEmpty()) { System.err.println("No data to plot."); ret = 3; } else { makePlot(data, false); ret = 0; } return ret; }
From source file:com.offbynull.voip.kademlia.GraphHelper.java
private void setupRoutingTreeGraph(Context ctx) { IdXorMetricComparator idComparator = new IdXorMetricComparator(baseId); Map<BitString, Point> processedPrefixes = new HashMap<>(); // prefix -> position on graph addRootToGraph(ctx, processedPrefixes); routeTreePrefixToIds.put(BitString.createFromString(""), new TreeSet<>(idComparator)); // special case for empty prefix LinkedList<BitString> tempPrefixes = new LinkedList<>(routerBucketPrefixes); double maxYPosition = Double.MIN_VALUE; while (true) { // Get next prefixes ArrayList<BitString> nextLevelPrefixes = removePrefixesForNextLevel(tempPrefixes); if (nextLevelPrefixes.isEmpty()) { break; }//from w w w .j a va 2 s .c o m // Find parent int bitLengthOfNextLevelPrefixes = nextLevelPrefixes.get(0).getBitLength(); BitString parentPrefix = getParentPrefix(processedPrefixes.keySet(), nextLevelPrefixes.get(0)); Point parentPoint = processedPrefixes.get(parentPrefix); // Calculate number of bits after parent prefix (the bits to display) int newBitsOffset = parentPrefix.getBitLength(); int newBitsLength = bitLengthOfNextLevelPrefixes - parentPrefix.getBitLength(); // Calculate starting x and y positions double numBranches = 1 << newBitsLength; double missingBitLength = baseId.getBitLength() - bitLengthOfNextLevelPrefixes; double ySpreadAtLevel = Y_SPREAD * (missingBitLength + 1.0); double xSpreadAtLevel = X_SPREAD * (missingBitLength + 1.0); double yPosition = parentPoint.y + ySpreadAtLevel; // nodes right below the parent double xPosition = parentPoint.x - xSpreadAtLevel * (numBranches - 1.0) / 2.0; // nodes x-centered on parent // special-case for netLevelPrefixes where prefix for our baseId doesn't exist... this is the branch that falls further down // // e.g. If you're 000, prefixes will be 1, 01, 001, 000... but for each of those you'll want to show the falling-thru prefix as // well.. for example... // // /\ // (NOT STATED IN PREFIXES) 0 / \ 1 // /\ // (NOT STATED IN PREFIXES) 00 / \ 01 // /\ // (EXISTS IN PREFIXES) 000 / \ 001 // // Note that 000 exists, but 00 and 0 don't. BitString baseIdPortion = baseId.getBitString().getBits(0, bitLengthOfNextLevelPrefixes); if (!nextLevelPrefixes.contains(baseIdPortion)) { nextLevelPrefixes.add(baseIdPortion); } // Make sure smallest branch is always to the left-most by sorting Collections.sort(nextLevelPrefixes, (x, y) -> Long.compare(x.getBitsAsLong(newBitsOffset, newBitsLength), y.getBitsAsLong(newBitsOffset, newBitsLength))); // Add prefixes from routing tree for (BitString nextPrefix : nextLevelPrefixes) { routeTreePrefixToIds.put(nextPrefix, new TreeSet<>(idComparator)); addPrefixToGraph(nextPrefix, newBitsOffset, newBitsLength, xPosition, yPosition, ctx, parentPrefix, processedPrefixes); xPosition += xSpreadAtLevel; } // Update max Y position maxYPosition = Math.max(maxYPosition, yPosition); } }
From source file:dk.nsi.haiba.epimibaimporter.email.EmailSender.java
public void send(final Collection<String> unknownBanrSet, final Collection<String> unknownAlnrSet) { String not_html = "After the recent import, the following unknown table entries are discovered:\n"; ArrayList<String> alnrSet = new ArrayList<String>(unknownAlnrSet); Collections.sort(alnrSet, AlphanumComparator.INSTANCE); ArrayList<String> banrSet = new ArrayList<String>(unknownBanrSet); Collections.sort(banrSet, AlphanumComparator.INSTANCE); if (!alnrSet.isEmpty()) { not_html += "-----\n"; not_html += "alnr:\n"; String delim = ""; for (String alnr : alnrSet) { not_html += delim + alnr;/* w w w.j a va 2s . c o m*/ delim = ", "; } not_html += "\n"; } if (!banrSet.isEmpty()) { not_html += "-----\n"; not_html += "banr:\n"; String delim = ""; for (String banr : banrSet) { not_html += delim + banr; delim = ", "; } not_html += "\n"; } sendText("EPIMIBA: Notification on unknown table entries", not_html); }
From source file:org.shareok.data.plosdata.PlosDoiDataImpl.java
@Override public void getDspaceLoadingData(String fileName) throws Exception { importData(fileName);/*ww w .j a va2s .c o m*/ ArrayList<String> doiList = getDoiData(); if (!doiList.isEmpty()) { PlosRequest req = (PlosRequest) PlosUtil.getPlosContext().getBean("plosRequest"); PlosData plosData = (PlosData) PlosUtil.getPlosContext().getBean("plosData"); for (String doi : doiList) { String[] valArray = doi.split("---"); String isPartOfSeries = valArray[0]; String[] doiArr = valArray[1].split(":"); doi = doiArr[0]; plosData = getDspaceJournalLoadingFilesBySingleDoi(doi); plosDataList.add(plosData); } } }
From source file:com.globocom.grou.report.ts.opentsdb.OpenTSDBClient.java
private ArrayList<HashMap<String, Object>> metrics(Test test) { long testCreated = TimeUnit.MILLISECONDS.toSeconds(test.getCreatedDate().getTime()); long testLastModified = TimeUnit.MILLISECONDS.toSeconds(test.getLastModifiedDate().getTime()); final List<Query> queries = prepareQueries(test, testCreated, testLastModified); final ArrayList<HashMap<String, Object>> listOfResult = doRequest(testCreated, testLastModified, queries); try {/*from www. j a va 2 s .co m*/ if (listOfResult.isEmpty()) { return mapper.readValue("[{\"error\":\" OpenTSDB result is EMPTY \"}]", typeRef); } else { return listOfResult; } } catch (IOException e) { LOGGER.error(e.getMessage(), e); } return null; }
From source file:org.springframework.cloud.netflix.hystrix.amqp.HystrixStreamTask.java
@Scheduled(fixedRateString = "${hystrix.stream.amqp.sendRate:500}") public void sendMetrics() { ArrayList<String> metrics = new ArrayList<>(); this.jsonMetrics.drainTo(metrics); if (!metrics.isEmpty()) { if (log.isTraceEnabled()) { log.trace("sending amqp metrics size: " + metrics.size()); }/* ww w. j a v a 2s . c o m*/ for (String json : metrics) { // TODO: batch all metrics to one message try { this.channel.send(json); } catch (Exception ex) { if (log.isTraceEnabled()) { log.trace("failed sending amqp metrics: " + ex.getMessage()); } } } } }