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 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.
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?
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.:
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...
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?
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(",");
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]]++;
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.
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.
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.
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:
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++) {
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;
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.
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.
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. * */
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 ?
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:
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).
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.
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