traversal

How can I listen to a TAB key pressed/typed in Java?

旧街凉风 提交于 2019-11-29 09:07:40
private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) { //cant capture my TAB? System.out.print(evt.getKeyChar()); } What is the simplest way in an java gui to capture the tab key without doing using the focus listening technique? VK_TAB is the tab constant. However: No Tab key-pressed or key-released events are received by the key event listener. This is because the focus subsystem consumes focus traversal keys, such as Tab and Shift Tab. See: http://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html To solve this, apply the following to the component that is firing the

How to parse or query complex JSON in JavaScript

别等时光非礼了梦想. 提交于 2019-11-29 08:38:11
Is it possible to perform complex queries over a JSON object? I am open to JavaScript or jQuery solutions, the easier the better. I'm envisioning some kind of functional programming language similar to LINQ or SQL. I Prefer no other third party libraries or add-ons. UPDATE From the looks of early answers, an add-on is going to be necessary. In that case, I prefer an add-on that requires no installation process. Something that deploys with the software publish (like jQuery) is fine (e.g. sets of *.js files). Ryan Ternier Check out: Is there a query language for JSON? From that thread: JaQL (

Jquery tree traversal - Nested Unordered list elements to JSON

本秂侑毒 提交于 2019-11-29 08:20:58
Okay, Now I have an unordered list here: <ul id="mycustomid"> <li><a href="url of Item A" title="sometitle">Item A</a> <ul class="children"> <li><a href="url of Child1 of A" title="sometitle">Child1 of A</a> <ul class="children"> <li><a href="url of Grandchild of A" title="sometitle">Grandchild of A</a> <ul class="children"> <li><a href="url of Grand Grand child of A" title="sometitle">Grand Grand child of A</a></li> </ul> </li> </ul> </li> </ul> </li> <li><a href="url of Item B" title="sometitle">Item B</a></li> <li><a href="url of Item C" title="sometitle">Item C</a></li> </ul> Basically, I

Construct a Tree

若如初见. 提交于 2019-11-29 07:35:12
How can I construct a tree given its inorder and preorder traversal? I am just looking for an efficient algorithm. A blatant copy and paste from Sun's (Oracle now, I guess...) forum : Question: Can anybody help me on how to construct Binary tree from inorder and postorder traversals,i just want to know the algorithm so that i can apply it. Answer: Let p_1 , p_2 ... p_n be the postorder traversal and let i_1 , i_2 ... i_n be the inorder traversal. From the postorder traversal we know that the root of the tree is p_n . Find this element in the inorder traversal, say i_1 , i_2 ... i_k-1 p_n i_k+1

Skip recursion in jQuery.find() for a selector?

笑着哭i 提交于 2019-11-29 07:15:45
TL;DR: How do I get an action like find(), but block traversal (not full stop, just skip) for a certain selector? ANSWERS: $(Any).find(Selector).not( $(Any).find(Mask).find(Selector) ) There were many truly great answers, I wish I could some how distribute the bounty points more, maybe I should make some 50 pt bounties in response to some of these ;p I choose Karl-André Gagnon's because this answer managed to make findExclude unrequired in one, slightly long, line. While this uses three find calls and a heavy not filter, in most situations jQuery can use very fast implementation that skips

Efficiently Traverse Directory Tree with opendir(), readdir() and closedir()

試著忘記壹切 提交于 2019-11-29 06:18:29
问题 The C routines opendir(), readdir() and closedir() provide a way for me to traverse a directory structure. However, each dirent structure returned by readdir() does not seem to provide a useful way for me to obtain the set of pointers to DIR that I would need to recurse into the directory subdirectories. Of course, they give me the name of the files, so I could either append that name to the directory path and stat() and opendir() them, or I could change the current working directory of the

Find the next element that is not immediate?

牧云@^-^@ 提交于 2019-11-29 05:32:05
I want to find the first span element after class counter, in code something like this: <div class="counter"></div> <p></p> <span></span> It seems like the next() function only finds the immediate next element, so something like this: $(".counter").next("span") Won't work. The way I have been using is a bit lengthy and I was wondering if there was a shorter way, it is this: $(".counter").nextAll("span").eq(0) I think the closest() method in jQuery 3 will do the trick, but I am using 1.2.6 -- is there a better way to do this (am I just using next() wrong?) Pim Jager I think your method is the

How do I iterate over Binary Tree?

╄→尐↘猪︶ㄣ 提交于 2019-11-29 01:35:52
问题 Right now I have private static void iterateall(BinaryTree foo) { if(foo!= null){ System.out.println(foo.node); iterateall(foo.left); iterateall(foo.right); } } Can you change it to Iteration instead of a recursion? 回答1: Can you change it to Iteration instead of a recursion? You can, using an explicit stack. Pseudocode: private static void iterateall(BinaryTree foo) { Stack<BinaryTree> nodes = new Stack<BinaryTree>(); nodes.push(foo); while (!nodes.isEmpty()) { BinaryTree node = nodes.pop();

Using jQuery to gather all text nodes from a wrapped set, separated by spaces

柔情痞子 提交于 2019-11-28 23:46:45
I'm looking for a way to gather all of the text in a jQuery wrapped set, but I need to create spaces between sibling nodes that have no text nodes between them. For example, consider this HTML: <div> <ul> <li>List item #1.</li><li>List item #2.</li><li>List item #3.</li> </ul> </div> If I simply use jQuery's text() method to gather the text content of the <div> , like such: var $div = $('div'), text = $div.text().trim(); alert(text); that produces the following text: List item #1.List item #2.List item #3. because there is no whitespace between each <li> element. What I'm actually looking for

Are there non-trivial Foldable or Traversable instances that don't look like containers?

前提是你 提交于 2019-11-28 21:06:42
问题 There are lots of functors that look like containers (lists, sequences, maps, etc.), and many others that don't (state transformers, IO , parsers, etc.). I've not yet seen any non-trivial Foldable or Traversable instances that don't look like containers (at least if you squint a bit). Do any exist? If not, I'd love to get a better understanding of why they can't. 回答1: Every valid Traversable f is isomorphic to Normal s for some s :: Nat -> * where data Normal (s :: Nat -> *) (x :: *) where --