Example usage for java.util LinkedList remove

List of usage examples for java.util LinkedList remove

Introduction

In this page you can find the example usage for java.util LinkedList remove.

Prototype

public E remove() 

Source Link

Document

Retrieves and removes the head (first element) of this list.

Usage

From source file:Main.java

public static void main(String[] args) {

    // create a LinkedList
    LinkedList<String> list = new LinkedList<String>();

    // add some elements
    list.add("Hello");
    list.add("from java2s.com");
    list.add("10");

    // print the list
    System.out.println("LinkedList:" + list);

    // remove the head of the list
    list.remove();

    // print the list
    System.out.println("LinkedList:" + list);
}

From source file:org.apache.axis2.jaxws.util.WSDLExtensionUtils.java

/**
 * This method will search for all wsdl extensibility elements marked as required=true in wsdl:bindings
 * As per the wsdl 2.2 specification section 2.5 here is how a wsdl:binding is defined:
 * <wsdl:definitions .... >/*ww  w  .j  a v a2  s  .co m*/
 *      <wsdl:binding name="nmtoken" type="qname"> *
 *       <-- extensibility element (1) --> *
 *       <wsdl:operation name="nmtoken"> *
 *          <-- extensibility element (2) --> *
 *          <wsdl:input name="nmtoken"? > ?
 *              <-- extensibility element (3) --> 
 *          </wsdl:input>
 *          <wsdl:output name="nmtoken"? > ?
 *              <-- extensibility element (4) --> *
 *          </wsdl:output>
 *          <wsdl:fault name="nmtoken"> *
 *              <-- extensibility element (5) --> *
 *          </wsdl:fault>
 *       </wsdl:operation>
 *   </wsdl:binding>
 * </wsdl:definitions>
 * we will look for wsdl extensions in binding root, wsdl:operation, wsdl:input, wsdl:output and wsdl:fault.
 * If the extensibility element is defines outside of these sections it will not be picked up by this method.
 * 
 * @param wsdlBinding - WSDLBinding Object read from WSDL Definition.
 * @param set - Set that will be filled with list of required=true extension elements.
 * @return
 */
