Java Code Examples for java.util.LinkedList#remove()

The following examples show how to use java.util.LinkedList#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CEventCenter.java    From CEventCenter with Apache License 2.0 6 votes vote down vote up
/**
 * 注销监听器
 *
 * @param listener 监听器
 * @param topics   多个主题
 */
public static void unregisterEventListener(I_CEventListener listener, String[] topics) {
    if (null == listener || null == topics) {
        return;
    }
    synchronized (LISTENER_LOCK) {
        for (String topic : topics) {
            if (TextUtils.isEmpty(topic)) {
                continue;
            }
            Object obj = LISTENER_MAP.get(topic);
            if (null == obj) {
                continue;
            } else if (obj instanceof I_CEventListener) {
                // 有一个监听器
                if (obj == listener) {
                    LISTENER_MAP.remove(topic);
                }
            } else if (obj instanceof List) {
                // 有多个监听器
                LinkedList<I_CEventListener> listeners = (LinkedList<I_CEventListener>) obj;
                listeners.remove(listener);
            }
        }
    }
}
 
Example 2
Source File: BrickDataManager.java    From brickkit-android with Apache License 2.0 6 votes vote down vote up
/**
 * Removes a brick with a tag from the cache.
 *
 * @param item the Brick
 */
public void removeFromTagCache(@NonNull BaseBrick item) {
    synchronized (this.tagCache) {
        if (item.getTag() != null && this.tagCache.containsKey(item.getTag())) {
            LinkedList<BaseBrick> list = this.tagCache.get(item.getTag());
            if (null == list) {
                Log.w(TAG, "removeFromTagCache: The tag cache is null.");
                return; // safety
            }

            list.remove(item);

            if (list.size() == 0) {
                this.tagCache.remove(item.getTag());
            }
        }
    }
}
 
Example 3
Source File: RefactoringLocationControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Saves the history of this control.
 */
public void saveHistory() {
	final IDialogSettings settings= fWizard.getDialogSettings();
	if (settings != null) {
		final LinkedList<String> locations= new LinkedList<String>();
		final String[] items= fCombo.getItems();
		for (int index= 0; index < items.length; index++)
			locations.add(items[index]);
		final String text= fCombo.getText().trim();
		if (!"".equals(text)) { //$NON-NLS-1$
			locations.remove(text);
			locations.addFirst(text);
		}
		final int size= locations.size();
		for (int index= 0; index < size - MAX_HISTORY_SIZE; index++)
			locations.removeLast();
		settings.put(fKey, locations.toArray(new String[locations.size()]));
	}
}
 
Example 4
Source File: DownloadManager.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public void deleteRangeDownload(LongList gidList) {
    stopRangeDownloadInternal(gidList);

    for (int i = 0, n = gidList.size(); i < n; i++) {
        long gid = gidList.get(i);
        DownloadInfo info = mAllInfoMap.get(gid);
        if (null == info) {
            Log.d(TAG, "Can't get download info with gid: " + gid);
            continue;
        }

        // Remove from DB
        EhDB.removeDownloadInfo(info.gid);

        // Remove from all info map
        mAllInfoList.remove(info);
        mAllInfoMap.remove(info.gid);

        // Remove from label list
        LinkedList<DownloadInfo> list = getInfoListForLabel(info.label);
        if (list != null) {
            list.remove(info);
        }
    }

    // Update listener
    for (DownloadInfoListener l: mDownloadInfoListeners) {
        l.onReload();
    }

    // Ensure download
    ensureDownload();
}
 
Example 5
Source File: BilingualAlignmentService.java    From termsuite-core with Apache License 2.0 5 votes vote down vote up
/**
 * E.g. Given the compound [hydro|électricité] and the component [hydro], the method should return the 
 * term [électricité]
 * 
 * 
 * @param termino
 * @param compound
 * @param component
 * @return
 */
