List of usage examples for java.util LinkedList isEmpty
boolean isEmpty();
From source file:org.movsim.simulator.roadnetwork.RoadSegment.java
private static double travelTimeInRange(double begin, double end, double maxRoadSpeed, LinkedList<Vehicle> vehicles) { int count = 0; double sumSpeed = 0; while (!vehicles.isEmpty() && vehicles.getLast().getFrontPosition() < end) { Vehicle veh = vehicles.removeLast(); sumSpeed += Math.max(veh.getSpeed(), MIN_SPEED_TT); count++;//from w w w .j a v a 2 s. c o m } double avgSpeed = (count == 0) ? maxRoadSpeed : sumSpeed / count; return (end - begin) / avgSpeed; }
From source file:com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter.java
private void addDatum(String name, double value, LinkedList<PutMetricDataRequest> requests, Date timestamp) { if (logger.isDebugEnabled()) { logger.debug("Adding Datum {} with value {} at {}", name, value, timestamp); }/* w ww . j av a 2s .co m*/ if (requests.isEmpty() || requests.getLast().getMetricData().size() == MAX_CLOUDWATCH_DATUM_PER_REQUEST) { requests.add(createRequest()); } PutMetricDataRequest request = requests.getLast(); MetricDatum datum = new MetricDatum().withTimestamp(timestamp).withValue(value).withMetricName(name) .withUnit(StandardUnit.None).withDimensions(createDimensions()); request.withMetricData(datum); }
From source file:org.talend.cwm.db.connection.ConnectionUtils.java
/** * if the DriverClassName is empty or Jar File Path is invalid return false. * //from www .j a va 2 s .com * @param dbConn a General JDBC database connection * @return * @throws MalformedURLException */ public static ReturnCode checkGeneralJdbcJarFilePathDriverClassName(DatabaseConnection dbConn) throws MalformedURLException { ReturnCode returnCode = new ReturnCode(); String driverClass = JavaSqlFactory.getDriverClass(dbConn); String driverJarPath = JavaSqlFactory.getDriverJarPath(dbConn); if (driverClass == null || driverClass.trim().equals("")) { //$NON-NLS-1$ returnCode.setOk(false); returnCode.setMessage(Messages.getString("ConnectionUtils.DriverClassEmpty")); //$NON-NLS-1$ } else { if (driverJarPath == null || driverJarPath.trim().equals("")) { //$NON-NLS-1$ returnCode.setOk(false); returnCode.setMessage(Messages.getString("ConnectionUtils.DriverJarFileEmpty")); //$NON-NLS-1$ } else { List<String> driverJarNameList = new ArrayList<String>(); String[] splits = driverJarPath.split(";"); //$NON-NLS-1$ for (String str : splits) { if (!StringUtils.isBlank(str)) { driverJarNameList.add(str); } } LinkedList<String> driverJarRealPaths = getDriverJarRealPaths(driverJarNameList); if (driverJarRealPaths.isEmpty()) { returnCode.setOk(false); returnCode.setMessage(Messages.getString("ConnectionUtils.JarFileCanNotBeFound")); //$NON-NLS-1$ } for (String str : driverJarRealPaths) { File jarFile = new File(str); if (!jarFile.exists() || jarFile.isDirectory()) { returnCode.setOk(false); returnCode.setMessage(Messages.getString("ConnectionUtils.DriverJarFileInvalid")); //$NON-NLS-1$ break; } } } } return returnCode; }
From source file:org.squashtest.tm.domain.library.structures.LibraryGraph.java
/** * <p> Will merge the structure of a graph into this graph. This means that nodes will be created if no equivalent exist already, * same goes for inbound/outbound edges . You must provide an implementation of {@link NodeTransformer} * in order to allow the conversion of a node from the other graph into a node acceptable for this graph.</p> * <p> The merge Nodes and edges inserted that way will not erase existing data provided if nodes having same keys are already present.</p> * * <p>The generics are the following : * <ul>//w ww.j a v a 2s. c o m * <li>OIDENT : the class of the key of the other graph</li> * <li>ON : the type definition of a node from the other graph</li> * <li>OG : the type of the other graph </li> * </ul> * </p> * * @param othergraph */ public <OIDENT, ON extends GraphNode<OIDENT, ON>, OG extends LibraryGraph<OIDENT, ON>> void mergeGraph( OG othergraph, NodeTransformer<ON, T> transformer) { LinkedList<ON> processing = new LinkedList<>(othergraph.getOrphans()); Set<ON> processed = new HashSet<>(); while (!processing.isEmpty()) { ON current = processing.pop(); T newParent = transformer.createFrom(current); for (ON child : current.getOutbounds()) { addEdge(newParent, transformer.createFrom(child)); if (!processed.contains(child)) { processing.add(child); processed.add(child); } } // in case the node had no children it might be useful to add itself again addNode(newParent); } }
From source file:org.nanocom.console.input.ArgsInput.java
/** * {@inheritDoc}//from w ww . j a v a2s . c o m */ @Override public Object getParameterOption(List<String> values, Object defaultValue) { LinkedList<String> locTokens = new LinkedList<String>(); locTokens.addAll(tokens); while (!locTokens.isEmpty()) { String token = locTokens.poll(); for (String value : values) { if (value.startsWith(token)) { int pos = token.indexOf("="); if (pos > -1) { return token.substring(pos + 1); } return locTokens.poll(); } } } return defaultValue; }
From source file:alma.acs.nc.sm.generic.AcsScxmlEngine.java
/** * Gets the signals that would trigger transitions for the current state. * <p>//www .ja v a2 s . co m * When actually sending such signals later on, the SM may have moved to a different state. * To prevent this, you can synchronize on this AcsScxmlEngine, which will block concurrent calls to {@link #fireSignal(Enum)}. * <p> * This method can be useful for displaying applicable signals in a GUI, * or to reject signals (with exception etc) that do not "fit" the current state * (while normally such signals would be silently ignored). * The latter gets used in {@link #fireSignalWithErrorFeedback(Enum)}. * * @see org.apache.commons.scxml.semantics.SCXMLSemanticsImpl#enumerateReachableTransitions(SCXML, Step, ErrorReporter) */ public synchronized Set<S> getApplicableSignals() { Set<String> events = new HashSet<String>(); @SuppressWarnings("unchecked") Set<TransitionTarget> stateSet = new HashSet<TransitionTarget>(exec.getCurrentStatus().getStates()); LinkedList<TransitionTarget> todoList = new LinkedList<TransitionTarget>(stateSet); while (!todoList.isEmpty()) { TransitionTarget tt = todoList.removeFirst(); @SuppressWarnings("unchecked") List<Transition> transitions = tt.getTransitionsList(); for (Transition t : transitions) { String event = t.getEvent(); events.add(event); } TransitionTarget parentTT = tt.getParent(); if (parentTT != null && !stateSet.contains(parentTT)) { stateSet.add(parentTT); todoList.addLast(parentTT); } } // convert signal names to enum constants Set<S> ret = new HashSet<S>(); for (String signalName : events) { S signal = Enum.valueOf(signalType, signalName); ret.add(signal); } return ret; }
From source file:org.squashtest.tm.domain.library.structures.LibraryGraph.java
/** * Will remove from this graph any edge that exists in othergraph. If removeAll is * set to true every connection between the source and destination node of such edges * will be removed, is false only their cardinalities will be substracted. * * * @param othergraph//from w ww .j av a 2 s . c o m * @param transformer * @param removeAll */ public <OIDENT, ON extends GraphNode<OIDENT, ON>, OG extends LibraryGraph<OIDENT, ON>> void substractGraph( OG othergraph, NodeTransformer<ON, T> transformer, boolean removeAll) { LinkedList<ON> processing = new LinkedList<>(othergraph.getOrphans()); Set<ON> processed = new HashSet<>(); while (!processing.isEmpty()) { ON otherCurrent = processing.pop(); IDENT thisCurrent = (IDENT) transformer.createKey(otherCurrent); for (ON otherChild : otherCurrent.getOutbounds()) { IDENT thisChild = (IDENT) transformer.createKey(otherChild); if (hasEdge(thisCurrent, thisChild)) { if (removeAll) { removeAllEdges(thisCurrent, thisChild); } else { removeEdge(thisCurrent, thisChild); } } if (!processed.contains(otherChild)) { processing.add(otherChild); processed.add(otherChild); } } } }
From source file:org.openmrs.module.chartsearch.solr.ChartSearchSearcher.java
/** * Adds filter Queries to the query for selected categories returned from the UI * //from w w w. java 2 s. c o m * @param query * @param selectedCats */ public void addSelectedFilterQueriesToQuery(SolrQuery query, List<String> selectedCats) { String filterQuery = ""; LinkedList<String> selectedCategories = new LinkedList<String>(); selectedCategories.addAll(selectedCats); if (selectedCategories == null || selectedCategories.isEmpty()) { } else { LinkedList<CategoryFilter> existingCategories = new LinkedList<CategoryFilter>(); existingCategories.addAll(getChartSearchService().getAllCategoryFilters()); int indexOfFirstSelected = selectedCategories.indexOf(selectedCategories.getFirst()); int indexOfLastSelected = selectedCategories.indexOf(selectedCategories.getLast()); int indexOfFirstExisting = existingCategories.indexOf(existingCategories.getFirst()); int indexOfLastExisting = existingCategories.indexOf(existingCategories.getLast()); for (int i = indexOfFirstSelected; i <= indexOfLastSelected; i++) { String currentSelected = selectedCategories.get(i); for (int j = indexOfFirstExisting; j <= indexOfLastExisting; j++) { CategoryFilter currentExisting = existingCategories.get(j); String currentExistingName = currentExisting.getCategoryName(); if (currentSelected.equals(currentExistingName.toLowerCase())) { if (i != indexOfLastSelected) { filterQuery += currentExisting.getFilterQuery() + " OR "; } else filterQuery += currentExisting.getFilterQuery(); } } } query.addFilterQuery(filterQuery); } }
From source file:org.apache.hadoop.hbase.replication.regionserver.DumpReplicationQueues.java
@Override public int run(String[] args) throws Exception { int errCode = -1; LinkedList<String> argv = new LinkedList<String>(); argv.addAll(Arrays.asList(args)); DumpOptions opts = parseOpts(argv);//from w ww. j a va 2s .c o m // args remaining, print help and exit if (!argv.isEmpty()) { errCode = 0; printUsage(); return errCode; } return dumpReplicationQueues(opts); }
From source file:com.google.blockly.android.codegen.CodeGeneratorService.java
private boolean equivalentLists(List<String> newDefinitions, List<String> oldDefinitions) { LinkedList<String> checkList = new LinkedList<>(oldDefinitions); for (String filename : newDefinitions) { if (!checkList.remove(filename)) { return false; }/*from w ww . j av a 2 s .co m*/ } return checkList.isEmpty(); // If it is empty, all filenames were found / matched. }