Difference between ways of selecting descendants - jquery-selectors

With the risk of being redirected to a dublicate question, what is the difference between using $("ul li") and $("ul").find("li")?

You may find this similar question of interest: What is the fastest method for selecting descendant elements in jQuery?
If you only need first level children, using .children() will give you a performance boost since there is less to interrogate.

$("ul").find("li") is faster than $("ul li").
$("ul li") is going to be changed into $("ul").find("li") after some checks and breaking.
find() appeared faster than children() to me in single level selections.

Related

Is there a way to get count of elements with the same accessibilityID?

Is there a way to get the count of elements having same accessibilityID/label etc in Swift?
Not easily. It may be worth filing a feature request for it. In the mean time, Here are some options, each having their own drawbacks:
EarlGrey added API called atIndex which lets you select a single element from a list of multiple matched elements but this list is not exposed. You could try something like calling atIndexwith a no-op assertion in a loop and increment a counter on each successful assertion. When the assertion fails, you know that's when index went out of bounds. It will essentially give you the count but it will be very slow and inefficient as it will scan the UI hierarchy each time you run the assertion.
Expose their private method matchedElementsWithTimeout:error: but you will risk being broken if they rename it.
I think that there is much better solution that google provides right in EarlGrey repo. Follow this link.

Scala PriorityQueue conflict resolution?

I'm working on a project that uses a PriorityQueue and A*. After digging around a ton I think part of the problem that I'm encountering while my search tries to solve my problem is in the PriorityQueue. I'm guessing that when it generates nodes of equal scoring (for example one earlier, and one later) it will chose the one from earlier rather than the one that was most recently generated.
Does anyone know if a PriorityQueue prioritizes the newest node if the scores are the same? If not, how can I make it do this?
Thanks!
PriorityQueue uses a heap to select the next element. Beyond that it makes no guarantees about how the elements are ordered. If it is important to you that nodes are ordered by addition order, you should keep a count of the number of items added and prioritize by the tuple (priority, -order).
If you do anything else, even if it happens to work now, it may break at any arbitrary time since the API makes no guarantees about how it chooses from among equal elements.

Should ErrorCollector (which is part of JSR-303 functionality) in GWT 2.4 be redesigned?

I know this question is not about particular problem I have. It's rather question to GWT SDK team. As far as I remember StackOverflow is now their official communication channel with engineering community :)
Problem:
For aliased editors such as ValueBoxEditorDecorator you'll receive duplicate errors in your HasEditorErrors.showErrors() - one for ValueBoxEditorDecorator itself and another one for nested ValueBoxEditor. Current implementation of ValueBoxEditorDecorator iterates through list of errors and rejects ones that don't belong to nested editor. It looks like a hacky workaround to me :)
Question:
I think duplicates should be discarded somewhere earlier, for example in SimpleViolation.pushViolations or DelegateMap.of or ErrorCollector.endVisit.
Initially I thought why not just keep one delegate per unique EditorContext.getAbsolutePath and drop the rest. Then I realized that perhaps there is a use-case when ValueBoxEditorDecorator and its inner ValueBoxEditor would get different errors although I can't come up with the scenario how it can happen due to my short-time knowledge of gwt's sources.
So here is what I think. Why don't we use map in ErrorCollector.errorStack instead of List where the key will be combination of EditorError.getAbsolutePath() and EditorError.getUserData() ? It would solve two issues IMO:
We won't need to filter out dupkicate errors in our editors.
ErrorCollector.visit() won't assume that editors like this one are traversed in hierarchical order. I don't see anywhere in documentation that visitors would always work that way.
What do you think ?

Any tips or best practices for adding a new item to a history while maintaining a maximum total number of items?

I'm working on some basic logging/history functionality for a Core Data iPhone app. I want to maintain a maximum number of history items.
My general plan is to ignore the maximum when adding a new item and enforce it whenever I need to fetch all the items anyway (e.g. for searching or browsing the history). Alternatively, I could do it when adding a new item: fetch the current items, add the new one, and delete the oldest one if we're at the maximum. The second way seems less efficient, since I would be fetching all the items when I otherwise wouldn't need to.
So, the questions:
Which way is better? Is there an even better way to do this that I'm not considering?
How many items would be a reasonable maximum? The history is used for text field autocompletion, so more items means better usability, unless the number of items is so huge that it's slowing stuff down.
Thanks!
Whichever method is easier to implement is the right one. You shouldn't bother with a more efficient/more complicated implementation unless it proves it's needed.
If these objects are in a to-many relationship of some kind, I'd use the relationship to manage the maximum number. (Override add<Whatever>Object: and delete the extraneous items then).
If you're just fetching them, then that's really your only opportunity to filter them out. If you're using an NSArrayController, you might be able to implement a subclass that detects when new objects are added and chops off the extra ones.
If the items are added manually by the user, then you can safely use the method of cleaning up later. With text data, a user won't enter more a few hundred items at most and text data takes up very little room. If the items are added by software, you have to check every so many entries or risk spill over.
You might not want to spend a lot of time on this. Autocomplete is not that big, usually just a few hundred entries. I would right it the simplest way, with clean up later, and then fiddle with it only if you hit a definite performance bottleneck.
Remember, premature optimization is the root of all programming evil. That and the dweebs in marketing.

Is there a better way to use sorting and filtering with ILazyTreeContentProvider

Apparently if using ILazyTree(TreePath)ContentProvider sorting and filtering is not supported by TreeViewers. So setting ViewerFilters or Sorters/Comparators to your TreeView won't do any good. Perhaps this is related to not knowing all elements, including those not visible at the moment.
In support to this statement here is javadoc excerpt from org.eclipse.jface.viewers.TreeViewer class:
If the content provider is an
ILazyTreeContentProvider or an
ILazyTreePathContentProvider, the underlying Tree must be
created using the {#link SWT#VIRTUAL} style bit, the tree viewer will not
support sorting or filtering, and hash lookup must be enabled by calling
{#link #setUseHashlookup(boolean)}.
The only solution I see at the moment is to get the children for each node already ordered. If you need dynamic sorting, i.e., being able to switch sorting order in desc or asc order during run time, then you need to come up with your own solution for this, monitoring a boolean flag of sorts when filling and updating children for example.
Are you aware possibly of better solutions, perhaps more jface API involving?
Indeed, sorting is not possible for a VIRTUAL-TreeViewer whether you use a IStructuredContentProvider or a lazy one, as noted in this thread:
You will have to do the sorting yourself (in your model).
The underlying assumption is that the elements might not even be in memory.
Things may change in e4 (from this message in June 2009):
IMHO the JFace Virtual Table and Tree implementation is not as good as the none virtual one - well I stay away from it and use it in none of my projects.
[...] its senseless to have virtual tables because from an UI-Design point of view it is senseless to show an user 10.000s of elements and even more important because the model
stays resident in your memory showing big tables with JFace might eat up
all your heapspace
(We hope to come up with a redesigned set of Viewers in E4 who fix such problems).
See this project and bug 260451.
(more genral bugs: 167436 and 262160)
Right now:
we are creating a strong reference in the viewer after the table requested it.
IMHO its much better to give the user:
- paging
- intelligent filtering possibilities
instead of showing million of results and then e.g. in case of CDO (Connected Data Objects) the filtering happens on the server using their new query-API.