public Collection<TermService> getMorphologicalExtensionsAsTerms(
		TerminologyService terminoService, 
		TermIndex lemmaLowerCaseIndex, 
		TermService compound, 
		Component component) {
	Preconditions.checkArgument(compound.isSingleWord());
	Preconditions.checkArgument(compound.isCompound());
	Preconditions.checkArgument(compound.getWords().get(0).getWord().getComponents().contains(component));
	
	Word compoundWord = compound.getWords().get(0).getWord();
	LinkedList<Component> extensionComponents = Lists.newLinkedList(compoundWord.getComponents());
	extensionComponents.remove(component);
	
	if(!(component.getBegin() == 0 || component.getEnd() == compound.getLemma().length()))
		return Lists.newArrayList();

	
	Set<String> possibleExtensionLemmas = Sets.newHashSet();
	possibleExtensionLemmas.add(compound.getLemma().substring(
			extensionComponents.getFirst().getBegin(), 
			extensionComponents.getLast().getEnd()));
		
	if(extensionComponents.size() > 1) {
		LinkedList<Component> allButLast = Lists.newLinkedList(extensionComponents);
		Component last = allButLast.removeLast();
		String lemma = compound.getLemma().substring(allButLast.getFirst().getBegin(), last.getBegin())
					+ last.getLemma();
		possibleExtensionLemmas.add(lemma);
	}
	
	List<TermService> extensionTerms = Lists.newArrayList();
	for(String s:possibleExtensionLemmas) 
		for(Term term:lemmaLowerCaseIndex.getTerms(s.toLowerCase()))
			extensionTerms.add(terminoService.asTermService(term));
	
	return extensionTerms;
}
 
Example 6
Source File: ObjectCache.java    From leakcanary-for-eclipse with MIT License 5 votes vote down vote up
protected void revalueEntry(Entry<E> entry)
{
    LinkedList<Entry<E>> currBucket = lfu(entry.numUsages);
    LinkedList<Entry<E>> nextBucket = lfu(++entry.numUsages);

    currBucket.remove(entry);
    nextBucket.addFirst(entry);
}
 
Example 7
Source File: XmlAsserter.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
String createXPathString(LinkedList<String> buffer) {
	LinkedList<String> queue = new LinkedList<String>(buffer);
	StringBuilder stringBuffer = new StringBuilder();
	while (!queue.isEmpty()) {
		String value = queue.remove();
		if (!(queue.isEmpty() && value.equals("/"))) {
			stringBuffer.append(value);
		}
	}
	return stringBuffer.toString();
}
 
Example 8
Source File: CacheInteracter.java    From BmapLite with Apache License 2.0 5 votes vote down vote up
public void deleteRouteHistory(RouteHistoryModel history) throws JSONException {
    if (null == history) {
        return;
    }
    LinkedList<RouteHistoryModel> historyList = getRouteHistory();
    if (null == historyList) {
        return;
    }
    historyList.remove(history);

    setRouteHistory(historyList);
}
 
Example 9
Source File: CacheInteracter.java    From BmapLite with GNU General Public License v3.0 5 votes vote down vote up
public void deleteSearchHistoryKeyword(String keyword) {
    if (null == keyword || keyword.isEmpty()) {
        return;
    }
    LinkedList<String> historyList = getSearchHistoryKeyword();
    if (null == historyList) {
        return;
    }
    historyList.remove(keyword);

    setSearchHistoryKeyword(historyList);
}
 
Example 10
Source File: CacheInteracter.java    From BmapLite with GNU General Public License v3.0 5 votes vote down vote up
public void addSearchHistoryKeyword(String keyword) {
    LinkedList<String> historyList = getSearchHistoryKeyword();
    if (null == historyList) {
        historyList = new LinkedList<>();
    }
    if (historyList.contains(keyword)) {
        historyList.remove(keyword);
    }
    historyList.addFirst(keyword);

    setSearchHistoryKeyword(historyList);
}
 
