下面列出了java.util.LinkedList#clone ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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), ""));
}
}
/**
* 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;
}
/**
* 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;
}
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;
}
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;
}
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;
}