Java Code Examples for java.util.ListIterator.hasNext()

The following are Jave code examples for showing how to use hasNext() of the java.util.ListIterator class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OpenJSharp   File: AuthCacheImpl.java   View Source Code Vote up 6 votes
public synchronized void remove (String pkey, AuthCacheValue entry) {
    LinkedList<AuthCacheValue> list = hashtable.get (pkey);
    if (list == null) {
        return;
    }
    if (entry == null) {
        list.clear();
        return;
    }
    ListIterator<AuthCacheValue> iter = list.listIterator ();
    while (iter.hasNext()) {
        AuthenticationInfo inf = (AuthenticationInfo)iter.next();
        if (entry.equals(inf)) {
            iter.remove ();
        }
    }
}
 
Example 2
Project: athena   File: PortChainSfMapManager.java   View Source Code Vote up 6 votes
@Override
public List<ServiceFunctionGroup> getServiceFunctions(PortChainId portChainId) {
    List<ServiceFunctionGroup> serviceFunctionGroupList = Lists.newArrayList();
    PortChain portChain = portChainService.getPortChain(portChainId);
    // Go through the port pair group list
    List<PortPairGroupId> portPairGrpList = portChain.portPairGroups();
    ListIterator<PortPairGroupId> listGrpIterator = portPairGrpList.listIterator();

    while (listGrpIterator.hasNext()) {
        PortPairGroupId portPairGroupId = listGrpIterator.next();
        PortPairGroup portPairGroup = portPairGroupService.getPortPairGroup(portPairGroupId);
        ServiceFunctionGroup sfg = new ServiceFunctionGroup(portPairGroup.name(), portPairGroup.description(),
                                                            portPairGroup.portPairLoadMap());
        serviceFunctionGroupList.add(sfg);
    }
    return ImmutableList.copyOf(serviceFunctionGroupList);
}
 
Example 3
Project: RNLearn_Project1   File: NativeAnimatedNodesManager.java   View Source Code Vote up 6 votes
public void removeAnimatedEventFromView(int viewTag, String eventName, int animatedValueTag) {
  String key = viewTag + eventName;
  if (mEventDrivers.containsKey(key)) {
    List<EventAnimationDriver> driversForKey = mEventDrivers.get(key);
    if (driversForKey.size() == 1) {
      mEventDrivers.remove(viewTag + eventName);
    } else {
      ListIterator<EventAnimationDriver> it = driversForKey.listIterator();
      while (it.hasNext()) {
        if (it.next().mValueNode.mTag == animatedValueTag) {
          it.remove();
          break;
        }
      }
    }
  }
}
 
Example 4
Project: openjdk-jdk10   File: ConsoleReader.java   View Source Code Vote up 6 votes
public int searchForwards(String searchTerm, int startIndex, boolean startsWith) {
    if (startIndex >= history.size()) {
        startIndex = history.size() - 1;
    }

    ListIterator<History.Entry> it = history.entries(startIndex);

    if (searchIndex != -1 && it.hasNext()) {
        it.next();
    }

    while (it.hasNext()) {
        History.Entry e = it.next();
        if (startsWith) {
            if (e.value().toString().startsWith(searchTerm)) {
                return e.index();
            }
        } else {
            if (e.value().toString().contains(searchTerm)) {
                return e.index();
            }
        }
    }
    return -1;
}
 
Example 5
Project: incubator-netbeans   File: ActiveRegion.java   View Source Code Vote up 6 votes
void cull(int origin) {

        // See RegionManager.cull() for culling strategy.
        // This function isn't recursive. It's called only once on root.

        if (children == null) {
            return;
        }

        int nculled = 0;

        ListIterator<ActiveRegion> iter = children.listIterator();
        while (iter.hasNext()) {
            ActiveRegion child = iter.next();
            if (child.begin.row < origin) {
                iter.remove();
                nculled++;
            } else {
                break;	// short circuit out
            }
        }

    // System.out.println("cull'ed " + nculled + " regions");	// NOI18N
    }
 
Example 6
Project: athena   File: PcepRroObjectVer1.java   View Source Code Vote up 5 votes
@Override
public int write(ChannelBuffer cb) throws PcepParseException {
    //write Object header
    int objStartIndex = cb.writerIndex();

    int objLenIndex = rroObjHeader.write(cb);

    if (objLenIndex <= 0) {
        throw new PcepParseException(" object Length Index" + objLenIndex);
    }

    ListIterator<PcepValueType> listIterator = llSubObjects.listIterator();

    while (listIterator.hasNext()) {
        listIterator.next().write(cb);
    }

    //Update object length now
    int length = cb.writerIndex() - objStartIndex;
    cb.setShort(objLenIndex, (short) length);
    //will be helpful during print().
    rroObjHeader.setObjLen((short) length);

    //As per RFC the length of object should be multiples of 4
    int pad = length % 4;

    if (0 != pad) {
        pad = 4 - pad;
        for (int i = 0; i < pad; i++) {
            cb.writeByte((byte) 0);
        }
        length = length + pad;
    }
    objLenIndex = cb.writerIndex();
    return objLenIndex;
}
 
