List of usage examples for java.util LinkedList getLast
public E getLast()
From source file:cn.keke.travelmix.publictransport.type.EfaConnectionResponseHandler.java
public RouteResult readRouteInfo(LinkedList<PartialRoute> partialRoutes) { String startPoint = partialRoutes.getFirst().getOriginLocation().getName(); String endPoint = partialRoutes.getLast().getDestinationLocation().getName(); long individualTotalDistance = 0; int individualTotalTimeMinute = 0; List<Coordinate> coordinates = new LinkedList<Coordinate>(); List<Instruction> instructions = new LinkedList<Instruction>(); for (PartialRoute partialRoute : partialRoutes) { if (partialRoute.getType() == TransportType.IT) { individualTotalTimeMinute += partialRoute.getTimeMinute(); individualTotalDistance += partialRoute.getDistance(); }/* ww w . j av a 2s . c om*/ LocationPoint originLocation = partialRoute.getOriginLocation(); coordinates.add(originLocation.getCoordinate()); int idx = coordinates.size() - 1; Instruction instruction = createOriginLocationInstruction(partialRoute, originLocation, idx); instructions.add(instruction); if (partialRoute.getType() == TransportType.IT) { for (PathDescription description : partialRoute.getDescriptions()) { instruction = new Instruction(partialRoute.getMot(), createInstruction(description.getDirection(), description.getStreet()), description.getDistance(), description.getCoordIdxFrom() + idx, description.getDuration(), createDistanceText(description.getDistance()), description.getSkyDirection(), description.getDirection()); instructions.add(instruction); // System.out.println(instruction.getInstructionText()); } } coordinates.addAll(partialRoute.getCoordinates()); LocationPoint destinationLocation = partialRoute.getDestinationLocation(); coordinates.add(destinationLocation.getCoordinate()); idx = coordinates.size() - 1; instruction = createDestinationLocationInstruction(partialRoute, destinationLocation, idx); instructions.add(instruction); } long totalDistance = getTotalDistance(coordinates); int totalTimeMinute = getLocationMinutesDiff(partialRoutes.getFirst().getOriginLocation(), partialRoutes.getLast().getDestinationLocation()); RouteResult result = new RouteResult(startPoint, endPoint, totalDistance, totalTimeMinute * 60, individualTotalDistance, individualTotalTimeMinute * 60, coordinates, instructions); return result; }
From source file:org.mycore.common.content.transformer.MCRXSLTransformer.java
@Override public MCRContent transform(MCRContent source, MCRParameterCollector parameter) throws IOException { try {//from w ww . j a va 2 s .c om LinkedList<TransformerHandler> transformHandlerList = getTransformHandlerList(parameter); XMLReader reader = getXMLReader(transformHandlerList); TransformerHandler lastTransformerHandler = transformHandlerList.getLast(); return transform(source, reader, lastTransformerHandler, parameter); } catch (TransformerException e) { throw new IOException(e); } catch (SAXException e) { throw new IOException(e); } }
From source file:org.mycore.common.content.transformer.MCRXSLTransformer.java
@Override public void transform(MCRContent source, OutputStream out, MCRParameterCollector parameter) throws IOException { MCRErrorListener el = null;/*from w ww. j a v a2s . c o m*/ try { LinkedList<TransformerHandler> transformHandlerList = getTransformHandlerList(parameter); XMLReader reader = getXMLReader(transformHandlerList); TransformerHandler lastTransformerHandler = transformHandlerList.getLast(); el = (MCRErrorListener) lastTransformerHandler.getTransformer().getErrorListener(); StreamResult result = new StreamResult(out); lastTransformerHandler.setResult(result); reader.parse(source.getInputSource()); } catch (TransformerConfigurationException e) { throw new IOException(e); } catch (IllegalArgumentException e) { throw new IOException(e); } catch (SAXException e) { throw new IOException(e); } catch (RuntimeException e) { if (el != null && e.getCause() == null && el.getExceptionThrown() != null) { //typically if a RuntimeException has no cause, we can get the "real cause" from MCRErrorListener, yeah!!! throw new IOException(el.getExceptionThrown()); } throw e; } }
From source file:org.wso2.developerstudio.eclipse.gmf.esb.diagram.custom.deserializer.ProxyServiceDeserializer.java
@Override public org.wso2.developerstudio.eclipse.gmf.esb.ProxyService createNode(IGraphicalEditPart editPart, ProxyService object) {//from ww w . j av a 2s. c o m org.wso2.developerstudio.eclipse.gmf.esb.ProxyService proxy = (org.wso2.developerstudio.eclipse.gmf.esb.ProxyService) DeserializerUtils .createNode(editPart, EsbElementTypes.ProxyService_3001); setElementToEdit(proxy); refreshEditPartMap(); executeSetValueCommand(PROXY_SERVICE__NAME, object.getName()); // Fixing TOOLS-2033. if (object.getTraceState() == 1) { executeSetValueCommand(PROXY_SERVICE__TRACE_ENABLED, new Boolean(true)); } else { executeSetValueCommand(PROXY_SERVICE__TRACE_ENABLED, new Boolean(false)); } //Fixing TOOLS-2735 StatisticsConfigurable statisticsConfigurable = object.getAspectConfiguration(); if (statisticsConfigurable != null && statisticsConfigurable.isStatisticsEnable()) { executeSetValueCommand(PROXY_SERVICE__STATISTICS_ENABLED, new Boolean(true)); } else { executeSetValueCommand(PROXY_SERVICE__STATISTICS_ENABLED, new Boolean(false)); } executeSetValueCommand(PROXY_SERVICE__START_ON_LOAD, object.isStartOnLoad()); boolean hasPublishWsdl = true; if (object.getWsdlURI() != null) { executeSetValueCommand(PROXY_SERVICE__WSDL_TYPE, ProxyWsdlType.SOURCE_URL); executeSetValueCommand(PROXY_SERVICE__WSDL_URL, object.getWsdlURI().toString()); } else if (object.getWSDLKey() != null) { executeSetValueCommand(PROXY_SERVICE__WSDL_TYPE, ProxyWsdlType.REGISTRY_KEY); RegistryKeyProperty keyProperty = EsbFactory.eINSTANCE.createRegistryKeyProperty(); keyProperty.setKeyValue(object.getWSDLKey()); executeSetValueCommand(PROXY_SERVICE__WSDL_KEY, keyProperty); } else if (object.getInLineWSDL() != null) { executeSetValueCommand(PROXY_SERVICE__WSDL_TYPE, ProxyWsdlType.INLINE); executeSetValueCommand(PROXY_SERVICE__WSDL_XML, object.getInLineWSDL().toString()); } else if (object.getPublishWSDLEndpoint() != null) { executeSetValueCommand(PROXY_SERVICE__WSDL_TYPE, ProxyWsdlType.ENDPOINT); RegistryKeyProperty keyProperty = EsbFactory.eINSTANCE.createRegistryKeyProperty(); keyProperty.setKeyValue(object.getPublishWSDLEndpoint()); executeSetValueCommand(PROXY_SERVICE__WSDL_ENDPOINT, keyProperty); } else { executeSetValueCommand(PROXY_SERVICE__WSDL_TYPE, ProxyWsdlType.NONE); hasPublishWsdl = false; } Endpoint targetInLineEndpoint = object.getTargetInLineEndpoint(); if (targetInLineEndpoint != null) { setHasInlineEndPoint(true); } else if (StringUtils.isNotBlank(object.getTargetEndpoint())) { setHasInlineEndPoint(true); } if (hasPublishWsdl && object.getResourceMap() != null) { Map<String, String> resourcesMap = object.getResourceMap().getResources(); EList<ProxyWSDLResource> wsdlResourceList = new BasicEList<ProxyWSDLResource>(); for (Entry<String, String> entry : resourcesMap.entrySet()) { ProxyWSDLResource resource = EsbFactory.eINSTANCE.createProxyWSDLResource(); resource.getKey().setKeyValue(entry.getValue()); resource.setLocation(entry.getKey()); wsdlResourceList.add(resource); } executeSetValueCommand(PROXY_SERVICE__WSDL_RESOURCES, wsdlResourceList); } if (object.getTransports() != null && object.getTransports().size() > 0) { executeSetValueCommand(PROXY_SERVICE__TRANSPORTS, DeserializerUtils.join(object.getTransports(), ",")); } if (object.getServiceGroup() != null) { executeSetValueCommand(PROXY_SERVICE__SERVICE_GROUP, object.getServiceGroup()); } if (object.getPinnedServers().size() > 0) { executeSetValueCommand(PROXY_SERVICE__PINNED_SERVERS, DeserializerUtils.join(object.getPinnedServers(), ",")); } executeSetValueCommand(PROXY_SERVICE__SECURITY_ENABLED, object.isWsSecEnabled()); executeSetValueCommand(PROXY_SERVICE__RELIABLE_MESSAGING_ENABLED, object.isWsRMEnabled()); EList<ProxyServiceParameter> parameters = new BasicEList<ProxyServiceParameter>(); for (Map.Entry<String, Object> entry : object.getParameterMap().entrySet()) { ProxyServiceParameter parameter = EsbFactory.eINSTANCE.createProxyServiceParameter(); parameter.setName(entry.getKey()); parameter.setValue(entry.getValue().toString()); parameters.add(parameter); } if (parameters.size() > 0) { executeSetValueCommand(PROXY_SERVICE__SERVICE_PARAMETERS, parameters); } EList<ProxyServicePolicy> policies = new BasicEList<ProxyServicePolicy>(); for (PolicyInfo entry : object.getPolicies()) { ProxyServicePolicy policy = EsbFactory.eINSTANCE.createProxyServicePolicy(); policy.getPolicyKey().setKeyValue(entry.getPolicyKey()); policies.add(policy); } if (policies.size() > 0) { executeSetValueCommand(PROXY_SERVICE__SERVICE_POLICIES, policies); } addRootInputConnector(proxy.getInputConnector()); MediatorFlow mediatorFlow = proxy.getContainer().getSequenceAndEndpointContainer().getMediatorFlow(); SequenceMediator inSequence = object.getTargetInLineInSequence(); GraphicalEditPart compartment = (GraphicalEditPart) ((getEditpart(mediatorFlow)).getChildren().get(0)); setRootCompartment(compartment); if (inSequence != null) { if (StringUtils.isNotBlank(inSequence.getErrorHandler())) { RegistryKeyProperty inSeqOnErrorKeyProperty = EsbFactory.eINSTANCE.createRegistryKeyProperty(); inSeqOnErrorKeyProperty.setKeyValue(inSequence.getErrorHandler()); executeSetValueCommand(PROXY_SERVICE__IN_SEQUENCE_ON_ERROR, inSeqOnErrorKeyProperty); } deserializeSequence(compartment, inSequence, proxy.getOutputConnector()); } else { String inSequenceName = object.getTargetInSequence(); if (inSequenceName != null) { if (inSequenceName.startsWith("/") || inSequenceName.startsWith("conf:") || inSequenceName.startsWith("gov:")) { executeSetValueCommand(PROXY_SERVICE__IN_SEQUENCE_TYPE, SequenceType.REGISTRY_REFERENCE); RegistryKeyProperty keyProperty = EsbFactory.eINSTANCE.createRegistryKeyProperty(); keyProperty.setKeyValue(inSequenceName); executeSetValueCommand(PROXY_SERVICE__IN_SEQUENCE_KEY, keyProperty); } else { executeSetValueCommand(PROXY_SERVICE__IN_SEQUENCE_TYPE, SequenceType.NAMED_REFERENCE); executeSetValueCommand(PROXY_SERVICE__IN_SEQUENCE_NAME, inSequenceName); } } } /*if(object.getTargetInLineEndpoint() == null){ String endpointName = object.getTargetEndpoint(); if(StringUtils.isNotBlank(endpointName)){ if(endpointName.startsWith("/") || endpointName.startsWith("conf:") || endpointName.startsWith("gov:")){ executeSetValueCommand(PROXY_SERVICE__ENDPOINT_TYPE, SequenceType.REGISTRY_REFERENCE); RegistryKeyProperty keyProperty = EsbFactory.eINSTANCE.createRegistryKeyProperty(); keyProperty.setKeyValue(endpointName); executeSetValueCommand(PROXY_SERVICE__ENDPOINT_KEY, keyProperty); } else{ executeSetValueCommand(PROXY_SERVICE__ENDPOINT_TYPE, SequenceType.NAMED_REFERENCE); executeSetValueCommand(PROXY_SERVICE__ENDPOINT_NAME, endpointName); } } }*/ if (hasInlineEndPoint()) { if (object.getTargetEndpoint() != null) { IndirectEndpoint indirectEndpoint = new IndirectEndpoint(); indirectEndpoint.setKey(object.getTargetEndpoint()); targetInLineEndpoint = indirectEndpoint; } @SuppressWarnings("rawtypes") IEsbNodeDeserializer deserializer = EsbDeserializerRegistry.getInstance() .getDeserializer(targetInLineEndpoint); if (deserializer != null) { LinkedList<EsbNode> connectionFlow = getConnectionFlow(proxy.getOutputConnector()); if (connectionFlow.size() > 0 && connectionFlow.getLast() instanceof SendMediator) { EditPart sendMediatorFlow = getEditpart( ((SendMediator) connectionFlow.getLast()).getMediatorFlow()); @SuppressWarnings("unchecked") EndPoint endPointModel = (EndPoint) deserializer.createNode( (IGraphicalEditPart) sendMediatorFlow.getChildren().get(0), targetInLineEndpoint); executeSetValueCommand(endPointModel, END_POINT__IN_LINE, true); connectionFlow.add(endPointModel); } else { SendMediator sendModel = (SendMediator) DeserializerUtils.createNode(getRootCompartment(), EsbElementTypes.SendMediator_3515); executeSetValueCommand(sendModel, SEND_MEDIATOR__SKIP_SERIALIZATION, true); refreshEditPartMap(); EditPart sendMediatorFlow = getEditpart(sendModel.getMediatorFlow()); connectionFlow.add(sendModel); @SuppressWarnings("unchecked") EndPoint endPointModel = (EndPoint) deserializer.createNode( (IGraphicalEditPart) sendMediatorFlow.getChildren().get(0), targetInLineEndpoint); executeSetValueCommand(endPointModel, END_POINT__IN_LINE, true); connectionFlow.add(endPointModel); } } } setHasInlineEndPoint(false); setRootCompartment(null); setAddedAddressingEndPoint(false); SequenceMediator outSequence = object.getTargetInLineOutSequence(); if (outSequence != null) { setRootCompartment(compartment); if (StringUtils.isNotBlank(outSequence.getErrorHandler())) { RegistryKeyProperty outSeqOnErrorKeyProperty = EsbFactory.eINSTANCE.createRegistryKeyProperty(); outSeqOnErrorKeyProperty.setKeyValue(outSequence.getErrorHandler()); executeSetValueCommand(PROXY_SERVICE__OUT_SEQUENCE_ON_ERROR, outSeqOnErrorKeyProperty); } deserializeSequence(compartment, outSequence, proxy.getInputConnector()); setRootCompartment(null); } else { String outSequenceName = object.getTargetOutSequence(); if (outSequenceName != null) { if (outSequenceName.startsWith("/") || outSequenceName.startsWith("conf:") || outSequenceName.startsWith("gov:")) { executeSetValueCommand(PROXY_SERVICE__OUT_SEQUENCE_TYPE, SequenceType.REGISTRY_REFERENCE); RegistryKeyProperty keyProperty = EsbFactory.eINSTANCE.createRegistryKeyProperty(); keyProperty.setKeyValue(outSequenceName); executeSetValueCommand(PROXY_SERVICE__OUT_SEQUENCE_KEY, keyProperty); } else { executeSetValueCommand(PROXY_SERVICE__OUT_SEQUENCE_TYPE, SequenceType.NAMED_REFERENCE); executeSetValueCommand(PROXY_SERVICE__OUT_SEQUENCE_NAME, outSequenceName); } } deserializeSequence(compartment, new SequenceMediator(), proxy.getInputConnector()); } SequenceMediator faultSequence = object.getTargetInLineFaultSequence(); MediatorFlow faultmediatorFlow = proxy.getContainer().getFaultContainer().getMediatorFlow(); GraphicalEditPart faultCompartment = (GraphicalEditPart) ((getEditpart(faultmediatorFlow)).getChildren() .get(0)); if (faultSequence != null) { setRootCompartment(compartment); if (StringUtils.isNotBlank(faultSequence.getErrorHandler())) { RegistryKeyProperty faultSeqOnErrorKeyProperty = EsbFactory.eINSTANCE.createRegistryKeyProperty(); faultSeqOnErrorKeyProperty.setKeyValue(faultSequence.getErrorHandler()); executeSetValueCommand(PROXY_SERVICE__FAULT_SEQUENCE_ON_ERROR, faultSeqOnErrorKeyProperty); } deserializeSequence(faultCompartment, faultSequence, proxy.getFaultInputConnector()); setRootCompartment(null); } else { String faultSequenceName = object.getTargetFaultSequence(); if (faultSequenceName != null) { if (faultSequenceName.startsWith("/") || faultSequenceName.startsWith("conf:") || faultSequenceName.startsWith("gov:")) { executeSetValueCommand(PROXY_SERVICE__FAULT_SEQUENCE_TYPE, SequenceType.REGISTRY_REFERENCE); RegistryKeyProperty keyProperty = EsbFactory.eINSTANCE.createRegistryKeyProperty(); keyProperty.setKeyValue(faultSequenceName); executeSetValueCommand(PROXY_SERVICE__FAULT_SEQUENCE_KEY, keyProperty); } else { executeSetValueCommand(PROXY_SERVICE__FAULT_SEQUENCE_TYPE, SequenceType.NAMED_REFERENCE); executeSetValueCommand(PROXY_SERVICE__FAULT_SEQUENCE_NAME, faultSequenceName); } } deserializeSequence(faultCompartment, new SequenceMediator(), proxy.getFaultInputConnector()); } addPairMediatorFlow(proxy.getOutputConnector(), proxy.getInputConnector()); //TODO : deserialize other properties return proxy; }
From source file:ml.dmlc.xgboost4j.java.NativeLibraryLoaderChain.java
@Override public void loadNativeLibs() throws IOException { LinkedList<IOException> exs = new LinkedList<>(); for (NativeLibrary lib : nativeLibs) { try {// w ww .j av a2 s . co m // Try to load if (lib.load()) { // It was successful load, so remember it successfullyLoaded = lib; break; } } catch (IOException e) { logger.info("Cannot load library: " + lib.toString()); exs.add(e); } } if ((successfullyLoaded == null) && (!exs.isEmpty())) { throw new IOException(exs.getLast()); } }
From source file:net.relet.freimap.LinkInfo.java
public void setLinkProfile(LinkedList<LinkData> lp) { XYSeries data = new XYSeries("etx"); XYSeries avail = new XYSeries("avail"); XYSeriesCollection datac = new XYSeriesCollection(data); datac.addSeries(avail);//w ww . ja v a 2 s. com linkChart = ChartFactory.createXYLineChart("average link etx\r\naverage link availability", "time", "etx", datac, PlotOrientation.VERTICAL, false, false, false); sexupLayout(linkChart); long first = lp.getFirst().time, last = lp.getLast().time, lastClock = first, count = 0, //number of samplis in aggregation timespan maxCount = 0; //max idem long aggregate = (last - first) / CHART_WIDTH; //calculate aggregation timespan: divide available timespan in CHART_WIDTH equal chunks double sum = 0; /* ok, this ain't effective, we do it just to pre-calculate maxCount */ ListIterator<LinkData> li = lp.listIterator(); while (li.hasNext()) { LinkData ld = li.next(); count++; if (ld.time - lastClock > aggregate) { if (maxCount < count) maxCount = count; lastClock = ld.time; count = 0; } } //reset for second iteration count = 0; lastClock = first; //iterate again li = lp.listIterator(); while (li.hasNext()) { LinkData ld = li.next(); sum += ld.quality; count++; if (aggregate == 0) aggregate = 1000;//dirty hack if (ld.time - lastClock > aggregate) { for (long i = lastClock; i < ld.time - aggregate; i += aggregate) { data.add(i * 1000, (i == lastClock) ? sum / count : Double.NaN); avail.add(i * 1000, (i == lastClock) ? ((double) count / maxCount) : 0); } count = 0; sum = 0; lastClock = ld.time; } } status = STATUS_AVAILABLE; }
From source file:nl.strohalm.cyclos.services.transfertypes.AuthorizationLevelServiceImpl.java
private AuthorizationLevel getLowerLevel(final AuthorizationLevel authorizationLevel) { final TransferType transferType = authorizationLevel.getTransferType(); final LinkedList<AuthorizationLevel> authorizationLevels = new LinkedList<AuthorizationLevel>( transferType.getAuthorizationLevels()); if (CollectionUtils.isEmpty(authorizationLevels)) { return null; }/*from w w w .j a v a2 s . com*/ final Integer currentLevel = authorizationLevel.getLevel(); if (currentLevel == null) { // We are inserting a new authorization level, the lower level is the highest level saved return authorizationLevels.getLast(); } else { // We are updating a saved authorization level if (currentLevel == 1 || authorizationLevels.size() == 1) { return null; } // List indexes start with 0 return authorizationLevels.get(currentLevel - 2); } }
From source file:net.relet.freimap.NodeInfo.java
public void setLinkCountProfile(LinkedList<LinkCount> lcp) { if (lcp.size() == 0) { minLinks = 0;/*from w w w. j ava 2 s .c o m*/ maxLinks = 0; return; } XYSeries data = new XYSeries("links"); XYSeries avail = new XYSeries("avail"); XYSeriesCollection datac = new XYSeriesCollection(data); datac.addSeries(avail); linkCountChart = ChartFactory.createXYLineChart("average incoming link count\r\nincoming link availability", "time", "count", datac, PlotOrientation.VERTICAL, false, false, false); sexupLayout(linkCountChart); long first = lcp.getFirst().time, last = lcp.getLast().time, lastClock = first, count = 0, maxCount = 0; long aggregate = (last - first) / CHART_WIDTH; double sum = 0; /* ok, this ain't effective, we do it just to pre-calculate maxCount */ ListIterator<LinkCount> li = lcp.listIterator(); while (li.hasNext()) { LinkCount lc = li.next(); count++; if (lc.time - lastClock > aggregate) { if (maxCount < count) maxCount = count; lastClock = lc.time; count = 0; } } //reset for second iteration count = 0; lastClock = first; //iterate again li = lcp.listIterator(); while (li.hasNext()) { LinkCount lc = li.next(); if (minLinks > lc.count) minLinks = lc.count; if (maxLinks < lc.count) maxLinks = lc.count; sum += lc.count; count++; if (aggregate == 0) aggregate = 1000;//dirty hack if (lc.time - lastClock > aggregate) { for (long i = lastClock; i < lc.time - aggregate; i += aggregate) { data.add(i * 1000, (i == lastClock) ? sum / count : Double.NaN); avail.add(i * 1000, (i == lastClock) ? ((double) count / maxCount) : 0); } count = 0; sum = 0; lastClock = lc.time; } } status = STATUS_AVAILABLE; }
From source file:net.sourceforge.fenixedu.domain.reports.FlunkedReportFile.java
@Override public void renderReport(Spreadsheet spreadsheet) { spreadsheet.setHeader("nmero aluno"); spreadsheet.setHeader("ciclo estudos"); setDegreeHeaders(spreadsheet);/*from ww w. j ava 2s. co m*/ for (final Degree degree : Degree.readNotEmptyDegrees()) { if (checkDegreeType(getDegreeType(), degree)) { for (final Registration registration : degree.getRegistrationsSet()) { LinkedList<RegistrationState> states = new LinkedList<RegistrationState>(); states.addAll(registration.getRegistrationStatesSet()); CollectionUtils.filter(states, new Predicate() { @Override public boolean evaluate(Object item) { return ((RegistrationState) item).getExecutionYear() != null && ((RegistrationState) item).getExecutionYear().equals(getExecutionYear()); } }); Collections.sort(states, RegistrationState.DATE_COMPARATOR); if (!states.isEmpty() && states.getLast().getStateType().equals(RegistrationStateType.FLUNKED)) { final Row row = spreadsheet.addRow(); row.setCell(registration.getNumber()); CycleType cycleType = registration.getCycleType(states.getLast().getExecutionYear()); row.setCell(cycleType != null ? cycleType.toString() : ""); setDegreeCells(row, degree); } } } } }
From source file:org.gradle.integtests.fixtures.executer.OutputScrapingExecutionResult.java
private List<String> grepTasks(final Pattern pattern) { final LinkedList<String> tasks = new LinkedList<String>(); eachLine(new Action<String>() { public void execute(String s) { java.util.regex.Matcher matcher = pattern.matcher(s); if (matcher.matches()) { String taskName = matcher.group(1); if (!taskName.startsWith(":buildSrc:")) { //for INFO/DEBUG level the task may appear twice - once for the execution, once for the UP-TO-DATE //so I'm not adding the task to the list if it is the same as previously added task. if (tasks.size() == 0 || !tasks.getLast().equals(taskName)) { tasks.add(taskName); }/* w ww .jav a 2 s .com*/ } } } }); return tasks; }