|
Pete O'Hanlon wrote: Ooh. Text speak. Guaranteed to really annoy.
Man, forget helping the OP now, as far as I'm concerned.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
This is homework. We don't do homework. We have jobs to do.
Show us what you've got.
regards Torsten
I never finish anyth...
|
|
|
|
|
|
I need to find an alphanumeric sequence example:1wer3rtyu4sd inside a block of text
to which the alpanumeric sequence is unique.
I am using the following piece of code:
Pattern pattern = Pattern.compile(regex);//need a proper regex
Matcher matcher = pattern.matcher(strLine); //strLine consists the text
if (matcher.find())
{
System.out.println(matcher.group());
System.out.println(matcher.groupCount());
}
|
|
|
|
|
Your question is unclear. Are you searching for a pattern that you already know exactly? If so, use strLine.indexOf(wantedString). If you are doing something selse, you need to tell us more about how to specify the search pattern.
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
I successfully created UNbalanced Binary Search Tree to see if I can actually do it and I did - However, I would like to know how to make it a "Balanced" Binary Search Tree.
Here is the code for "BinarySearchTree.java"
package util;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class BinarySearchTree implements BinarySearchTreeADT {
private static final String INDENT = " ";
private Node root;
private static String makeIndents(int indent) {
String result = "";
for (int i = 0; i < indent; i++) {
result = result + BinarySearchTree.INDENT;
}
return result;
}
@Override
public final void add(Comparable item) {
this.root = addIterative(item, this.root);
}
private Node addIterative(Comparable item, Node n) {
Node originalTree = n;
if (n == null) {
Node newNode = new Node();
newNode.item = item;
return newNode;
}
while (n != null) {
int compare = item.compareTo(n.item);
if (compare == 0) throw new DuplicateElementException();
if (compare < 0) {
if (n.left == null) {
n.left = new Node();
n.left.item = item;
break;
}
else n = n.left;
}
else {
if (n.right == null) {
n.right = new Node();
n.right.item = item;
break;
}
else n = n.right;
}
}
return originalTree;
}
private Node add(Comparable item, Node n) {
if (n == null) {
Node newNode = new Node();
newNode.item = item;
return newNode;
}
if (item.compareTo(n.item) > 0) {
n.right = add(item, n.right);
return n;
}
if (item.compareTo(n.item) < 0) {
n.left = add(item, n.left);
return n;
}
throw new DuplicateElementException();
}
@Override
public Iterator<Comparable> iterator() throws ConcurrentModificationException,
UnsupportedOperationException {
throw new UnsupportedOperationException("To do.") ;
}
@Override
public String printTree() {
if (this.root == null) return "";
return "\n" + printTree(this.root, 0);
}
private String printTree(Node root, int level) {
String result = "";
if (root.right != null) {
result = result + printTree(root.right, level + 1);
}
result = result + makeIndents(level) + root.item.toString() +
"(" + root.getBalanceFactor() + ")\n";
if (root.left != null) {
result = result + printTree(root.left, level + 1);
}
return result;
}
@Override
public void remove(Comparable item) {
this.root = removeIterativeAlmost(item, this.root);
}
private Node removeIterativeAlmost(Comparable item, Node n) {
Node parent = null;
Node toremove = n;
while (toremove != null) {
int compare = item.compareTo(toremove.item);
if (compare == 0) break;
parent = toremove;
if (compare < 0) toremove = toremove.left;
else toremove = toremove.right;
}
if (toremove == null) throw new NoSuchElementException();
if (toremove.left == null) {
replaceChildNodeInParent(parent, toremove, toremove.right);
return n;
}
if (toremove.right == null) {
replaceChildNodeInParent(parent, toremove, toremove.left);
return n;
}
Comparable largest = findLargest(toremove.left);
toremove.item = largest;
toremove.left = removeIterativeAlmost(largest, toremove.left);
return n;
}
private void replaceChildNodeInParent(
Node parent, Node currentchild, Node newchild) {
if (parent == null) this.root = newchild;
else if (parent.left == currentchild) parent.left = newchild;
else parent.right = newchild;
}
private Node remove(Comparable item, Node n) {
if (n == null) throw new NoSuchElementException();
if (item.compareTo(n.item) < 0) {
n.left = remove(item, n.left);
return n;
}
if (item.compareTo(n.item) > 0) {
n.right = remove(item, n.right);
return n;
}
if (n.left == null) return n.right;
if (n.right == null) return n.left;
Comparable largest = findLargest(n.left);
n.item = largest;
n.left = remove(largest, n.left);
return n;
}
private Comparable findLargest(Node n) {
while (n.right != null) {
n = n.right;
}
return n.item;
}
private Comparable findSmallest(Node n) {
while (n.left != null) {
n = n.left;
}
return n.item;
}
private class Node {
private Comparable item;
private Node left;
private Node right;
private int getBalanceFactor() {
return -999;
}
}
}
Here is the code for "BinarySearchTreeADT.java"
package util;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
public interface BinarySearchTreeADT {
public void add(Comparable item) throws DuplicateElementException;
public Iterator<Comparable> iterator() throws ConcurrentModificationException,
UnsupportedOperationException;
public String printTree();
public void remove(Comparable item);
}
Here is the code for "DuplicateElementException.java"
package util;
public class DuplicateElementException extends RuntimeException {
}
Here is the code for "Program.java"
package util;
import java.util.Iterator;
import util.BinarySearchTree;
import java.util.TreeSet;
public class Program {
private static final String NAME = "D3158";
public static void main(String[] args) {
BinarySearchTree tree = new BinarySearchTree();
System.out.println("BST: " + Program.NAME);
System.out.println("= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =");
tree.add("Eve");
tree.add("Pam");
tree.add("Zoe");
tree.add("Cam");
tree.add("Lee");
tree.add("Joy");
System.out.println("\nBinary search tree after add: Eve Pam Zoe Cam Lee Joy");
System.out.print(tree.printTree());
System.out.println("= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =");
tree.add("Ivy");
tree.add("Abe");
tree.add("Fay");
System.out.println("\nBinary search tree after add: Ivy Abe Fay");
System.out.print(tree.printTree());
System.out.println("= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =");
System.out.println("\nIterator output\n");
for (Iterator<Comparable> it = tree.iterator(); it.hasNext();) {
System.out.print(it.next() + " ");
}
System.out.println("\n\n= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =");
tree.remove("Lee");
tree.remove("Cam");
tree.remove("Abe");
System.out.println("\nBinary search tree after remove: Lee Cam Abe");
System.out.print(tree.printTree());
System.out.println("= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =");
}
}
|
|
|
|
|
Are you asking us to review your code, rewrite it for you, or give you an algorithm for how a balanced binary tree should work?
|
|
|
|
|
Review the code, of course. Then rewrite the code(with comments possibly, so I can understand it better) which is a big time request. I am struggling big time with it. Please assist me.
|
|
|
|
|
can you answer me:
How do you define the Binary Seach Tree(BST)?
if you define by List Link you can repair struct of two tree:
step 1: find possible of root of tree 2 in tree 1;
step 2: replace link at this possible
step 3: ok;
|
|
|
|
|
Bug is:</b> <b>{"error":{"lang":"en-US","description":"Please provide valid credentials. OAuth oauth_problem=\"signature_invalid\", realm=\"yahooapis.com\""}},
package yahoo.contast.query;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.GeneralSecurityException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.scribe.services.HMACSha1SignatureService;
import sun.misc.BASE64Encoder;
public class Login{
private static final String CONSUMER_KEY = "dj0yJmk9RzNIMEI3NXNMTXdPJmQ9WVdrOVRWQnZjREZvTlRZbWNHbzlPRGs0T0RZM05UWXkmcz1jb25zdW1lcnNlY3JldCZ4PWM0";
private static String CONSUMER_SECRET = "e2ac48448a54afa7d6eae9033f702e3e6e420011";
public static void main(String[] args) throws Exception {
String userName = ".....@yahoo.com.vn";
String password = "123456";
HttpClient client = new HttpClient();
client.getParams().setParameter(
HttpMethodParams.USER_AGENT,
"Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");
PostMethod post = new PostMethod("https://login.yahoo.com/WSLogin /V1/get_auth_token?&login="+userName+"&passwd="+password+"&oauth_consumer_key="+CONSUMER_KEY+"&xoauth_lang_pref=en-us");
post.setDoAuthentication(true);
client.executeMethod(post);
String requestTokent = requestTokent = post.getResponseBodyAsString();
System.out.println(requestTokent);
long timeStamp = System.currentTimeMillis() / 1000;
String[] temp = requestTokent.split("=");
String signatureToken = URLEncoder.encode(CONSUMER_SECRET+"&");
String url = "https://api.login.yahoo.com/oauth/v2/get_token?oauth_consumer_key="+CONSUMER_KEY+"&oauth_signature_method=plaintext&oauth_version=1.0&oauth_timestamp="+timeStamp+"&oauth_nonce=8B9SaF&oauth_signature="+signatureToken+"&oauth_token="+temp[1]+"";
GetMethod getToken = new GetMethod(url);
client.executeMethod(getToken);
String token = getToken.getResponseBodyAsString();
System.out.println("Token: "+ token);
String param[] = token.split("&");
String oauthTokenSplit[] = param[0].split("=");
String oauthToken = oauthTokenSplit[1];
String ouathTokenSecret = param[1].replace("oauth_token_secret=", "");
String ouathExpriresIn = param[2];
String ouathSessionHandle = param[3].replace("oauth_session_handle=", "");
String ouathAuthoriztion = param[4];
String xouathYahooGuid = param[5].replace("xoauth_yahoo_guid=", "");
long timeStampRefresh = System.currentTimeMillis() / 1000;
String signatureRefresh = URLEncoder.encode( CONSUMER_SECRET + "&" + ouathTokenSecret );
String urlRefresh = "https://api.login.yahoo.com/oauth>/v2/get_token?oauth_consumer_key="+CONSUMER_KEY+"&oauth_signature_method=PLAINTEXT&oauth_version=1.0&oauth_timestamp="+timeStampRefresh+"&oauth_nonce=8B9SkF&oauth_signature="+signatureRefresh+"&oauth_token="+oauthToken+"&oauth_session_handle="+ouathSessionHandle+"";
PostMethod refreshToken = new PostMethod(urlRefresh);
client.executeMethod(refreshToken);
String refresh = refreshToken.getResponseBodyAsString();
System.out.println("Token Refresh: "+refresh);
String paramRefresh[] = refresh.split("&");
String oauthTokenRefresh = paramRefresh[0].replace("oauth_token=", "");
String oauthTokenSecretRefresh = paramRefresh[1].replace("oauth_token_secret=", "");
String ouathSessionHandleRefresh = paramRefresh[3].replace("oauth_session_handle=", "");
String guid = paramRefresh[5].replace("xoauth_yahoo_guid=", "");
long profileTimeStamp = System.currentTimeMillis();
profileTimeStamp = profileTimeStamp / 1000;
String baseString = "GET&" + URLEncoder.encode("http://social.yahooapis.com/v1/user/"+guid+"/profile?format=json&oauth_consumer_key="+CONSUMER_KEY+"&oauth_nonce=24829869585&oauth_signature_method=HMAC-SHA1&oauth_timestamp="+profileTimeStamp+"&oauth_token="+oauthTokenRefresh+"&oauth_version=1.0");
HMACSha1SignatureService hmacSha1SignatureService = new HMACSha1SignatureService();
String signatureProfile = hmacSha1SignatureService.getSignature( baseString, CONSUMER_SECRET, oauthTokenSecretRefresh );
signatureProfile = URLEncoder.encode(signatureProfile,"utf-8");
GetMethod profile = new GetMethod("http://social.yahooapis.com/v1/user/"+guid+"/profile?format=json&realm=yahooapis.com&oauth_consumer_key="+CONSUMER_KEY+"&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_timestamp="+profileTimeStamp+"&oauth_nonce=24829869585&oauth_token="+oauthTokenRefresh+"&oauth_signature="+signatureProfile+"");
client.executeMethod(profile);
String profileResponse = profile.getResponseBodyAsString();
System.out.println(profileResponse);
}
}
</code>
modified on Wednesday, June 22, 2011 3:05 AM
|
|
|
|
|
Please format that mess as a "code block" - no one is willing to read this otherwise.
Where is the problem? did you debug it?
I never finish anyth...
|
|
|
|
|
Okie! I'm formated code, please you help me ?
|
|
|
|
|
great. Please feel free to provide more information as you also want some lines as answer.
- where at Yahoo are you trying to login? mail? social stuff? other?
- what kind of exception did you get? Post the exception!
regards Torsten
I never finish anyth...
|
|
|
|
|
Exception:
{"error":{"lang":"en-US","description":"Please provide valid credentials. OAuth oauth_problem=\"signature_invalid\", realm=\"yahooapis.com\""}}
Here, I'm used Yahoo API get profile information of user. Frist I'm get request token, after I'm used request token get access token and parameter, final I'm used access token and parameter get profile of user. but I've encountered one bug \"signature_invalid\" in the final step.
|
|
|
|
|
see - the exception says:
Please provide valid credentials
so please check them. It's not fun, but they are broke.
regards Torsten
I never finish anyth...
|
|
|
|
|
This sounds a rather specific problem. You might find asking on a yahoo API programmers' forum that you'll get more help.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
"Please provide valid credentials" - the error is quite clear.
|
|
|
|
|
I have one project java . I want read book.xml by SAX sample . You have dowload my project to check erro http://www.mediafire.com/?a721nrt49a7eokv[^]
this struct of Book.xml :
<?xml version="1.0"?><br />
<catalog><br />
<book id="bk101"><br />
<author>Gambardella, Matthew</author><br />
<title>XML Developer's Guide</title><br />
<genre>Computer</genre><br />
<price>44.95</price><br />
<publish_date>2000-10-01</publish_date><br />
<description>An in-depth look at creating applications <br />
with XML.</description><br />
</book><br />
<book id="bk102"><br />
<author>Ralls, Kim</author><br />
<title>Midnight Rain</title><br />
<genre>Fantasy</genre><br />
<price>5.95</price><br />
<publish_date>2000-12-16</publish_date><br />
<description>A former architect battles corporate zombies, <br />
an evil sorceress, and her own childhood to become queen <br />
of the world.</description><br />
</book><br />
<book id="bk103"><br />
<author>Corets, Eva</author><br />
<title>Maeve Ascendant</title><br />
<genre>Fantasy</genre><br />
<price>5.95</price><br />
<publish_date>2000-11-17</publish_date><br />
<description>After the collapse of a nanotechnology <br />
society in England, the young survivors lay the <br />
foundation for a new society.</description><br />
</book><br />
<book id="bk104"><br />
<author>Corets, Eva</author><br />
<title>Oberon's Legacy</title><br />
<genre>Fantasy</genre><br />
<price>5.95</price><br />
<publish_date>2001-03-10</publish_date><br />
<description>In post-apocalypse England, the mysterious <br />
agent known only as Oberon helps to create a new life <br />
for the inhabitants of London. Sequel to Maeve <br />
Ascendant.</description><br />
</book><br />
<book id="bk105"><br />
<author>Corets, Eva</author><br />
<title>The Sundered Grail</title><br />
<genre>Fantasy</genre><br />
<price>5.95</price><br />
<publish_date>2001-09-10</publish_date><br />
<description>The two daughters of Maeve, half-sisters, <br />
battle one another for control of England. Sequel to <br />
Oberon's Legacy.</description><br />
</book><br />
<book id="bk106"><br />
<author>Randall, Cynthia</author><br />
<title>Lover Birds</title><br />
<genre>Romance</genre><br />
<price>4.95</price><br />
<publish_date>2000-09-02</publish_date><br />
<description>When Carla meets Paul at an ornithology <br />
conference, tempers fly as feathers get ruffled.</description><br />
</book><br />
<book id="bk107"><br />
<author>Thurman, Paula</author><br />
<title>Splish Splash</title><br />
<genre>Romance</genre><br />
<price>4.95</price><br />
<publish_date>2000-11-02</publish_date><br />
<description>A deep sea diver finds true love twenty <br />
thousand leagues beneath the sea.</description><br />
</book><br />
<book id="bk108"><br />
<author>Knorr, Stefan</author><br />
<title>Creepy Crawlies</title><br />
<genre>Horror</genre><br />
<price>4.95</price><br />
<publish_date>2000-12-06</publish_date><br />
<description>An anthology of horror stories about roaches,<br />
centipedes, scorpions and other insects.</description><br />
</book><br />
<book id="bk109"><br />
<author>Kress, Peter</author><br />
<title>Paradox Lost</title><br />
<genre>Science Fiction</genre><br />
<price>6.95</price><br />
<publish_date>2000-11-02</publish_date><br />
<description>After an inadvertant trip through a Heisenberg<br />
Uncertainty Device, James Salway discovers the problems <br />
of being quantum.</description><br />
</book><br />
<book id="bk110"><br />
<author>O'Brien, Tim</author><br />
<title>Microsoft .NET: The Programming Bible</title><br />
<genre>Computer</genre><br />
<price>36.95</price><br />
<publish_date>2000-12-09</publish_date><br />
<description>Microsoft's .NET initiative is explored in <br />
detail in this deep programmer's reference.</description><br />
</book><br />
<book id="bk111"><br />
<author>O'Brien, Tim</author><br />
<title>MSXML3: A Comprehensive Guide</title><br />
<genre>Computer</genre><br />
<price>36.95</price><br />
<publish_date>2000-12-01</publish_date><br />
<description>The Microsoft MSXML3 parser is covered in <br />
detail, with attention to XML DOM interfaces, XSLT processing, <br />
SAX and more.</description><br />
</book><br />
<book id="bk112"><br />
<author>Galos, Mike</author><br />
<title>Visual Studio 7: A Comprehensive Guide</title><br />
<genre>Computer</genre><br />
<price>49.95</price><br />
<publish_date>2001-04-16</publish_date><br />
<description>Microsoft Visual Studio 7 is explored in depth,<br />
looking at how Visual Basic, Visual C++, C#, and ASP+ are <br />
integrated into a comprehensive development <br />
environment.</description><br />
</book><br />
</catalog><br />
The First , i read Books.xml by startElement(),endElement(). At endElement(), instale object Books class and add it in the ArrayList(listBook).I used method getListBook() return ArrayList <books> . At main() in class xxx.java, i print console by "read" all object in List.
Thank
|
|
|
|
|
Point 1: use the proper <pre> tags to format your code rather than the inline <code> tags (go back and edit your original message).
Point 2: Nobody is going to download your project in order to find out what's wrong with your code. Compile and test your program, find out what or where it is going wrong, and post a proper description of your problem; people will then try to help you.
The best things in life are not things.
|
|
|
|
|
i` sorry !! i will fix the message at night . i`m very bussiness,now
i`m very sorry!!!
|
|
|
|
|
Can anybody tell me, Hoew to capture the image from webcam using java code ?,...................
I need for my project...
|
|
|
|
|
Here's an example[^] that may help.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
Hi folks!
this is the code thats giving me problems.
try{
ResultSet rs = Main.dbase.search("select * from myTable");
while(rs.next())
{
cmb.addItem(rs.getString(1).trim());
}
rs.close();
} catch (Exception ex) {System.out.println(ex);}
here dbase is an object executing Statement.executeQuery , and cmb is JComboBox.
the problem is that even though the table has 10 rows, i get only single row in cmb.
if I don't comment out the first rs.next() , i get the 2nd row in cmb.
i tried to track the value of rs.next() and found that after while(rs.next()) it gives out false , always.
My target is to get all the 10 values in cmb.
TheMrProgrammer
http://www.icbse.com/2009/funny-exam-answers-school-students
http://download.cnet.com/TheCalcMan/3000-2094_4-10958266.html
|
|
|
|
|
Have a go at this:
Statement statement = null;
try {
statement = Main.dbase.createStatement();
ResultSet rs = statement.executeQuery("select * from myTable");
while (rs.next()) {
cmb.addItem(rs.getString(1).trim());
}
} catch (SQLException e ) {
System.out.println(ex);
} finally {
if (statement != null) {
statement.close();
}
}
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
Myself I can't see how that answers the OPs question.
|
|
|
|
|