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

The following examples show how to use java.util.LinkedList#clone() . 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: FileListAdapter.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public FileListAdapter(final Context context,
                       final LinkedList<FileDetail> fileDetails,
                       final boolean isRoot,
                       FileAdapterListener fileAdapterListener) {
    this.fileAdapterListener = fileAdapterListener;
    this.fileDetails = fileDetails;
    this.originalFileList = (LinkedList<FileDetail>) fileDetails.clone();
    this.orig = fileDetails;
    this.inflater = LayoutInflater.from(context);
    if (!isRoot) {
        this.fileDetails.addFirst(new FileDetail("..", context.getString(R.string.folder), ""));
    } else {
        this.fileDetails.addFirst(new FileDetail(context.getString(R.string.home), context.getString(R.string.folder), ""));
    }
}
 
Example 2
Source File: UserCasePreferences.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * sort the input: start with sorting as specified in parameter topItemsSorting, always add a
 * separator and then sort the rest alphabetically
 * 
 * @param input
 *            String[] of all billing systems, unsorted
 * @param topItemsSorting
 *            LinkedList<String> Array of billing systems in the order they should appear in the
 *            menu/combo
 * @param alwaysShowSeparator
 *            boolean should the separator also be shown when NO topItems are present
 * @return String[] the sorted list
 */
public static String[] sortBillingSystems(String[] input, LinkedList<String> topItemsSorting,
	boolean alwaysShowSeparator){
	// create a copy of topItemsSorting - we append the other items to the end later
	LinkedList<String> lTopItemsSorting = (LinkedList<String>) topItemsSorting.clone();
	
	// create sorted list for the other items
	SortedList<String> sortedList = new SortedList<String>(new Comparator<String>() {
		@Override
		public int compare(String o1, String o2){
			return (o1.compareTo(o2));
		}
	});
	for (int i = 0; i < input.length; i++) {
		String item = input[i];
		if (!lTopItemsSorting.contains(item))
			sortedList.add(item);
	}
	
	// now append the sorted items to the copied top items
	if (alwaysShowSeparator
		|| ((topItemsSorting.size() > 0) && (!topItemsSorting.get(0).equalsIgnoreCase("")))) { //$NON-NLS-1$
		lTopItemsSorting.add(MENUSEPARATOR);
	}
	lTopItemsSorting.addAll(sortedList);
	lTopItemsSorting.remove(""); //$NON-NLS-1$
	
	String[] output = new String[lTopItemsSorting.size()];
	lTopItemsSorting.toArray(output);
	
	return output;
}
 
Example 3
Source File: Parser.java    From cogitolearning-examples with MIT License 5 votes vote down vote up
/**
 * Parse a mathematical expression in contained in a list of tokens and return
 * an ExpressionNode.
 * 
 * @param tokens
 *          a list of tokens holding the tokenized input
 * @return the internal representation of the expression in form of an
 *         expression tree made out of ExpressionNode objects
 */
public ExpressionNode parse(LinkedList<Token> tokens)
{
  // implementing a recursive descent parser
  this.tokens = (LinkedList<Token>) tokens.clone();
  lookahead = this.tokens.getFirst();

  // top level non-terminal is expression
  ExpressionNode expr = expression();
  
  if (lookahead.token != Token.EPSILON)
    throw new ParserException("Unexpected symbol %s found", lookahead);
  
  return expr;
}
 
Example 4
Source File: ChainedCallSite.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private MethodHandle relinkInternal(GuardedInvocation invocation, MethodHandle relink, boolean reset) {
    final LinkedList<GuardedInvocation> currentInvocations = invocations.get();
    @SuppressWarnings({ "unchecked", "rawtypes" })
    final LinkedList<GuardedInvocation> newInvocations =
        currentInvocations == null || reset ? new LinkedList<>() : (LinkedList)currentInvocations.clone();

    // First, prune the chain of invalidated switchpoints.
    for(Iterator<GuardedInvocation> it = newInvocations.iterator(); it.hasNext();) {
        if(it.next().hasBeenInvalidated()) {
            it.remove();
        }
    }

    // prune() is allowed to invoke this method with invocation == null meaning we're just pruning the chain and not
    // adding any new invocations to it.
    if(invocation != null) {
        // Remove oldest entry if we're at max length
        if(newInvocations.size() == getMaxChainLength()) {
            newInvocations.removeFirst();
        }
        newInvocations.addLast(invocation);
    }

    // prune-and-invoke is used as the fallback for invalidated switchpoints. If a switchpoint gets invalidated, we
    // rebuild the chain and get rid of all invalidated switchpoints instead of letting them linger.
    final MethodHandle pruneAndInvoke = makePruneAndInvokeMethod(relink);

    // Fold the new chain
    MethodHandle target = relink;
    for(GuardedInvocation inv: newInvocations) {
        target = inv.compose(pruneAndInvoke, target);
    }

    // If nobody else updated the call site while we were rebuilding the chain, set the target to our chain. In case
    // we lost the race for multithreaded update, just do nothing. Either the other thread installed the same thing
    // we wanted to install, or otherwise, we'll be asked to relink again.
    if(invocations.compareAndSet(currentInvocations, newInvocations)) {
        setTarget(target);
    }
    return target;
}
 