Example 7
Project: jmt   File: NetController.java   View Source Code Vote up 5 votes
/** This is the run method of the NetController (thread). */
public void run() throws InterruptedException, NetException {
	SimSystem.runStart();
	startTime = NetSystem.getElapsedTime();

	while (SimSystem.runTick()) {
		synchronized (this) {
			//the presence of this "if" allows pause control
			if (blocked) {
				wait();
			}
			n++;

			if (n % refreshPeriod == 0) {
				//User may have defined measures that will not receive any sample
				if (n % reachabilityTest == 0) {
					//stop measures which have not collected samples yet
					NetSystem.stopNoSamplesMeasures();
				}
				//refresh measures
				NetSystem.checkMeasures();
			}
			//check if a positive max simulated time is set and has been reached for the first time
			if (maxSimulatedTime > 0 && SimSystem.getClock() > maxSimulatedTime && !aborting) {
				ListIterator<QueueNetwork> nets = NetSystem.getNetworkList().listIterator();
				QueueNetwork network;
				while (nets.hasNext()) {
					network = nets.next();
					network.abortAllMeasures();
					aborting = true;
				}
				NetSystem.checkMeasures(); //refresh measures, this triggers a simulation stop because all measures have been aborted
			}
		}
	}
	//sim is finished: get stop time
	stopTime = NetSystem.getElapsedTime();
	SimSystem.runStop();
	running = false;
}
 
Example 8
Project: visuflow-plugin   File: GraphManager.java   View Source Code Vote up 5 votes
/**
 * Renders the method CFG, sets the {@link #CFG} to true and pans the graph to the first node of the graph based on the value of {@code panToNode}.
 *
 * @param cfg
 * @param panToNode
 * @throws Exception
 * @author Shashank B S
 */
private void renderMethodCFG(ControlFlowGraph cfg, boolean panToNode) throws Exception {
	if (cfg == null)
		throw new Exception("GraphStructure is null");

	this.reintializeGraph();
	ListIterator<VFEdge> edgeIterator = cfg.listEdges.listIterator();

	while (edgeIterator.hasNext()) {
		VFEdge currEdgeIterator = edgeIterator.next();

		VFNode src = currEdgeIterator.getSource();
		VFNode dest = currEdgeIterator.getDestination();

		createControlFlowGraphNode(src);
		createControlFlowGraphNode(dest);
		createControlFlowGraphEdge(src, dest);
	}
	if (cfg.listEdges.size() == 1) {
		VFNode node = cfg.listNodes.get(0);
		createControlFlowGraphNode(node);
	}
	this.CFG = true;
	experimentalLayout();

	if (panToNode) {
		defaultPanZoom();
		panToNode(graph.getNodeIterator().next().getId());
	}
	this.header.setText("Method CFG ----> " + ServiceUtil.getService(DataModel.class).getSelectedMethod().toString());
}
 
Example 9
Project: r8   File: IRCode.java   View Source Code Vote up 5 votes
public void removeMarkedBlocks() {
  ListIterator<BasicBlock> blockIterator = listIterator();
  while (blockIterator.hasNext()) {
    BasicBlock block = blockIterator.next();
    if (block.isMarked()) {
      blockIterator.remove();
      if (block == normalExitBlock) {
        normalExitBlock = null;
      }
    }
  }
}
 
Example 10
Project: bibliome-java-utils   File: Matcher.java   View Source Code Vote up 5 votes
/**
 * Matches the specified character.
 * @param c
 */
public void matchChar(char c) {
	if (end.accept(last, c))
		endMatches();
	if (charPos)
		position++;
	if (start.accept(last, c))
		startMatch();
	if (!filter.accept(last, c)) {
		last = c;
		return;
	}
	ListIterator<Match<T>> lit = pending.listIterator();
	while (lit.hasNext()) {
		Match<T> m = lit.next();
		char mc = mapper.map(last, c);
		State<T> s = m.getState().getChild(mc);
		if (s == null)
			lit.remove();
		else {
			if (visitedStates != null)
				visitedStates.add(s);
			m.setState(s);
		}
	}
	last = c;
}
 
