What complexity are the methods multiply, divide and pow in BigInteger currently? There is no mention of the computational complexity in the documentation (nor anywhere else).
hi,
need to convert a pdf file to a doc file. I found different type of example to generate pdf file but not got pdf to doc.
please help me in this regard with good example or source code or guideline.
I am trying to create a database of users with connection between users (friends list).
There are 2 main tables: UserEntity (main field id) and FriendEntity with fields:
- initiatorId - id of user who initiated the friendship
- friendId - id of user who has been invited.
Now I am trying to fetch all friends of one particular user and encountered some problems with using subqueries in JDO here.
Logically the query should be something like this:
SQL: SELECT * FROM UserEntity WHERE EXISTS (SELECT * FORM FriendEntity WHERE (initiatorId == UserEntity.id && friendId == userId) || (friendId == UserEntity.id && initiatorId == userId))
or SELECT * FROM UserEntity WHERE userId IN (SELECT * FROM FriendEntity WHERE initiatorId == UserEntity.id) OR userId IN (SELECT * FROM FriendEntity WHERE friendId == UserEntity.id)
So to replicate the last query in JDOQL, I tried to do the following:
Query friendQuery = pm.newQuery(FriendEntity.class);
friendQuery.setFilter("initiatorId == uidParam");
friendQuery.setResult("friendId");
Query initiatorQuery = pm.newQuery(FriendEntity.class);
initiatorQuery.setFilter("friendId == uidParam");
initiatorQuery.setResult("initiatorId");
Query query = pm.newQuery(UserEntity.class);
query.setFilter("initiatorQuery.contains(id) || friendQuery.contains(id)");
query.addSubquery(initiatorQuery, "List initiatorQuery", null, "String uidParam");
query.addSubquery(friendQuery, "List friendQuery", null, "String uidParam");
query.declareParameters("String uidParam");
List<UserEntity> friends = (List<UserEntity>) query.execute(userId);
In result I get the following error:
Unsupported method while parsing expression.
Could anyone help with this query please?
Hello, I know the following code could extract whole texts of the docx document, however, I need to extract paragraph instead. Is there are possible way??
public static String extractText(InputStream in) throws Exception {
JOptionPane.showMessageDialog(null, "Start extracting docx");
XWPFDocument doc = new XWPFDocument(in);
XWPFWordExtractor ex = new XWPFWordExtractor(doc);
String text = ex.getText();
return text;
}
Any helps would much appreciated. I need this so urgently.
Here's what I am looking to accomplish, I have a class that has an enum of some values and I want to subclass that and add more values to the enum. This is a bad example, but:
public class Digits
{
public enum Digit
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
}
}
public class HexDigits extends Digits
{
public enum Digit
{
A, B, C, D, E, F
}
}
so that HexDigits.Digit contains all Hex Digits. Is that possible?
I am a building a console Sudoku Solver where the main objective is raw speed.
I now have a ManagerThread that starts WorkerThreads to compute the neibhbors of each cell. So one WorkerThread is started for each cell right now. How can I re-use an existing thread that has completed its work?
The Thread Pool Pattern seems to be the solution, but I don't understand what to do to prevent the thread from dying once its job has been completed.
ps : I do not expect to gain much performance for this particular task, just want to experiment how multi-threading works before applying it to the more complex parts of the code.
Thanks
I need to split a text using the separator ". ". For example I want this string :
Washington is the U.S Capital. Barack is living there.
To be cut into two parts:
Washington is the U.S Capital.
Barack is living there.
Here is my code :
// Initialize the tokenizer
StringTokenizer tokenizer = new StringTokenizer("Washington is the U.S Capital. Barack is living there.", ". ");
while (tokenizer.hasMoreTokens()) {
System.out.println(tokenizer.nextToken());
}
And the output is unfortunately :
Washington
is
the
U
S
Capital
Barack
is
living
there
Can someone explain what's going on?
Suppose I have a string that contains '¿'. How would I find all those unicode characters? Should I test for their code? How would I do that?
I want to detect it to avoid sax parser exception which I am getting it while parsing the xml
saved as a clob in oracle 10g database.
Exception
javax.servlet.ServletException: org.xml.sax.SAXParseException: Invalid byte 1 of 1-byte UTF-8 sequence.
I am writing a simple multithreaded socketserver and I am wondering how best to handle incoming connections:
create a new thread for each new connection. The number of concurrent threads would be limited and waiting connections limited by specifying a backlog
add all incoming connections into a queue and have a pool of worker threads that process the queue
I am inclined to go for option 2 because I really don't want to refuse any connections, even under high loads, but I am wondering if there are any considerations I should be aware of with accepting effectively unlimited connections?
I am relatively new to multi-threading and want to execute a background task using a Swingworker thread - the method that is called does not actually return anything but I would like to be notified when it has completed.
The code I have so far doesn't appear to be working:
private void crawl(ActionEvent evt)
{
try
{
SwingWorker<Void, Void> crawler = new SwingWorker<Void, Void>()
{
@Override
protected Void doInBackground() throws Exception
{
Discoverer discover = new Discoverer();
discover.crawl();
return null;
}
@Override
protected void done()
{
JOptionPane.showMessageDialog(jfThis, "Finished Crawling", "Success", JOptionPane.INFORMATION_MESSAGE);
}
};
crawler.execute();
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(this, ex.getMessage(), "Exception", JOptionPane.ERROR_MESSAGE);
}
}
Any feedback/advice would be greatly appreciated as multi-threading is a big area of programming that I am weak in.
when looping, for instance:
for ( int j = 0; j < 1000; j++) {}; and I need to instantiate 1000 objects, how does it differ when I declare the object inside the loop from declaring it outside the loop ??
for ( int j = 0; j < 1000; j++) {Object obj; obj =}
vs
Object obj;
for ( int j = 0; j < 1000; j++) {obj =}
It's obvious that the object is accessible either only from the loop scope or from the scope that is surrounding it. But I don't understand the performance question, garbage collection etc.
What is the best practice ? Thank you
Right, this is from an older exam which i'm using to prepare my own exam in january. We are given the following method:
public static void Oorspronkelijk()
{
String bs = "Dit is een boodschap aan de wereld";
int max = -1;
char let = '*';
for (int i=0;i<bs.length();i++) {
int tel = 1;
for (int j=i+1;j<bs.length();j++) {
if (bs.charAt(j) == bs.charAt(i)) tel++;
}
if (tel > max) {
max = tel;
let = bs.charAt(i);
}
}
System.out.println(max + " keer " + let);
}
The questions are:
what is the output? - Since the code is just an algorithm to determine the most occuring character, the output is "6 keer " (6 times space)
What is the time complexity of this code?
Fairly sure it's O(n²), unless someone thinks otherwise?
Can you reduce the time complexity, and if so, how?
Well, you can. I've received some help already and managed to get the following code:
public static void Nieuw()
{
String bs = "Dit is een boodschap aan de wereld";
HashMap<Character, Integer> letters = new HashMap<Character, Integer>();
char max = bs.charAt(0);
for (int i=0;i<bs.length();i++) {
char let = bs.charAt(i);
if(!letters.containsKey(let)) {
letters.put(let,0);
}
int tel = letters.get(let)+1;
letters.put(let,tel);
if(letters.get(max)<tel) {
max = let;
}
}
System.out.println(letters.get(max) + " keer " + max);
}
However, I'm uncertain of the time complexity of this new code: Is it O(n) because you only use one for-loop, or does the fact we require the use of the HashMap's get methods make it O(n log n) ?
And if someone knows an even better way of reducing the time complexity, please do tell! :)
<resource name="cde.xml" status="updated" isCollection="false">
<mediaType>xml</mediaType>
<creator>admin</creator>
<createdTime>1352783477964</createdTime>
<lastUpdater>admin</lastUpdater>
<lastModified>1352783477964</lastModified>
<description />
<version>0</version>
<content>ZGFza2QgbGQgbGt2Zmx3ZGFzamQgYWRsa2ogYWxramRrbGEgamQK
</content>
</resource>
i want to catch nodes which are having status using xpath here is the xpath expression other part of the code is correct. I have problem with xpath expression
AXIOMXPath xpathExpression = new AXIOMXPath ( "//resourse[@name]");
I would like to know what is the best, fastest and easiest way to compare between 2-dimension arrays of integer.
the length of arrays is the same. (one of the array's is temporary array)
thanks.
Hello,
Im using Collections.sort() to sort a LinkedList whose elements implements Comparable interface, so they are sorted in a natural order. In the javadoc documentation its said this method uses mergesort algorithm wich has n*log(n) performance.
My question is if there is a more efficient algorithm to sort my LinkedList?
The size of that list could be very high and sort will be also very frequent.
Thanks!
I have a program where I am generating two double numbers by adding several input prices from a file based on a condition.
String str;
double one = 0.00;
double two = 0.00;
BufferedReader in = new BufferedReader(new FileReader(myFile));
while((str = in.readLine()) != null){
if(str.charAt(21) == '1'){
one += Double.parseDouble(str.substring(38, 49) + "." + str.substring(49, 51));
}
else{
two += Double.parseDouble(str.substring(38, 49) + "." + str.substring(49, 51));
}
}
in.close();
System.out.println("One: " + one);
System.out.println("Two: " + two);
The output is like:
One: 2773554.02
Two: 6.302505836000001E7
Question:
None of the input have more then two decimals in them. The way one and two are getting calculated exactly same.
Then why the output format is like this.
What I am expecting is:
One: 2773554.02
Two: 63025058.36
Why the printing is in two different formats ? I want to write the outputs again to a file and thus there must be only two digits after decimal.
Recently i've found myself writing a lot of methods with what i can only think to call debugging scaffolding. Here's an example:
public static void printArray (String[] array, boolean bug)
{
for (int i = 0; i<array.lenght; i++)
{
if (bug) System.out.print (i) ; //this line is what i'm calling the debugging scaffolding i guess.
System.out.println(array[i]) ;
}
}
in this method if i set bug to true, wherever its being called from maybe by some kind of user imput, then i get the special debugging text to let me know what index the string being printed as at just in case i needed to know for the sake of my debugging (pretend a state of affairs exists where its helpful).
All of my questions more or less boil down to the question: is this a good idea? but with a tad bit more objectivity:
Is this an effective way to test my
methods and debug them? i mean effective in terms of efficiency and not messing up my code.
Is it acceptable to leave the if
(bug) stuff ; code in place after
i've got my method up and working?
(if a definition of "acceptability"
is needed to make this question
objective then use "is not a matter
of programing controversy such as
ommiting brackets in an if(boolean)
with only one line after it, though
if you've got something better go
ahead and use your definition i won't
mind)
Is there a more effective way to
accomplish the gole of making
debugging easier than what i'm doing?
Anything you know i mean to ask but
that i have forgotten too (as much
information as makes sense is
appreciated).
I have written this piece of code to break an image into 9 pieces and it gives me runtime error. There is no error in LogCat and I am stuck. The error comes at line 7 line from bottom (Bitmap.createBitmap(...);).
public Bitmap[] getPieces(Bitmap bmp) {
Bitmap[] bmps = new Bitmap[9];
int width = bmp.getWidth();
int height = bmp.getHeight();
int rows = 3;
int cols = 3;
int cellHeight = height / rows;
int cellWidth = width / cols;
int piece = 0;
for (int x = 0; x <= width; x += cellWidth) {
for (int y = 0; y <= height; y += cellHeight) {
Bitmap b = Bitmap.createBitmap(bmp, x, y, cellWidth,
cellHeight, null, false);
bmps[piece] = b;
piece++;
}
}
return bmps;
}
i have installed open cms on my local machine and it perfectly works fine.
But in order to work it corre,ty it is mentioned that i have to modify the my.ini file and set max_alllowed_packed site to 32
I have done it and it works perfectly fine
but can i modify this file if i use a third party hosting provider for tomcat and mysql??