Example 5
Source File: ChainedCallSite.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private MethodHandle relinkInternal(GuardedInvocation invocation, MethodHandle relink, boolean reset) {
    final LinkedList<GuardedInvocation> currentInvocations = invocations.get();
    @SuppressWarnings({ "unchecked", "rawtypes" })
    final LinkedList<GuardedInvocation> newInvocations =
        currentInvocations == null || reset ? new LinkedList<>() : (LinkedList)currentInvocations.clone();

    // First, prune the chain of invalidated switchpoints.
    for(Iterator<GuardedInvocation> it = newInvocations.iterator(); it.hasNext();) {
        if(it.next().hasBeenInvalidated()) {
            it.remove();
        }
    }

    // prune() is allowed to invoke this method with invocation == null meaning we're just pruning the chain and not
    // adding any new invocations to it.
    if(invocation != null) {
        // Remove oldest entry if we're at max length
        if(newInvocations.size() == getMaxChainLength()) {
            newInvocations.removeFirst();
        }
        newInvocations.addLast(invocation);
    }

    // prune-and-invoke is used as the fallback for invalidated switchpoints. If a switchpoint gets invalidated, we
    // rebuild the chain and get rid of all invalidated switchpoints instead of letting them linger.
    final MethodHandle pruneAndInvoke = makePruneAndInvokeMethod(relink);

    // Fold the new chain
    MethodHandle target = relink;
    for(GuardedInvocation inv: newInvocations) {
        target = inv.compose(pruneAndInvoke, target);
    }

    // If nobody else updated the call site while we were rebuilding the chain, set the target to our chain. In case
    // we lost the race for multithreaded update, just do nothing. Either the other thread installed the same thing
    // we wanted to install, or otherwise, we'll be asked to relink again.
    if(invocations.compareAndSet(currentInvocations, newInvocations)) {
        setTarget(target);
    }
    return target;
}
 
Example 6
Source File: ChainedCallSite.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
private MethodHandle relinkInternal(GuardedInvocation invocation, MethodHandle relink, boolean reset) {
    final LinkedList<GuardedInvocation> currentInvocations = invocations.get();
    @SuppressWarnings({ "unchecked", "rawtypes" })
    final LinkedList<GuardedInvocation> newInvocations =
        currentInvocations == null || reset ? new LinkedList<>() : (LinkedList)currentInvocations.clone();

    // First, prune the chain of invalidated switchpoints.
    for(Iterator<GuardedInvocation> it = newInvocations.iterator(); it.hasNext();) {
        if(it.next().hasBeenInvalidated()) {
            it.remove();
        }
    }

    // prune() is allowed to invoke this method with invocation == null meaning we're just pruning the chain and not
    // adding any new invocations to it.
    if(invocation != null) {
        // Remove oldest entry if we're at max length
        if(newInvocations.size() == getMaxChainLength()) {
            newInvocations.removeFirst();
        }
        newInvocations.addLast(invocation);
    }

    // prune-and-invoke is used as the fallback for invalidated switchpoints. If a switchpoint gets invalidated, we
    // rebuild the chain and get rid of all invalidated switchpoints instead of letting them linger.
    final MethodHandle pruneAndInvoke = makePruneAndInvokeMethod(relink);

    // Fold the new chain
    MethodHandle target = relink;
    for(GuardedInvocation inv: newInvocations) {
        target = inv.compose(pruneAndInvoke, target);
    }

    // If nobody else updated the call site while we were rebuilding the chain, set the target to our chain. In case
    // we lost the race for multithreaded update, just do nothing. Either the other thread installed the same thing
    // we wanted to install, or otherwise, we'll be asked to relink again.
    if(invocations.compareAndSet(currentInvocations, newInvocations)) {
        setTarget(target);
    }
    return target;
}