Example 11
Project: GitHub   File: Code.java   View Source Code Vote up 5 votes
static List<Term> trimLeadingIndent(List<Term> code) {
  ArrayList<Term> result = new ArrayList<>(code);
  ListIterator<Term> it = result.listIterator();
  while (it.hasNext()) {
    Term t = it.next();
    if (t.isWhitespace()) {
      String whitespace = t.toString();
      int indexOf = whitespace.indexOf('\n');
      if (indexOf >= 0) {
        it.set(new Whitespace(whitespace.substring(0, indexOf + 1)));
      }
    }
  }
  return result;
}
 
Example 12
Project: iTAP-controller   File: DHCPTest.java   View Source Code Vote up 5 votes
public void testDeSerializeBad1() {
    Ethernet eth = new Ethernet();
    eth.deserialize(dhcpPacketBadOption1, 0, dhcpPacketBadOption1.length);
    assertTrue(eth.getPayload() instanceof IPv4);
    IPv4 ipv4 = (IPv4) eth.getPayload();
    assertTrue(ipv4.getPayload() instanceof UDP);
    UDP udp = (UDP) ipv4.getPayload();
    assertTrue(udp.getPayload() instanceof DHCP);
    DHCP dhcp = (DHCP) udp.getPayload();
    /** The invalid option in DHCP packet is dropped. Reset checksums and
     *  length field so that the serialize() function can re-compute them
     */
    resetChecksumsAndLengths(ipv4, udp);
    
    assertEquals(DHCP.OPCODE_REPLY, dhcp.getOpCode());
    ListIterator<DHCPOption> lit = dhcp.getOptions().listIterator();
    // Expect 5 correct options and an END option.
    assertEquals(dhcp.getOptions().size(), 6);
    while (lit.hasNext()) {
        DHCPOption option = lit.next();
        assertFalse(option.code == (byte)0x0c);
    }

    byte[] result = eth.serialize();
    // Since one option is badly formated, the result is different.
    assertFalse(Arrays.equals(this.dhcpPacketPXE, result));
}
 
Example 13
Project: guava-mock   File: LinkedListMultimap.java   View Source Code Vote up 5 votes
/**
 * {@inheritDoc}
 *
 * <p>If any entries for the specified {@code key} already exist in the
 * multimap, their values are changed in-place without affecting the iteration
 * order.
 *
 * <p>The returned list is immutable and implements
 * {@link java.util.RandomAccess}.
 */
@CanIgnoreReturnValue
@Override
public List<V> replaceValues(@Nullable K key, Iterable<? extends V> values) {
  List<V> oldValues = getCopy(key);
  ListIterator<V> keyValues = new ValueForKeyIterator(key);
  Iterator<? extends V> newValues = values.iterator();

  // Replace existing values, if any.
  while (keyValues.hasNext() && newValues.hasNext()) {
    keyValues.next();
    keyValues.set(newValues.next());
  }

  // Remove remaining old values, if any.
  while (keyValues.hasNext()) {
    keyValues.next();
    keyValues.remove();
  }

  // Add remaining new values, if any.
  while (newValues.hasNext()) {
    keyValues.add(newValues.next());
  }

  return oldValues;
}
 
