Efficient XML Parsing For Count Using Java Hashmap?
Aug 20, 2014
I am kind of new to Java. I have a query.. look at it. Have an xml like
<ProductList>
<Product Quality='Good' color='Blue'>
<Details ItemID='1001'/>
</Product>
...
..
</ProductList>
The <Product> tags can run into hundreds or thousands. Quality can have values like Good, Bad, Damaged. Color can also have various values (Blue, Red ..)
ItemID can repeat or can be different. So I want group by ItemID->Color->Good count or BadCount and TotalCount as below.
I want to get a sum like
<ProductList>
<ProductType ItemID="1001">
<Product_Detail CountGood="1" CountBad="2" CountTotal="3" Type="Blue"/>
</ProductType>
...
...
</ProductList>
I think using Hashmaps (Hashmap1 for ItemID, Hashmap2 for color, Hashmap3 for quality) may do the work. But I have to parse the xml number of ItemID's multiply-by number of colors multiply by various colors times for this.
Any better algorithm is there in performance perspective using Java.
View Replies
ADVERTISEMENT
Jan 30, 2014
my project flow is html,css,js<--->ajax<-->jsp<--->jdbc(.java)<--->mysql. In that jdbc i am returning the records from the database and fill into the resultset. From the resultset i put all records in arraylist and passed to jsp then i am displaying data in the screen.Whether i can use arraylist, hashmap or treetable?
View Replies
View Related
Jul 15, 2014
I have a query regarding parsing a directory, its subdirectories and files of directories. i am using File Object to load absolutepath of main directory and checking file is a directory or file but not geeting exact solution what i want. Suppose directory structure is D:TestPC
PC is a directory and have 2 files test.txt test1.txt and one directory
PC1 directory contains 2 directories PC2 ,PC3 and each PC2 and PC3 have some files.
Now my query is : i want to store each directory in HashMap and its files corresponding to its directory. E.g.:
D:TestPC ---> D:TestPC est1.txt , D:TestPC est2.txt
D:TestPCPC1---> Null
D:TestPCPC1PC2 --->D:TestPCPC1PC2 est1.txt, D:TestPCPC1PC2 est2.txt
like this, where first directory path as key and files are its values.
View Replies
View Related
Nov 29, 2014
I have a textfile that contient the name of items separated by blank space
Header 1Header 2Header 3Header 4Header 5javaoraclesqlphpjavasql phpphporaclejava
First i want to read the text file and I want to count the number of occurrence of each item and after that i want store the result in hashmap structure...
Example :
Header 1Header 2java3oracle2sql2PHP3
How can I do that ?
View Replies
View Related
Dec 10, 2014
I have to write Scanner and Parser for the C-Code based on Java and obtain Abstract syntax tree(AST) . I am allowed to use tools like ANTLR, CUP. But i should be able to expand all macros in my code to its basic low level data type like int, boolean and whats the best approach?How to start initially?
View Replies
View Related
Dec 24, 2014
In the code below I am splitting the String relativeDN at the "," character. After splitting the String I need to parse the string from the "=" character using indexof and then rebuild the string. I was able to parse the first = sign then rebuild the string but it doesn't remove the subsequent = character. I am trying to parse the string using idexof for all the "=" characters and then rebuild it using StringBuilder.
public class StringTestProgram {
public static void main(String[] args) {
String relativeDN = "cn=abc,dn=xyz,ou=abc/def";
//Split String
String[] stringData = relativeDN.split(",");
[Code] ....
View Replies
View Related
Jun 26, 2015
I have an excel file with data listed as the following, i m trying to parse down using POI
A
B
C
D1
D2
F
G1
G2
G3
M
S1
R
T
U
L
X
Y
Z
is it possible to generate an output like the following
A
A-->B
A-->B-->C
A-->B-->C-->D1
A-->B-->C-->D2
A-->B-->F
A-->B-->F-->G1
A-->B-->F-->G2
A-->B-->F-->G3
A-->B-->M
A-->B-->M-->S1
A-->R
A-->R-->T
A-->U
L
L-->X
L-->X-->Y
L-->X-->Y-->Z
I have been trying from quite some time but havent figured out the logic ...
View Replies
View Related
Jun 30, 2014
I have an array with the following characters {'E', 'L','E','P','H','A','N','T','P','O'}
now, I need an array that will store the first array such that only the occurence occurs e.g {'E','L','P','H','A','N','T','O'} Notice that the characters 'E' and 'P' occur twice and as a result were not repeated the second time in the new array.
How would one go about this using the counting elements technique?
I tried this but not sure how to use the counting elements technique.
char [] arr = new char{'E', 'L','E','P','H','A','N','T','P','O'};
char[] bucket = new char[(arr[0] * arr.length)];
for (int i = 0; i < len; i++)
bucket[arr[i]]++;
View Replies
View Related
Sep 9, 2014
How can I convert JSON string to HashMap. My JSON string is like
{
"AvailableDeliveries": {
"500": {
"code": "INOFFICE",
"desc": "In Office",
"id": 500,
[code]....
I looked on other examples which have collection of object but I have this extra top level object "AvailableDeliveries" not sure how to handle that level.
View Replies
View Related
Apr 3, 2014
I have a table which contains list of regular expression and its corresponding value.I have to fetch those value and put it HASHMAP where regex as key.I have to compare the each key with the given string(input) and If matches I have to get the corresponding Value for the regex.
View Replies
View Related
Feb 11, 2014
How to implement HashMap put and get methods without using Java Collection framework?
View Replies
View Related
Mar 6, 2014
How to do a count up timer in java? like "0:00:00" hh:mm:ss
View Replies
View Related
Jan 31, 2015
if one address point on another address. so set and get methods will be less efficient then an array, but add or remove will be more efficient by a linked list ? a linked list also inherit from queue so if i add an elemnt via "addFirst" function . where its adding the element ? to the right most or left most ?
if i have for example :
here [ ] --> [ ] --> [ ] --> [ ] -->[ ] or here
linked list its FIFO so the head will be the right most ?
Edit : its confused me a little bit but i understood now .so it will be at the left most. its actually ordered . not like the stack which is LIFO.
View Replies
View Related
Jan 23, 2014
My GCD testing:
Java Code:
public static long gcd(long a, long b) {
if(b == 0) {
return a;
} else {
return gcd(b, a % b);
}
} mh_sh_highlight_all('java');
Is there a more efficient way? Also, what can I do to speed this forloop up?
Java Code:
for(long i = 1; i < 750000; i++) { dothis; } mh_sh_highlight_all('java');
View Replies
View Related
May 27, 2015
I've a question on rounding doubles on 0.05 As far as i know there is no class method that is able to do this. To achieve this rounding i have the following code:
Example:
164.67 -> 164.70
173.33 -> 173.35
0.02 -> 0.05
double calculatedQuantity = 0.0;
// Formula to calculate the average working hours in a month
int totalWeeksInYear = 52;
int totalMonthsInYear = 12;
[Code].....
View Replies
View Related
Apr 12, 2015
I have taken array int[] a = {33,33,5,5,9,8,9,9};
In this array so many values are duplicates means 33 comes twice & 5 also comes twice & 9 comes three times. But I want to count the first value which is duplicate means 33 is first value which comes twice so answer would be 2.
I try:
public class FindFirstDuplicate {
public static void main(String[] args) {
int c=0;
int[] a = {33,33,5,5,9,8,9,9};
outerloop:
for(int i = 0; i < a.length; i++) {
[code]....
Output:
33
Count: 1
View Replies
View Related
May 7, 2014
I have to write a program that takes an array of grades and calculate the average and then count the number of grades that are above average and also count the number of grades that are below average. This is what I have so far, it calculate the average and tells me how many are above average... where and how do I get to count how many are below average
public class arrays{
public static void main(String[] args) {
final int grades = 5;
double[] numbers = new double[grades];
double sum = 0;
[Code] .....
View Replies
View Related
Oct 22, 2014
I'm looking for a way to gather data from a site page. all data is shown in the same page... I am trying to get the content and parse it is a bit crazy as data seems to be not organized. Itried to get it as a document but still looks crazy.
As all data is shown very clearly in the page (I would like every row to be an object) I'm sure there is some way to collect this data easily. (the data is from this page: [URL] ....)
I'll attach a snapshot and the content I got from the website.
in-play.jpgall_in-play_page.txtin-play.jpgall_in-play_page.txt
View Replies
View Related
Oct 18, 2014
This isn't solely related to java.awt.Color, it's more of a question on how to store methods or redirections to use methods on any value passed in. To explain my question I'll describe a scenario:
ClassA is an instanstiatable class
ClassA has an instance of ClassB called cB
ClassA has methods of affecting cB
ClassD is also an instanstiatable class
ClassD has an Array[x][y] of instances of ClassA
I want to create a ClassE which I would initiate it with references to ClassA's methods or their actual methods and then I can use ClassE to easily transform ClassD's instances of ClassA by the same methods.
What I'm actually doing:
I made a class called GameColor, it has methods like changeHue, setRed, setHue, changeBrightness, setSaturation etc, these methods affect an instance of java.awt.Color in the GameColor class instances, so like they can change the hue or set it with changeHue or setHue etc...
Now I want to do something like perform a single method on a whole BufferedImage, on each of it's pixels RGB. So, I'm thinking of creating a GameColorEffects class which I store references or actual methods of GameColor like changeHue, and then I use GameColorEffects somehow to change a whole BufferedImage more efficiently, what's the most efficient way I can store methods or their reference of GameColor and then later apply them on each pixel of a BufferedImage using GameColorEffects. So all I do is initiate GameColorEffects with methods or reference from GameColor, and then I can apply it to easily transform each pixel.
View Replies
View Related
Oct 3, 2014
I have to count the comparisons in the quick sort. I have done it by using a global variable. But I am stuck in doing it recursively.
This is my code.
import static java.time.Clock.system;
import java.util.Arrays;
public class test {
/**
* The swap method swaps the contents of two elements in an int array.
*
* @param The array containing the two elements.
* @param a The subscript of the first element.
* @param b The subscript of the second element.
*
*/
[Code] .....
View Replies
View Related
Jan 12, 2014
for example if the given string is: The world is running java technology?
Ans:
T is =2
h is=2
e is=2
w is=1
n= 4
like wise i need out put of the program?
View Replies
View Related
Feb 13, 2015
with arrays its binary search which finds a value in O(Logn) time but what about linked lists ? the most effiecient algorithm will be O(n) ? and i know that binary search cannot be implement on a linked list , therefore , the only way to search a linked list is a linear search ?
View Replies
View Related
Oct 28, 2014
I am getting :
Error ? java.lang.NullPointerException
I've placed the .mp3 file in the same directory as my project (where I've bin and src folders).
View Replies
View Related
Feb 26, 2015
I've been staring at my code for the past few days and I just can't get it to work out. I'm trying to parse a DOM object with the following XML loaded:
<?xml version='1.0' encoding='UTF-8' ?>
<form>
<record event="boot" date="2013-11-01">
<text>system boot</text>
</record>
<record event="login" host="localhost" date="2013-11-01">
[code].....
I'm trying to get all of the attributes that I care about out of the <record> tags (date, event, etc ...) and stick the data in a wrapper class (DocumentData). If you run this, you'll see that it is close to working, but I'm having trouble getting the attributes in the <subject> and <return> tags (I need to get the errval and uid attributes).
View Replies
View Related
Jul 1, 2014
I'm simulating temp/humidity values and want to separate the string value reported and parse each part (left and right) for their respective values. However, I'm having trouble figuring out how to parse the right hand side of this string value, I can get the left using split (shown below), but I think split removes the right hand side of the string value.
the value reads "Temp=22.9*C Humidity=50.9%"
Java Code: private Double parseTemperatureFromString(String consoleOutput) {
String[] tempHumidParts=consoleOutput.split(" ");
String[] tempPart=tempHumidParts[0].split("=");
String theTemp=tempPart[1];
theTemp=theTemp.replace("*C","");
return Double.parseDouble(theTemp);
[code]....
View Replies
View Related
Jul 1, 2014
I have use below code to parse the xml using xslt i am getting below error.
package com;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.*;
import java.io.IOException;
[Code] ....
I am getting below error ....
ERROR: 'No more DTM IDs are available'
javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.dtm.DTMException: No more DTM IDs are available
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:716)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
at com.TestXSLT.main(TestXSLT.java:34)
Caused by: com.sun.org.apache.xml.internal.dtm.DTMException: No more DTM IDs are available
[Code] ......
View Replies
View Related