I would like to time how long the program takes to insert in the tree to measure the efficiency of a TreeMap's inserting. I also want to measure how long it takes to sort separately. I am doing this for a report I am writing where I am comparing the inserting time and sorting time for a TreeMap, linkedList and ArrayList. For the linkedList and ArrayList I am just going to insert all and measure first, then call list.sort(comparator) and measure how long it takes to sort. I am not sure how to do this for a TreeMap though.   final long startTime = System.currentTimeMillis();             Comparator&lt;String&gt; secondCharComparator = new Comparator&lt;String&gt;() {                     @Override public int compare(String s1, String s2) {                         return s1.substring(1, 2).compareTo(s2.substring(1, 2));                     }                            };          SortedMap&lt;String,String&gt; map =                 new TreeMap&lt;String,String&gt;(secondCharComparator);             map.put("a", "one");             map.put("a", "two");             map.put("cd", "three");     final long endTime = System.currentTimeMillis();  long totalTime = endTime - startTime;
27793
How do I get a method's execution time?   Is there a Timer utility class for things like timing how long a task takes, etc?     Most of the searches on Google return results for timers that schedule threads and tasks, which is not what I want.
79598
I wonder if there is a counterpart to java.util.LinkedHashMap in .NET? (ie. the elements are (re)ordered automatically if I access an element. (boolean accessOrder) ).
66606
I'm working on a batch which getting a params from another batch in the finish method.  The Params are :    A Map - Map&lt;Sobject,Set&lt;String&gt;&gt; A Set -  Set&lt;String&gt;   I lost the values of my Map on the second run of the execution method - Means - Map.get(Sobject) returned with null although it had values in it.  That happened only within the second to the last run of the batch (from the second till the end of the chunks).  The first chunk getting the values as expected.  I guess it could be because defined a Sobject as a Key in a Map is not Best Practice because Hashing issue - Because the second param that I'm sending to the batch is a Set&lt;String&gt; - And it keeps its values for all the chunks.   Because of this issue, I decided to send a Set&lt;Id&gt; of all the Sobjects from the first batch, and retrieve the records in the second batch with SOQL query. and I wanted to know what are the best practices to do so.  the queryLocatoer in the Start method is needed to go over another Sobject without any related to the Sobject that I sent.  Where can I put this Query? Can I put it inside the Constructor and assign it to a global variable? Inside the Start method before I set the query for the queryLocator? - since it always will be the same results, I don't want to put it on the execute method.  What do you think? Why we have hashing issue when the key of a Map is a Sobject?  Thanks!
12956
I want to develop a simple GIS application using GeoTools. I have looked at the tutorials but i could get to much meaningful from them.   I have a simple JMapFrame to which add can add a featureLayer from a shapefile  public void action(ActionEvent e) throws Throwable{     sourceFile = JFileDataStoreChooser.showOpenFile("shp", null);     if (sourceFile == null) {         return;     }     FileDataStore store = FileDataStoreFinder.getDataStore(sourceFile);     featureSource = store.getFeatureSource();      Style style = SLD.createSimpleStyle(featureSource.getSchema());     Layer layer = new FeatureLayer(featureSource, style);     map.addLayer(layer); }   Now, lets say I want to create a buffer around my features. From what I have understood I have to get the featureSource, then create a featureCollection, iterate through the features and for each of those feature I have to cast them to a Geometry, then create a buffer.   When I have created a buffer should I go all the way back to featureLayer and add it to my map?
84853
Comment on Duplicate Reference: Why would this be marked duplicate when it was asked years prior to the question referenced as a duplicate?  I also believe the question, detail, and response is much better than the referenced question.  I've been a C++ programmer for quite a while but I'm new to Java and new to Eclipse.  I want to use the  to visualize some data I'm working with.  This code is organized like this:  ./com ./com/touchgraph ./com/touchgraph/graphlayout ./com/touchgraph/graphlayout/Edge.java ./com/touchgraph/graphlayout/GLPanel.java ./com/touchgraph/graphlayout/graphelements ./com/touchgraph/graphlayout/graphelements/GESUtils.java ./com/touchgraph/graphlayout/graphelements/GraphEltSet.java ./com/touchgraph/graphlayout/graphelements/ImmutableGraphEltSet.java ./com/touchgraph/graphlayout/graphelements/Locality.java ./com/touchgraph/graphlayout/graphelements/TGForEachEdge.java ./com/touchgraph/graphlayout/graphelements/TGForEachNode.java ./com/touchgraph/graphlayout/graphelements/TGForEachNodePair.java ./com/touchgraph/graphlayout/graphelements/TGNodeQueue.java ./com/touchgraph/graphlayout/graphelements/VisibleLocality.java ./com/touchgraph/graphlayout/GraphLayoutApplet.java ./com/touchgraph/graphlayout/GraphListener.java ./com/touchgraph/graphlayout/interaction ./com/touchgraph/graphlayout/interaction/DragAddUI.java ./com/touchgraph/graphlayout/interaction/DragMultiselectUI.java ./com/touchgraph/graphlayout/interaction/DragNodeUI.java ./com/touchgraph/graphlayout/interaction/GLEditUI.java ./com/touchgraph/graphlayout/interaction/GLNavigateUI.java ./com/touchgraph/graphlayout/interaction/HVRotateDragUI.java ./com/touchgraph/graphlayout/interaction/HVScroll.java ./com/touchgraph/graphlayout/interaction/HyperScroll.java ./com/touchgraph/graphlayout/interaction/LocalityScroll.java ./com/touchgraph/graphlayout/interaction/RotateScroll.java ./com/touchgraph/graphlayout/interaction/TGAbstractClickUI.java ./com/touchgraph/graphlayout/interaction/TGAbstractDragUI.java ./com/touchgraph/graphlayout/interaction/TGAbstractMouseMotionUI.java ./com/touchgraph/graphlayout/interaction/TGAbstractMousePausedUI.java ./com/touchgraph/graphlayout/interaction/TGSelfDeactivatingUI.java ./com/touchgraph/graphlayout/interaction/TGUIManager.java ./com/touchgraph/graphlayout/interaction/TGUserInterface.java ./com/touchgraph/graphlayout/interaction/ZoomScroll.java ./com/touchgraph/graphlayout/LocalityUtils.java ./com/touchgraph/graphlayout/Node.java ./com/touchgraph/graphlayout/TGAbstractLens.java ./com/touchgraph/graphlayout/TGException.java ./com/touchgraph/graphlayout/TGLayout.java ./com/touchgraph/graphlayout/TGLensSet.java ./com/touchgraph/graphlayout/TGPaintListener.java ./com/touchgraph/graphlayout/TGPanel.java ./com/touchgraph/graphlayout/TGPoint2D.java ./com/touchgraph/graphlayout/TGScrollPane.java ./TG-APACHE-LICENSE.txt ./TGGL ReleaseNotes.txt ./TGGraphLayout.html ./TGGraphLayout.jar   How do I add this project in Eclipse and get it compiling and running quickly?
119337
I want to record the time a user has spent on my particular node so I could show a pop up to the user to register once the user has read 3 article. But the user must have spent at least 30 seconds on each node.   There is the  module available, but I wonder if I can merge it with another (custom) module I have created (which records the number of nodes user have visited)?
47480
I'm trying to measure the execution time of a process that I call via the command line (i.e., I want to find out how long it takes to for the process to finish). Is there any command that I can add to the command calling the process that will achieve this?
1905
I ran into an interesting (and very frustrating) issue with the equals() method today which caused what I thought to be a well tested class to crash and cause a bug that took me a very long time to track down.   Just for completeness, I wasn't using an IDE or debugger - just good old fashioned text editor and System.out's. Time was very limited and it was a school project.  Anyhow -   I was developing a basic shopping cart which could contain an ArrayList of Book objects. In order to implement the addBook(), removeBook(), and hasBook() methods of the Cart, I wanted to check if the Book already existed in the Cart. So off I go -  public boolean equals(Book b) {     ... // More code here - null checks     if (b.getID() == this.getID()) return true;     else return false; }   All works fine in testing. I create 6 objects and fill them with data. Do many adds, removes, has() operations on the Cart and everything works fine. I read that you can either have equals(TYPE var) or equals(Object o) { (CAST) var } but assumed that since it was working, it didn't matter too much.  Then I ran into a problem - I needed to create a Book object with only the ID in it from within the Book class. No other data would be entered into it. Basically the following:  public boolean hasBook(int i) {     Book b = new Book(i);     return hasBook(b); }  public boolean hasBook(Book b) {     // .. more code here     return this.books.contains(b); }   All of a sudden, the equals(Book b) method no longer works. This took a VERY long time to track down without a good debugger and assuming the Cart class was properly tested and correct. After swaapping the equals() method to the following:  public boolean equals(Object o) {     Book b = (Book) o;     ... // The rest goes here    }   Everything began to work again. Is there a reason the method decided not to take the Book parameter even though it clearly  was  a Book object? The only difference seemed to be it was instantiated from within the same class, and only filled with one data member. I'm very very confused. Please, shed some light?
46114
First of all, I swear this is not homework, it's a question I was asked in an interview. I think I made a mess of it (though I did realise the solution requires recursion). Here is the question:  Implement the count() method which returns the number of nodes in a tree. If a node doesn't have either a left or right child, the relevant getXXChild() method will return null  class Tree {    Tree getRightChild() {     // Assume this is already implemented   }    Tree getLeftChild() {     // Assume this is already implemented   }    int count() {     // Implement me   } }   My reason for asking the question is simply curious to see the correct solution, and thereby measure how bad mine was.  Cheers, Tony
118759
Question  I'm writing some code that needs to be able to get the values of the parameters from the method that called into the class. I know how to get all the way to the ParameterInfo[] array, but I don't know how to then get the values. Is this even possible?  If it is, I think it has something to do with using the MethodBody property from the MethodInfo object, which allows you to inspect the IL stream, including properties, but I don't know how to do it, and I haven't found applicable code on Google.  Code  // Finds calling method from class that called into this one public class SomeClass {     public static void FindMethod()     {         for (int i = 1; i &lt; frameCount; i++)         {             var frame = new StackFrame(i);             var methodInfo = frame.GetMethod();             if (methodInfo.DeclaringType != this.GetType())             {                 string methodName = frame.GetMethod().Name;                 var paramInfos = methodInfo.GetParameters();                  // Now what?? How do I get the values from the paramInfos                  break;             }             else if (i == frameCount - 1)             {                 throw new TransportException("Couldn't find method name");             }         }     } }
14775
There is a case where a map will be constructed, and once it is initialized, it will never be modified again.  It will however, be accessed (via get(key) only) from multiple threads.  Is it safe to use a java.util.HashMap in this way?  (Currently, I'm happily using a java.util.concurrent.ConcurrentHashMap, and have no measured need to improve performance, but am simply curious if a simple HashMap would suffice.  Hence, this question is not "Which one should I use?" nor is it a performance question.  Rather, the question is "Would it be safe?")
8001
I am currently looking at the various libraries that I can use to show a map in my custom Android App. I have found several like Mapsforge, OSMDroid, ArcGIS runtime for Android, Google Maps for Android and so on. I'm sure that I am missing a few.   Is there a comparison chart somewhere about the differences in functionalities and pros and cons of each one?   If there isn't one, we could make this question community wiki, to serve alongside  &amp; .
54872
I'm generating a level, and I have an optional delay to show the steps level generation one by one.  If my generationDelay boolean is true, I want to use StartCoroutine to spread the generation out over time. If it's false, I want to call the same method but without StartCoroutine.  The problem is that the method is type IEnumerator.  I can make two methods one type of IEnumerator and one not. But I wonder if there is a way to use one method.  In the first script top i did:  public bool generationDelay = false;   Then in a method:  private void BeginGame()     {         mazeInstance = Instantiate(mazePrefab) as Maze;          if (generationDelay == true)         {             StartCoroutine(mazeInstance.Generate(generationDelay));         }         else         {             mazeInstance.Generate(generationDelay);         }     }   Then the other script where the method Generate is: In the top:  public float generationStepDelay = 0.01f;   Then the method Generate:  public IEnumerator Generate (bool generationDelay) {          if (generationDelay == true)             WaitForSeconds delay = new WaitForSeconds(generationStepDelay);         cells = new MazeCell[size.x, size.z];         List&lt;MazeCell&gt; activeCells = new List&lt;MazeCell&gt;();         DoFirstGenerationStep(activeCells);         while (activeCells.Count &gt; 0) {             yield return delay;             DoNextGenerationStep(activeCells);         }     }   I'm getting an error on the line:   WaitForSeconds delay = new WaitForSeconds(generationStepDelay);      "Embedded statement cannot be a declaration or labeled statement"   And an error on the line:  yield return delay;      "The name 'delay' does not exist in the current context"   The reason I want to use a bool variable is that when i'm using StartCoroutine it's kind of slow, even if I change the value of generationStepDelay to 0 it's kind of slow. And if I'm not using StartCoroutine and not using the Generate method as IEnumerator it will work fast.  So i wonder what should I do and how?
17527
I am designing an implementation of RSA . I recorded computation times in Java by using System.currentTimeMillis(). It returned an encryption time of 0.05 ms and decryption time of 0.55 ms, or a ratio of 1:11.   This seems like a large difference. Is it supposed to be this way?  //here my key has 256 bits  for (;;) {             long begin = System.currentTimeMillis();              for (int i = 0; i &lt; num; i++) {              decrypt();             }              long end = System.currentTimeMillis();              long time = end - begin;              if (time &gt;= 10000) {                 System.out.printf("Average Encryption takes: %.2f ms\n",                         (double) time / num);                 break;             }              num *= 2;         }  p = BigInteger.probablePrime(128, random); q = BigInteger.probablePrime(128, random); N=(p.subtract(one)).multiply(q.subtract(one)); e=BigInteger.probablePrime(32, random); d=e.modInverse(N); private void encrypt() {  C= M.modPow(e,N);  }  private void decrypt() {     RM = C.modPow(d, N);     }
57401
I have been working on a Java project for a class for a while now. It is an implementation of a linked list (here called AddressList, containing simple nodes called ListNode). The catch is that everything would have to be done with recursive algorithms. I was able to do everything fine sans one method: public AddressList reverse()      ListNode:    public class ListNode{   public String data;   public ListNode next; }   Right now my reverse function just calls a helper function that takes an argument to allow recursion.  public AddressList reverse(){   return new AddressList(this.reverse(this.head)); }   With my helper function having the signature of private ListNode reverse(ListNode current).  At the moment, I have it working iteratively using a stack, but this is not what the specification requires. I had found an algorithm in C that recursively reversed and converted it to Java code by hand, and it worked, but I had no understanding of it.  Edit: Nevermind, I figured it out in the meantime.  private AddressList reverse(ListNode current, AddressList reversedList){   if(current == null)        return reversedList;   reversedList.addToFront(current.getData());   return this.reverse(current.getNext(), reversedList); }   While I'm here, does anyone see any problems with this route?
32793
I was looking for a tree or graph data structure in C# but I guess there isn't one provided.  explains a bit about why.  Is there a convenient library which is commonly used to provide this functionality?  Perhaps through a strategy pattern to solve the issues presented in the article.  I feel a bit silly implementing my own tree, just as I would implementing my own ArrayList.     I just want a generic tree which can be unbalanced.  Think of a directory tree.  C5 looks nifty, but their tree structures seem to be implemented as balanced red-black trees better suited to search than representing a hierarchy of nodes.
19386
I place leaves on my trees with emitter particle systems. Then, to make a forest, I place those trees with another emitter (or hair) particle system.   Problem is particles of particles don't work, I only get the trunks without leaves in my forest.  Following this question : , which solution takes ages (I use about 500 000 leaves per tree), I tried to write a python script, but comes to the same problem. Searching on google, I found Brecht saying it comes from the naming of object (leave.001, leave.002 .... leave.500000) which after 1000 iterations becomes pretty slow and after 10000 extremely slow (so naming 2000 object is much slower than twice the time of naming 1000 of them). Anyway, that step is useless, blender needs one big mesh with all leaves to allow instancing it, not 500000 objects with one linked mesh.  So question is how can I convert all the particles to one unique object in one step (or at least avoid it to take 28 hours every time) ?