Example 14
Project: nifi-nars   File: PutScp.java   View Source Code Vote up 5 votes
@Override
public void onTrigger(final ProcessContext context, final ProcessSession processSession) {
    List<FlowFile> flowFiles = processSession.get(batchSize);
    if (flowFiles.isEmpty()) {
        return;
    }

    Session jschSession = null;
    Channel channel = null;
    try {
        jschSession = openSession(context);
        final String remotePath = context.getProperty(REMOTE_PATH).evaluateAttributeExpressions().getValue();
        channel = openExecChannel(context, jschSession, "scp -r -d -t " + remotePath);

        InputStream channelIn = channel.getInputStream();
        OutputStream channelOut = channel.getOutputStream();

        channel.connect();
        waitForAck(channelIn);

        ListIterator<FlowFile> fileIt = flowFiles.listIterator();
        while (fileIt.hasNext()) {
            final FlowFile flowFile = fileIt.next();

            // conditionally reject files that are zero bytes or less
            if (context.getProperty(REJECT_ZERO_BYTE).asBoolean() && flowFile.getSize() == 0) {
                logger.warn("Rejecting {} because it is zero bytes", new Object[]{flowFile});
                processSession.transfer(processSession.penalize(flowFile), REL_REJECT);
                fileIt.remove();
                continue;
            }

            final String filename = flowFile.getAttribute(CoreAttributes.FILENAME.key());
            final String permissions = context.getProperty(PERMISSIONS).evaluateAttributeExpressions(flowFile).getValue();

            // destination path + filename
            // final String fullPath = buildFullPath(context, flowFile, filename);

            processSession.read(flowFile, new InputStreamCallback() {
                @Override
                public void process(final InputStream flowFileIn) throws IOException {
                    // send "C0644 filesize filename", where filename should not include '/'
                    StringBuilder command = new StringBuilder("C").append(permissions).append(' ');
                    command.append(flowFile.getSize()).append(' ');
                    command.append(filename).append('\n');

                    channelOut.write(command.toString().getBytes(StandardCharsets.UTF_8));
                    channelOut.flush();
                    waitForAck(channelIn);

                    IOUtils.copy(flowFileIn, channelOut);
                    channelOut.flush();
                    sendAck(channelOut);
                    waitForAck(channelIn);
                }
            });

            processSession.transfer(flowFile, REL_SUCCESS);
            processSession.getProvenanceReporter().send(flowFile, remotePath);
            fileIt.remove();
            if (logger.isDebugEnabled()) {
                logger.debug("Sent {} to remote host", new Object[]{flowFile});
            }
        }

    } catch (JSchException | IOException ex) {
        context.yield();
        logger.error("Unable to create session to remote host due to {}", new Object[]{ex}, ex);
        processSession.transfer(flowFiles, REL_FAILURE);

    } finally {
        if (channel != null) {
            channel.disconnect();
        }
        if (jschSession != null) {
            jschSession.disconnect();
        }
    }
}
 
Example 15
Project: incubator-netbeans   File: CssParser.java   View Source Code Vote up 5 votes
private static void filterProblemsInVirtualCode(Snapshot snapshot, List<ProblemDescription> problems) {
    ListIterator<ProblemDescription> listIterator = problems.listIterator();
    while (listIterator.hasNext()) {
        ProblemDescription p = listIterator.next();
        int from = p.getFrom();
        int to = p.getTo();
        if (snapshot.getOriginalOffset(from) == -1 || snapshot.getOriginalOffset(to) == -1) {
            listIterator.remove();
        }
    }
}
 
Example 16
Project: QN-ACTR-Release   File: NetNode.java   View Source Code Vote up 5 votes
/** Sends a message to a section of all the NetNodes of the QueueNetwork.
 * @param Event Event tag.
 * @param Data  Data to be attached to the message.
 * @param Delay Scheduling delay.
 * @param SourceSection The source section.
 * @param DestinationSection The destination section.
 * @param NodeType Type of the node (reference or not: see constants in QueueNetwork).
 * @throws jmt.common.exception.NetException Exception
 */
void sendBroadcast(int Event, Object Data, double Delay, byte SourceSection, byte DestinationSection, int NodeType)
		throws jmt.common.exception.NetException {
	int Tag;
	ListIterator<NetNode> iterator;
	if ((Event == NetEvent.EVENT_JOB) || (Event == NetEvent.EVENT_ACK)) {
		throw new jmt.common.exception.NetException(this, EXCEPTION_UNABLE_TO_BROADCAST, "message could not be broadcasted.");
	}
	Tag = Event & NetEvent.EVENT_MASK;
	Tag += SourceSection << NodeSection.SOURCE_SHIFT;
	Tag += DestinationSection << NodeSection.DESTINATION_SHIFT;

	switch (NodeType) {
		case QueueNetwork.REFERENCE_NODE:
			iterator = Network.getReferenceNodes().listIterator();
			while (iterator.hasNext()) {
				//					Entity.sim_schedule(((NetNode) Iterator.next()).Entity.get_id(), Delay, Tag, Data);
				simSchedule(iterator.next().getId(), Delay, Tag, Data);
			}
			break;
		case QueueNetwork.NODE:
			//@3G           Iterator=Network.getReferenceNodes().listIterator();
			iterator = Network.getNodes().listIterator();
			while (iterator.hasNext()) {
				//					Entity.sim_schedule(((NetNode) Iterator.next()).Entity.get_id(), Delay, Tag, Data);
				simSchedule(iterator.next().getId(), Delay, Tag, Data);
			}
			break;
	}
}
 
Example 17
Project: ReadMark   File: BaseApplication.java   View Source Code Vote up 5 votes
/**
 * 删除所有activity
 */
public static void removeAllActivities(){
    ListIterator<BaseActivity> iterator = activities.listIterator();
    BaseActivity activity;
    while(iterator.hasNext()){
        activity = iterator.next();
        if(activity != null){
            activity.finish();
        }
    }
}
 
