天道酬勤,学无止境

java

Tools for generating a control flow graph from source code [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago. Improve this question I need a tool to generate a control flow graph from java source code. Are there such tools available? Is there a possibility to also generate source code if I have a control flow graph?

2022-01-19 02:42:37    分类:问答    java   control-flow

Object Pool Pattern in Java

So I've implemented my own Object Pool Pattern and it works just fine and as expected. Returning my "Teacher" objects from a list and creating them when there aren't any. My question: The object being returned "Teacher" then needs to be casted into one of its sub classes which is specialised e.g. "Biology-Teacher". What is the best way to get this kind of functionality? Edit: Sorry, I didn't think code was needed but here goes. Below is the casting I was talking about. This throws a run-time exception which is my main problem. final Bio-Teacher = (Bio-Teacher) ObjectPool.getTeacher(); This is

2022-01-19 02:41:48    分类:问答    java   algorithm   design-patterns

java DOM xml file create - Have no tabs or whitespaces in output file

I already looked through the postings on stackoverflow but it seems that nothing helps. Here is what have: // write the content into xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setAttribute("indent-number", 2); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource source = new DOMSource(xmlDoc); StreamResult result = new StreamResult(new File("C:\\testing.xml")); transformer.transform(source, result); and this is what I get as output: <?xml version="1.0"

2022-01-19 02:39:16    分类:问答    java   xml   dom   indentation

Java output from process buider overwritten when using BufferedReader

I'm trying to run an external program in Java and to read the output. The program is a Linux application in C++ that runs a data mining algorithm and prints the patterns found on standard output. I want to be able to read that output from my Java app and to show the patterns using a table. The problem is that the size of the output is quite big (as a test it produces 6.5MB in about 30 seconds). I'm using ProcessBuilder and reading the output using an InputStreamReader buffered using a BufferedReader as you can see in the following code: String[] cmd = {"./clogen_periodic", selected, support, "

2022-01-19 02:39:01    分类:问答    java

Defining and referencing a generic type bound in Play template signature

I have a number of sorted maps, keyed by a time and with a value of some type. For illustration, consider that I have 3 maps (in Java): SortedMap<OffsetDateTime, Foo> foo; SortedMap<OffsetDateTime, Boo> bar; SortedMap<OffsetDateTime, Baz> baz; I wish to write a generic Play template that accepts a map, and a renderer function, and outputs each pair. Within a template, I can define a local function with the following signature: @renderTrace[T <: Any](trace: ImmutableSortedMap[OffsetDateTime, Option[T]], renderer: (T) => Html) = { However, I would like to use this function in multiple templates

2022-01-19 02:38:53    分类:问答    java   scala   templates   generics   playframework-2.2

Hibernate Result Transformer cannot instantiate resultclass

I have a SQL query that I want to map to a class. I'm using Hibernate's createSQLQuery and then using a Result Transformer for the class I'd like to map to. But Hibernate is throwing this error: ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/mypackage].[MyPackageServlet]] Servlet.service() for servlet MyPackageServlet threw exception org.hibernate.HibernateException: Could not instantiate resultclass: com.myapp.mypackage.context.report.MonthlyReportContext$MonthlyReport at org.hibernate.transform.AliasToBeanResultTransformer.transformTuple(AliasToBeanResultTransformer

2022-01-19 02:38:40    分类:问答    java   sql   hibernate

Correct handling of background calls in jersey

I have to do some background calls to a web service within a web application. The response of the call is not really time-critical and barely interesting for me. It changes only in rare cases, where I will react to it by throwing a exception, or logging the failure or something. My conrete question now refers to the correct handling of such asynch calls in Jersey Client 2. Option 1 uses the async calls from jersey, but then starts a thread for each response. Option 2 would immediatly start a thread and use jersey from inside this thread. Generally which option would be more adviseable? Option

2022-01-19 02:37:35    分类:问答    java   multithreading   jax-rs   jersey-2.0   jersey-client

newline character in JLabel.setText()

How can I insert a newline when I am using JLabel.setText()? I tried to use Html but can seem to make it work for setText, only for the initial declaration of the jLabel the way to do it when initially declaring the jlabel is: label = new JLabel("<html>Hello World!<br>blahblahblah</html>"); my code: textString += "<html> quantityTextField.getText() + theInventory.findItem(UPCTextField.getText()).toString() + <br> </html>"; purchaseInfo.setText( textString); it displays the html tags and the method names instead of the string returned by the methods

2022-01-19 02:36:36    分类:问答    java   swing   newline   jlabel   multiline

Play framework: merge action only works in the Controller that triggered it

I have a simple Play applicaiton for test. I have 2 controllers, one is a "ListController" that displays a list of entries. Each entry has an "edit" link which goes to the "EditController". The "EditController" diplays the html form with the existing data for the entry, and the submit button posts that data towards another method in the "EditController", which saves the data to db and redisplays the newly modify data in the form. All this works ok. However once I modify an entry (which is redisplayed correctly in the edit page) when I return to the list, that entry still has the old values

2022-01-19 02:35:58    分类:问答    java   model   merge   playframework

Java / Android package name for example code

Is there a legitimate 'generic' package name I can use to open-source some demo code? I want to provide the source of a demo Android app as 'public-domain' via Google Code or wherever but I'd like the source package to be 'generic'. In other words, I do have a registered domain which I normally use for package naming but I'd rather not have that for demo code. I sometimes see example code packages using com.example.some.package (for example) but that's a registered domain name. Is there any common accepted way of naming a generic package which doesn't use someone's registered domain?

2022-01-19 02:34:40    分类:问答    java   android