public static void search(WSDLElement element, Set<WSDLValidatorElement> set, List<QName> unusedExtensions) {
    if (log.isDebugEnabled()) {
        log.debug("Start Searching for WSDLExtensions");
    }
    if (element == null) {
        return;
    }
    //This search method uses a simple BFS technique to search for Extension elements in WSDLBindings.
    //I will Queue all available WSDLElements starting in wsdl:binding and traverse them looking for 
    //extensions. Queue will be empty when I have processed everything.
    //NOTE:Binding, Operation, OperationInput, OperationOutput and OperationFault are all WSDLElements.
    LinkedList<WSDLElement> queue = new LinkedList<WSDLElement>();
    queue.offer(element);

    while (!queue.isEmpty()) {
        WSDLElement wsdlElement = queue.remove();
        //WSDLElement in Queue could be wsdl Binding, BindingOperations, Input, Output or Fault
        //Find Extensibility Elements in wsdlElement.
        processWSDLElement(wsdlElement, set, unusedExtensions);
        //check if we are dealing with wsdlBinding;
        //store all BindingOpeations from wsdlBindings
        if (wsdlElement instanceof Binding) {
            //lets get all operations and add to queue
            //TODO: WSDLDef API's don't use generics, hence we use Iterator below and type cast.
            List operations = ((Binding) wsdlElement).getBindingOperations();
            Iterator iter = operations.iterator();
            while (iter.hasNext()) {
                BindingOperation op = (BindingOperation) iter.next();
                queue.offer(op);
            }
        }
        //check if we are dealing with Bindingoperations
        //Store all input, output and faults.
        if (wsdlElement instanceof BindingOperation) {
            BindingInput bi = ((BindingOperation) wsdlElement).getBindingInput();
            queue.offer(bi);
            BindingOutput bo = ((BindingOperation) wsdlElement).getBindingOutput();
            queue.offer(bo);
            Map map = ((BindingOperation) wsdlElement).getBindingFaults();
            Collection c = map.values();
            Iterator iter = c.iterator();
            while (iter.hasNext()) {
                Object o = iter.next();
                if (o instanceof BindingFault) {
                    BindingFault bf = (BindingFault) o;
                    queue.offer(bf);
                }
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("End Searching for WSDLExtensions");
    }
}

From source file:com.jaeksoft.searchlib.Logging.java

public final static String readLogs(int lines, String fileName) throws IOException {
    if (fileName == null)
        return null;
    File logFile = new File(getLogDirectory(), fileName);
    if (!logFile.exists())
        return null;
    FileReader fr = null;//from   ww  w .  ja va 2 s.c om
    BufferedReader br = null;
    StringWriter sw = null;
    PrintWriter pw = null;
    LinkedList<String> list = new LinkedList<String>();
    try {
        fr = new FileReader(logFile);
        br = new BufferedReader(fr);
        String line = null;
        int size = 0;
        while ((line = br.readLine()) != null) {
            list.add(line);
            if (size++ > lines)
                list.remove();
        }
        sw = new StringWriter();
        pw = new PrintWriter(sw);
        for (String l : list)
            pw.println(StringEscapeUtils.escapeJava(l));
        return sw.toString();
    } finally {
        IOUtils.close(br, fr, pw, sw);
    }
}

From source file:com.github.dozermapper.core.util.MappingUtils.java

@SuppressWarnings("unchecked")
public static List<Class<?>> getInterfaceHierarchy(Class<?> srcClass, BeanContainer beanContainer) {
    final List<Class<?>> result = new LinkedList<>();
    Class<?> realClass = getRealClass(srcClass, beanContainer);

    final LinkedList<Class> interfacesToProcess = new LinkedList<>();

    Class[] interfaces = realClass.getInterfaces();

    interfacesToProcess.addAll(Arrays.asList(interfaces));

    while (!interfacesToProcess.isEmpty()) {
        Class<?> iface = interfacesToProcess.remove();
        if (!result.contains(iface)) {
            result.add(iface);//from   w  ww  . j a  v  a 2  s .  c o m
            for (Class subiface : iface.getInterfaces()) {
                // if we haven't processed this interface yet then add it to be processed
                if (!result.contains(subiface)) {
                    interfacesToProcess.add(subiface);
                }
            }
        }
    }

    return result;

}

From source file:org.dozer.util.MappingUtils.java

@SuppressWarnings("unchecked")
public static List<Class<?>> getInterfaceHierarchy(Class<?> srcClass) {
    final List<Class<?>> result = new LinkedList<Class<?>>();
    Class<?> realClass = getRealClass(srcClass);

    final LinkedList<Class> interfacesToProcess = new LinkedList<Class>();

    Class[] interfaces = realClass.getInterfaces();

    interfacesToProcess.addAll(Arrays.asList(interfaces));

    while (!interfacesToProcess.isEmpty()) {
        Class<?> iface = interfacesToProcess.remove();
        if (!result.contains(iface)) {
            result.add(iface);//from  w  w w .  j  a v  a  2 s .  co  m
            for (Class subiface : iface.getInterfaces()) {
                // if we haven't processed this interface yet then add it to be processed
                if (!result.contains(subiface)) {
                    interfacesToProcess.add(subiface);
                }
            }
        }
    }

    return result;

}

From source file:com.mchp.android.PIC32_BTSK.TemperatureFragment.java

public static void parseTemperature(String s, LinkedList<Integer> l) {
    int i;//from www  . java2  s .c  om
    s = s.trim();
    String splitS[] = s.split(",", 2);
    if (splitS.length != 2) {
        return;
    }
    if (!splitS[0].contentEquals(enableCmd)) {
        return;
    }
    try {
        i = Integer.parseInt(splitS[1]);
    } catch (NumberFormatException e) {
        return;
    }
    l.add(i);
    l.remove();

    return;
}

From source file:com.twitter.distributedlog.service.balancer.CountBasedStreamChooser.java

@Override
public synchronized String choose() {
    // reach the pivot
    if (next == pivot) {
        if (streamsDistribution.get(next - 1).getRight().size() > pivotCount) {
            next = 0;/*from  w w  w .ja v a  2s .com*/
        } else if (pivotCount == 0) { // the streams are empty now
            return null;
        } else {
            findNextPivot();
            next = 0;
        }
    }

    // get stream count that next host to choose from
    LinkedList<String> nextStreams = streamsDistribution.get(next).getRight();
    if (nextStreams.size() == 0) {
        return null;
    }

    String chosenStream = nextStreams.remove();
    ++next;
    return chosenStream;
}

From source file:org.springframework.cloud.contract.verifier.util.DelegatingJsonVerifiable.java

private String createMethodString() {
    LinkedList<String> queue = new LinkedList<>(this.methodsBuffer);
    StringBuilder stringBuffer = new StringBuilder();
    while (!queue.isEmpty()) {
        stringBuffer.append(queue.remove());
    }/*from ww w  .j  av  a2s .  c  o  m*/
    return stringBuffer.toString();
}

From source file:org.wso2.carbon.device.mgt.iot.services.firealarm.FireAlarmControllerService.java

@Path("/readcontrols/{owner}/{deviceId}")
@GET//from w  w  w.  j  av a 2 s  .  c o m
public String readControls(@PathParam("owner") String owner, @PathParam("deviceId") String deviceId,
        @Context HttpServletResponse response) {
    String result = null;
    LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId);

    if (deviceControlList == null) {
        result = "No controls have been set for device " + deviceId + " of owner " + owner;
        response.setStatus(HttpStatus.SC_NO_CONTENT);
    } else {
        try {
            result = deviceControlList.remove();
            response.setStatus(HttpStatus.SC_ACCEPTED);
            response.addHeader("Control", result);
        } catch (NoSuchElementException ex) {
            result = "There are no more controls for device " + deviceId + " of owner " + owner;
            response.setStatus(HttpStatus.SC_NO_CONTENT);
        }
    }
    log.info(result);
    return result;
}

From source file:org.nuxeo.ecm.core.storage.sql.db.H2Functions.java

/**
 * Rebuild the complete descendants tree.
 *//*from w ww.  j  a v  a2 s  .c o m*/

public static void initDescendants(Connection conn) throws SQLException {
    LinkedList<String> todo = new LinkedList<String>();

    // find roots
    Statement s = conn.createStatement();
    String sql = "SELECT ID FROM REPOSITORIES";
    logDebug(sql);
    ResultSet rs = s.executeQuery(sql);
    while (rs.next()) {
        String rootId = rs.getString(1);
        todo.add(rootId);
    }
    rs.close();
    log.trace("SQL:   -> " + todo);
    if (todo.size() == 0) {
        // db not yet initialized, ignore
        s.close();
        return;
    }

    // truncate table
    String table = "DESCENDANTS";
    sql = String.format("TRUNCATE TABLE %s", table);
    logDebug(sql);
    s.execute(sql);
    s.close();

    // traverse from roots
    Map<String, Set<String>> ancestors = new HashMap<String, Set<String>>();
    Map<String, Set<String>> descendants = new HashMap<String, Set<String>>();
    do {
        String p = todo.remove();
        sql = "SELECT ID FROM HIERARCHY WHERE PARENTID = ? AND ISPROPERTY = 0";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1, p);
        // logDebug(sql, p);
        rs = ps.executeQuery();
        // for each child
        while (rs.next()) {
            String c = rs.getString(1);
            todo.add(c);
            // child's ancestors
            Set<String> cans = ancestors.get(c);
            if (cans == null) {
                ancestors.put(c, cans = new HashSet<String>());
            }
            Set<String> pans = ancestors.get(p);
            if (pans != null) {
                cans.addAll(pans);
            }
            cans.add(p);
            // all ancestors have it as descendant
            for (String pp : cans) {
                Set<String> desc = descendants.get(pp);
                if (desc == null) {
                    descendants.put(pp, desc = new HashSet<String>());
                }
                desc.add(c);
            }
        }
        ps.close();
    } while (!todo.isEmpty());

    // insert descendants into table
    sql = String.format("INSERT INTO %s (ID, DESCENDANTID) VALUES (?, ?)", table);
    PreparedStatement ps = conn.prepareStatement(sql);
    int n = 0;
    for (Entry<String, Set<String>> e : descendants.entrySet()) {
        String p = e.getKey();
        for (String c : e.getValue()) {
            ps.setString(1, p);
            ps.setString(2, c);
            // logDebug(sql, p, c);
            ps.execute();
            n++;
        }
    }
    logDebug(String.format("-- inserted %s rows into %s", Long.valueOf(n), table));
    ps.close();
}