Example 11
Source File: RandomTopologyTest.java    From ict with Apache License 2.0 5 votes vote down vote up
@Test
public void testRandomNetworkTopologies() {
    List<Ict> network = createRandomNetworkTopology(10);
    randomlyConnectIcts(network, 3);
    Ict randomIct = network.get((int) (Math.random() * network.size()));
    LinkedList<Ict> otherIcts = new LinkedList<>(network);
    otherIcts.remove(randomIct);
    testCommunicationRange(randomIct, otherIcts, 20);
}
 
Example 12
Source File: RailRoadCar.java    From Siamese with GNU General Public License v3.0 5 votes vote down vote up
private static LinkedList a ( LinkedList list ) {
    System.out.println ( "Rearranging Cars..." );
    new LinkedList();
    final LinkedList<Object> list2 = new LinkedList<Object>();
    final LinkedList<Object> list3 = new LinkedList<Object>();
    final LinkedList<Object> list4 = new LinkedList<Object>();
    list = list;
    int size;
    while ( ( size = list.size() ) != 0 ) {
        for ( int i = 0; i < size; ++i ) {
            if ( i == 0 ) {
                list3.add ( list.element() );
                list.remove();
            } else if ( Integer.parseInt ( list3.element().toString() ) < Integer.parseInt ( list.element().toString() ) ) {
                list2.add ( list3.element() );
                list3.remove();
                list3.add ( list.element() );
                list.remove();
            } else {
                list2.add ( list.element() );
                list.remove();
            }
        }
        for ( int size2 = list2.size(), j = 0; j < size2; ++j ) {
            list.add ( list2.element() );
            list2.remove();
        }
        list4.add ( list3.element() );
        list3.remove();
        System.out.print ( list.toString() );
        System.out.print ( " , " );
        System.out.print ( list2.toString() );
        System.out.print ( " , " );
        System.out.print ( list3.toString() );
        System.out.print ( " , " );
        System.out.println ( list4.toString() );
    }
    return list4;
}
 
Example 13
Source File: LinkedListTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * remove removes next element, or throws NSEE if empty
 */
public void testRemove() {
    LinkedList q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.remove());
    }
    try {
        q.remove();
        shouldThrow();
    } catch (NoSuchElementException success) {}
}
 
Example 14
Source File: EnableBeansFilter.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void checkProxyability( TypeElement typeElement,
        LinkedList<Element> types , Set<Element> elements)
{
    try {
        String scope = ParameterInjectionPointLogic.getScope(typeElement,
                getWebBeansModel().getHelper());
        Elements elementsUtil = getHelper().getCompilationController().
            getElements();
        TypeElement scopeElement = elementsUtil.getTypeElement(scope);
        /*
         * Client proxies are never required for a bean whose
         * scope is a pseudo-scope such as @Dependent.
         */
        if ( scopeElement == null ||
                getHelper().hasAnnotation( elementsUtil.getAllAnnotationMirrors(
                scopeElement), SCOPE) )
        {
            return;
        }
    }
    catch (CdiException e) {
        types.remove( typeElement );
        elements.remove( typeElement);
        return;
    }
    /*
     * Certain legal bean types cannot be proxied by the container:
     * - classes which don't have a non-private constructor with no parameters,
     * - classes which are declared final or have final methods,
     * - primitive types,
     * -  and array types.
     */
    if ( hasModifier(typeElement, Modifier.FINAL)){
        types.remove(typeElement);
        elements.remove( typeElement );
        return;
    }
    checkFinalMethods(typeElement, types, elements);

    List<ExecutableElement> constructors = ElementFilter.constructorsIn(
            typeElement.getEnclosedElements()) ;
    boolean appropriateCtor = false;
    for (ExecutableElement constructor : constructors) {
        if ( hasModifier(constructor, Modifier.PRIVATE)){
            continue;
        }
        if ( constructor.getParameters().size() == 0 ){
            appropriateCtor = true;
            break;
        }
    }

    if ( !appropriateCtor){
        types.remove(typeElement);
        elements.remove( typeElement );
    }
}
 