Example 18
Project: sling-org-apache-sling-query   File: SiblingsIterator.java   View Source Code Vote up 4 votes
@Override
public boolean canAdvance(ListIterator<?> iterator) {
	return iterator.hasNext();
}
 
Example 19
Project: myfaces-trinidad   File: CorePanelChoiceRenderer.java   View Source Code Vote up 4 votes
/**
 *  Generates markup for rendering HTML select control.
 *
 *  The select control markup is contained within a TD element.
 */
@SuppressWarnings("unchecked")
private void _renderSelectItemInTD(FacesContext context,
                                   UIComponent component,
                                   String disclosedChildId)
  throws IOException
{
  String compId = component.getClientId(context);
  ResponseWriter out = context.getResponseWriter();
  UIXRenderingContext rCtx = getRenderingContext(context, component);

  out.startElement("td", component);
  out.writeAttribute("valign", "top", null);
  out.writeAttribute("nowrap", Boolean.TRUE, null);

  out.startElement("select", component);
  out.writeAttribute("id", compId + _CHOICE_SELECT_SUFFIX_ID_CONST, null);
  out.writeAttribute("name", compId + _CHOICE_SELECT_SUFFIX_ID_CONST,null);

  XhtmlLafRenderer.renderStyleClassAttribute(rCtx, getFieldTextClass());

  // construct the javascript for submitting the form
  String onChangeJS = _getChoiceOnchangeJS(context,rCtx, component, compId);
  if (onChangeJS != null)
  {
    out.writeAttribute("onchange", onChangeJS, null);
  }

  // Render options now.
  ListIterator<UIComponent> children = component.getChildren().listIterator();
  while (children.hasNext())
  {
    UIComponent child = children.next();
    if (child instanceof UIXShowDetail)
    {
      UIXShowDetail detailItem = (UIXShowDetail) child;

      Boolean disabledObj =
        (Boolean) detailItem.getAttributes().get("disabled");

      boolean disabled = false; // by default is enabled.
      if (disabledObj != null)
      {
        disabled = disabledObj.booleanValue();
      }

      if (disabled)
      {
        // MSDN DHTML Reference says disabled not supported for option element
        // hence don't render disabled options at all to be consistent 
        // across browsers. See Bug 4561967.
        continue;
      }

      String childTitle = (String) detailItem.getAttributes().get("text");
      String childClientId = child.getClientId(context);

      out.startElement("option", component);
      out.writeAttribute("id", childClientId, null);
      if (childClientId.equals(disclosedChildId))
      {
        out.writeAttribute("selected", Boolean.TRUE, null);
      }

      if (childTitle != null)
        out.writeText(childTitle, null);

      out.endElement("option");
    }
  }
  out.endElement("select");

  out.endElement("td");
}
 
Example 20
Project: athena   File: BgpSelectionAlgo.java   View Source Code Vote up 4 votes
/**
 * Stores BGP basic attributes of two objects.
 *
 * @param listIteratorObj1 list iterator of object1
 * @param listIteratorObj2 list iterator of object2
 */
void storeAttr(ListIterator<BgpValueType> listIteratorObj1, ListIterator<BgpValueType> listIteratorObj2) {
     while (listIteratorObj1.hasNext()) {
         BgpValueType pathAttributeObj1 = listIteratorObj1.next();
         switch (pathAttributeObj1.getType()) {
         case LocalPref.LOCAL_PREF_TYPE:
             obj1LocPref = (LocalPref) pathAttributeObj1;
             break;
         case AsPath.ASPATH_TYPE:
             obj1Aspath = (AsPath) pathAttributeObj1;
             break;
         case Origin.ORIGIN_TYPE:
             obj1Origin = (Origin) pathAttributeObj1;
             break;
         case Med.MED_TYPE:
             obj1Med = (Med) pathAttributeObj1;
             break;
         default:
             log.debug("Got other type, Not required: " + pathAttributeObj1.getType());
         }
     }
     while (listIteratorObj2.hasNext()) {
         BgpValueType pathAttributeObj2 = listIteratorObj2.next();
         switch (pathAttributeObj2.getType()) {
         case LocalPref.LOCAL_PREF_TYPE:
             obj2LocPref = (LocalPref) pathAttributeObj2;
             break;
         case AsPath.ASPATH_TYPE:
             obj2Aspath = (AsPath) pathAttributeObj2;
             break;
         case Origin.ORIGIN_TYPE:
             obj2Origin = (Origin) pathAttributeObj2;
             break;
         case Med.MED_TYPE:
             obj2Med = (Med) pathAttributeObj2;
             break;
         default:
             log.debug("Got other type, Not required: " + pathAttributeObj2.getType());
         }
    }
}