Example 15
Source File: MainPanel.java    From javagame with MIT License 4 votes vote down vote up
/**
 * �Q�[�����[�v
 */
public void run() {
    while (true) {
        if (goLeftKey.isPressed()) {
            // ���L�[��������Ă���΍������ɉ���
            player.accelerateLeft();
        } else if (goRightKey.isPressed()) {
            // �E�L�[��������Ă���ΉE�����ɉ���
            player.accelerateRight();
        } else {
            // ����������ĂȂ��Ƃ��͒�~
            player.stop();
        }

        if (jumpKey.isPressed()) {
            // �W�����v����
            player.jump();
        }

        // �v���C���[�̏�Ԃ��X�V
        player.update();

        // �}�b�v�ɂ���X�v���C�g���擾
        LinkedList sprites = map.getSprites();            
        Iterator iterator = sprites.iterator();
        while (iterator.hasNext()) {
            Sprite sprite = (Sprite)iterator.next();
            
            // �X�v���C�g�̏�Ԃ��X�V����
            sprite.update();

            // �v���C���[�ƐڐG���Ă���
            if (player.isCollision(sprite)) {
                if (sprite instanceof Kuribo) {  // �I�{�[
                    Kuribo kuribo = (Kuribo)sprite;
                    // �ォ�瓥�܂�Ă���
                    if ((int)player.getY() < (int)kuribo.getY()) {
                        // �I�{�[�͏�����
                        sprites.remove(kuribo);
                        // �T�E���h
                        kuribo.play();
                        // ���ނƃv���C���[�͍ăW�����v
                        player.setForceJump(true);
                        player.jump();
                        break;
                    } else {
                        // �Q�[���I�[�o�[
                        gameOver();
                    }
                } else if (sprite instanceof Coin) {  // �R�C��
                        Coin coin = (Coin)sprite;
                        // �R�C���͏�����
                        sprites.remove(coin);
                        // �����`��
                        coin.play();
                        // sprites����폜�����̂�
                        // break���Ȃ���iterator�����������Ȃ�
                        break;
                } else if (sprite instanceof Accelerator) {  // �����A�C�e��
                    // �A�C�e���͏�����
                    sprites.remove(sprite);
                    Accelerator accelerator = (Accelerator)sprite;
                    // �T�E���h
                    accelerator.play();
                    // �A�C�e�������̏�Ŏg��
                    accelerator.use(player);
                    break;
                } else if (sprite instanceof JumperTwo) {  // ��i�W�����v�A�C�e��
                    // �A�C�e���͏�����
                    sprites.remove(sprite);
                    JumperTwo jumperTwo = (JumperTwo)sprite;
                    // �T�E���h
                    jumperTwo.play();
                    // �A�C�e�������̏�Ŏg��
                    jumperTwo.use(player);
                    break;                        
                }
            }
        }
        
        // �ĕ`��
        repaint();

        // �x�~
        try {
            Thread.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
 
Example 16
Source File: WebConsole.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * This method is used by all the public method to process the passed
 * parameters.
 *
 * If the last parameter implements the Formatter interface, it will be
 * used to format the parameters and print the object.
 * @param objs the logging parameters
 * @return a String to be printed using the logger
 */
private String process(final Object[] objs) {
    if (objs == null) {
        return "null";
    }

    final StringBuilder sb = new StringBuilder();
    final LinkedList<Object> args = new LinkedList<>(Arrays.asList(objs));

    final Formatter formatter = getFormatter();

    if (args.size() > 1 && args.get(0) instanceof String) {
        final StringBuilder msg = new StringBuilder((String) args.remove(0));
        int startPos = msg.indexOf("%");

        while (startPos > -1 && startPos < msg.length() - 1 && args.size() > 0) {
            if (startPos != 0 && msg.charAt(startPos - 1) == '%') {
                // double %
                msg.replace(startPos, startPos + 1, "");
            }
            else {
                final char type = msg.charAt(startPos + 1);
                String replacement = null;
                switch (type) {
                    case 'o':
                    case 's':
                        replacement = formatter.parameterAsString(pop(args));
                        break;
                    case 'd':
                    case 'i':
                        replacement = formatter.parameterAsInteger(pop(args));
                        break;
                    case 'f':
                        replacement = formatter.parameterAsFloat(pop(args));
                        break;
                    default:
                        break;
                }
                if (replacement != null) {
                    msg.replace(startPos, startPos + 2, replacement);
                    startPos = startPos + replacement.length();
                }
                else {
                    startPos++;
                }
            }
            startPos = msg.indexOf("%", startPos);
        }
        sb.append(msg);
    }

    for (final Object o : args) {
        if (sb.length() != 0) {
            sb.append(' ');
        }
        sb.append(formatter.printObject(o));
    }
    return sb.toString();
}
 
Example 17
Source File: Options.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void processArgList(final LinkedList<String> argList) {
    while (!argList.isEmpty()) {
        final String arg = argList.remove(0);

        // skip empty args
        if (arg.isEmpty()) {
            continue;
        }

        // user arguments to the script
        if ("--".equals(arg)) {
            arguments.addAll(argList);
            argList.clear();
            continue;
        }

        // If it doesn't start with -, it's a file. But, if it is just "-",
        // then it is a file representing standard input.
        if (!arg.startsWith("-") || arg.length() == 1) {
            files.add(arg);
            continue;
        }

        if (arg.startsWith(definePropPrefix)) {
            final String value = arg.substring(definePropPrefix.length());
            final int eq = value.indexOf('=');
            if (eq != -1) {
                // -Dfoo=bar Set System property "foo" with value "bar"
                System.setProperty(value.substring(0, eq), value.substring(eq + 1));
            } else {
                // -Dfoo is fine. Set System property "foo" with "" as it's value
                if (!value.isEmpty()) {
                    System.setProperty(value, "");
                } else {
                    // do not allow empty property name
                    throw new IllegalOptionException(definePropTemplate);
                }
            }
            continue;
        }

        // it is an argument,  it and assign key, value and template
        final ParsedArg parg = new ParsedArg(arg);

        // check if the value of this option is passed as next argument
        if (parg.template.isValueNextArg()) {
            if (argList.isEmpty()) {
                throw new IllegalOptionException(parg.template);
            }
            parg.value = argList.remove(0);
        }

        // -h [args...]
        if (parg.template.isHelp()) {
            // check if someone wants help on an explicit arg
            if (!argList.isEmpty()) {
                try {
                    final OptionTemplate t = new ParsedArg(argList.get(0)).template;
                    throw new IllegalOptionException(t);
                } catch (final IllegalArgumentException e) {
                    throw e;
                }
            }
            throw new IllegalArgumentException(); // show help for
            // everything
        }

        if (parg.template.isXHelp()) {
            throw new IllegalOptionException(parg.template);
        }

        set(parg.template.getKey(), createOption(parg.template, parg.value));

        // Arg may have a dependency to set other args, e.g.
        // scripting->anon.functions
        if (parg.template.getDependency() != null) {
            argList.addFirst(parg.template.getDependency());
        }
    }
}
 
Example 18
Source File: HtmlTreeBuilder.java    From jsoup-learning with MIT License 4 votes vote down vote up
private void replaceInQueue(LinkedList<Element> queue, Element out, Element in) {
    int i = queue.lastIndexOf(out);
    Validate.isTrue(i != -1);
    queue.remove(i);
    queue.add(i, in);
}
 
Example 19
Source File: MainPanel.java    From javagame with MIT License 4 votes vote down vote up
/**
 * �Q�[�����[�v
 */
public void run() {
    while (true) {
        if (leftPressed) {
            // ���L�[��������Ă���΍������ɉ���
            player.accelerateLeft();
        } else if (rightPressed) {
            // �E�L�[��������Ă���ΉE�����ɉ���
            player.accelerateRight();
        } else {
            // ����������ĂȂ��Ƃ��͒�~
            player.stop();
        }

        if (upPressed) {
            // �W�����v����
            player.jump();
        }

        // �v���C���[�̏�Ԃ��X�V
        player.update();

        // �}�b�v�ɂ���X�v���C�g���擾
        LinkedList sprites = map.getSprites();            
        Iterator iterator = sprites.iterator();
        while (iterator.hasNext()) {
            Sprite sprite = (Sprite)iterator.next();
            
            // �X�v���C�g�̏�Ԃ��X�V����
            sprite.update();

            // �v���C���[�ƐڐG���Ă���
            if (player.isCollision(sprite)) {
                if (sprite instanceof Coin) {  // �R�C��
                    Coin coin = (Coin)sprite;
                    // �R�C���͏�����
                    sprites.remove(coin);
                    // �����`��
                    coin.play();
                    // sprites����폜�����̂�
                    // break���Ȃ���iterator�����������Ȃ�
                    break;
                } else if (sprite instanceof Kuribo) {  // �I�{�[
                    Kuribo kuribo = (Kuribo)sprite;
                    // �ォ�瓥�܂�Ă���
                    if ((int)player.getY() < (int)kuribo.getY()) {
                        // �I�{�[�͏�����
                        sprites.remove(kuribo);
                        // �T�E���h
                        kuribo.play();
                        // ���ނƃv���C���[�͍ăW�����v
                        player.setForceJump(true);
                        player.jump();
                        break;
                    } else {
                        // �Q�[���I�[�o�[
                        gameOver();
                    }
                } else if (sprite instanceof Accelerator) {  // �����A�C�e��
                    // �A�C�e���͏�����
                    sprites.remove(sprite);
                    Accelerator accelerator = (Accelerator)sprite;
                    // �T�E���h
                    accelerator.play();
                    // �A�C�e�������̏�Ŏg��
                    accelerator.use(player);
                    break;
                }
            }
        }
        
        // �ĕ`��
        repaint();

        // �x�~
        try {
            Thread.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
 
Example 20
Source File: Histogram.java    From chipster with MIT License 4 votes vote down vote up
private FloatArrayList getHistogram(int histogramSteps, String expression) throws MicroarrayException, IOException {

		// get data
		Iterable<Float> intensities = data.queryFeatures(expression).asFloats();
		LinkedList<Float> values = new LinkedList<Float>();
		for (float intensity : intensities) {
			values.add(intensity);
		}

		// sort it, so we don't have to search for value intervals
		Collections.sort(values);

		// filter out NaN's
		while (values.get(values.size() - 1).isNaN()) {
			values.remove(values.size() - 1);
		}

		if (values.size() < histogramSteps) {
			return new FloatArrayList(values); // can't make histogram, return
												// plain values
		}

		// determine step size
		float min = values.get(0);
		float max = values.get(values.size() - 1);
		float stepSize = (max - min) / ((float) histogramSteps);

		// initialise
		float[] histogram = new float[histogramSteps];
		int valueIndex = 0;
		float roof = min + stepSize;

		// step through categories, counting matching values as we go
		for (int step = 0; step < histogram.length; step++) {
			while (valueIndex < values.size() && values.get(valueIndex) <= roof) {
				histogram[step]++;
				valueIndex++;
			}
			roof += stepSize;
		}

		// add to last category what was left out
		histogram[histogram.length - 1] += (values.size() - valueIndex);

		return new FloatArrayList(histogram);
	}