# Ale Garcc

Greenhorn
since Aug 04, 2008
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
0
0
Total given
0
Given in last 30 days
0
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

## Recent posts by Ale Garcc

Campbell Ritchie wrote:Afraid that doesn't explain what you are doing, only how you intend to do it., When you work out the “how” before the “what”, you are skating on thin ice, with potentially brittle and error‑prone solutions. What's more, your solution destroys the evidence of the previous counts, so you will find it difficult to identify errors.
It does look like the counting words example I told you about last week.
You could make much more reliable and robust code if you made those objects immutable, and got rid of the setXXX() methods. I suggest you might want a combine() method which creates a new object combining the two counts, but insisting on the same name in both its arguments.

Not explaining what i am doing???
Yes...you are right...merry Christmas..
15 hours ago

Campbell Ritchie wrote:

Ale Garcc wrote:. . .
i will end up wih a map of Name->Total.
And i want the object itself contains the total inside the quantity field.
. . .

Please explain your design more; I can't see how you are going to have accurate quantities inside the element objects.

Campbell Ritchie wrote:

Ale Garcc wrote:. . .
i will end up wih a map of Name->Total.
And i want the object itself contains the total inside the quantity field.
. . .

Please explain your design more; I can't see how you are going to have accurate quantities inside the element objects.

Hi!
Yes,i can explain a little more:

1-Iterate the map
2-For each element in the map,iterate the list of Elements
3-Collect those elements inside a map,where the name is the Key,and the Element the value
4-And when values are the same,i add up the quantity field from oldElement with the quantity field of newElement

Suppose ,we are iterating the second element inside the resultMap map.
After getting that object,we iterate the Elements list of that object.
While iterating that list of "Elements" ,we create a Map,with the "name" as key ,and the Element itself as the value.
When elements are the same,the following line will be executed :

There ,i am adding up the quantities,when the elements are the same.
The resulting map would be :
Map of 2 elements:
-The First one with key="Name 2",value =Element (with quantity value 12)
-The Second one with key="Name 3",value =Element (with quantity value 6)

Then,i convert this into a List,having this new List,i set it into the Wrapper object

Let me know if it s more clear now ,thanks !
1 day ago

Campbell Ritchie wrote:Have removed most of the quote; nobody wants to see what I wrote twice Moving you to a Java® forum.

That's a pleasure

. . . The example i wrote it s something simple i did for this forum.

Beware of simplifying questions, though you may have to do that to keep proprietary content confidential. If you ask too simple a question, you may get too simple a reply which doesn't provide all you need.

. . . where should i add the addQuantitiesIfSameName() . . .

Not sure. Probably nowhere at all.

. . . iterate the set . . . i dont imagine where do that . . .

Consider filling the List, and as you go, summate the results. Did you see the word counting example in the Java™ Tutorials I told you about yesterday? It counts words, so it adds 1 to each “V” as it goes, but adding counts is only slightly harder. It will go something like this:-You will need some version of equals() in the element objects that will implement the definition of equality you need (and hashCode()).

You can create a Counter object that totals the counts, and use a Map<String, Counter> instead. There are probably other ways you can add counts with Streams and the collect method and Collectors.groupingBy. Or you might be able to use the putIfAbsent method of the Map.

Thanks again!
The problem with that approach ,it s that i will end up wih a map of Name->Total.
And i want the object itself contains the total inside the quantity field.

Basically,what i am doing it s the following:
1-Iterate the map
2-For each element in the map,iterate the list of Elements
3-Collect those elements inside a map,where the name is the Key,and the Element the value
4-And when values are the same,i add up the quantity field from oldElement with the quantity field of newElement
5-Convert the map to a List of Elements
6-Set the new modified list of Elements to the Wrapper object.
Let me know what you think ,thanks !
4 days ago

Campbell Ritchie wrote:I don't know any Angular, but I can see problems which are plain simple Java®/object‑oriented programming, which I do know. . . . .

This is Java code,i dont know why it s inside Angular Forum!
The context about my question,it s data that it s coming from a Http Request and i need to iterate the answer to make some grouping,changes,adding etc.
The example i wrote it s something simple i did for this forum.
And about your second option, "It is better to iterate the set and collect quantities",i dont imagine where do that,because once the list it s complete,i will need to iterate,collect and remove Duplicates objects inside Set.
I really appreciate the time you took to answer my question,because i really need to solve this problem.
Thanks !
5 days ago
Hi all!

I have an entity that has 2 fields: Wrapper Entity :

Then,the Element Class:

In the main Class,i have a List of "Wrappers":

Now,i transform this list into a Map,grouping by Wrapper ID

After this ,i have a map with 2 elements:

-The first One with KEY=1 -> List with 2 elements

-The second One with KEY=2 -> List with 4 elements.

This is what i need now:

As you can see,the Element Class,has a field "quantity",and i need to add up this field when the Elements belong to the same Wrapper ID and the Element name it s the same.
For example the above map,should result in:

-The first One with KEY=1 -> List with 1 element ,the quantity Field = 3 (The first Element has a 1 in quantity value and the second has a 2)

-The second One with KEY=2 -> List with 2 element,the first one with name "Name 2",quantity 12 ,the second one with name "Name 3",quantity 6

What i did to achieve this is the following:

-The List ,now it s a Set

-Overrided Equals method ,when Objects are the same,i add up the quantity field of Old value and New Value ,and return true. Here the changes i made:

The following into the Element Class:

Is this approach OK? Or it s a better one?
6 days ago
Hi all!

I have an entity that has 2 fields: Wrapper Entity :

Then,the Element Class:

In the main Class,i have a List of "Wrappers":

Now,i transform this list into a Map,grouping by Wrapper ID

After this ,i have a map with 2 elements:

-The first One with KEY=1 -> List with 2 elements

-The second One with KEY=2 -> List with 4 elements.

This is what i need now:

As you can see,the Element Class,has a field "quantity",and i need to add up this field when the Elements belong to the same Wrapper ID and the Element name it s the same.
For example the above map,should result in:

-The first One with KEY=1 -> List with 1 element ,the quantity Field = 3 (The first Element has a 1 in quantity value and the second has a 2)

-The second One with KEY=2 -> List with 2 element,the first one with name "Name 2",quantity 12 ,the second one with name "Name 3",quantity 6

What i did to achieve this is the following:

-The List ,now it s a Set

-Overrided Equals method ,when Objects are the same,i add up the quantity field of Old value and New Value ,and return true. Here the changes i made:

The following into the Element Class:

Is this approach OK? Or it s a better one?
6 days ago
I am deloping an ecommerce using Angular 7 and Spring boot and i need to add a special feauture. The idea is ,when you are seeing the products you have in the left some filters you could apply to your search. But,those filters should change if the user select another category inside a dropdown. So if the user select "Clothes" ,you will see filters related to "Clothes" category. This is the same way that Amazon shows you the filters you can apply to your category. I dont know which is the best option to do this:

Option 1: In Angular ,i can create Dynamic Form,so when user changes the Category,the correct form will be shown. When user click the search button,inside Spring ,i should read each parameter and add that condition to my query. The bad thing (i Think),it s in this way i can not work with the FilterID and i should use the name of the filter i am deciding inside Angular Form inside the backend. Let me clarify that point:

For Example ,from Angular i have a harcoded Form and those fields (filters for me) have names i created ,so when user clicks search, i will query to the backend something like this "?q=used=true" ,then in the backend,i should check if that condition exist ,then my query will have something like this "and (filter.name ="used" and filter.name=true) or...more filters) In this way,when same parameter name changes from one side or other,it could lead to problems.

Option 2 When user change the dropdown i could make a call to the backend and get the filters related to that category,they will be return in same way i know if for each of them i should draw a textbox,a dropdown,etc. So,with this returned data ,i could create a dynamic form. Now,the question is,when the user click search ,how the data should be passed to the backend? "q?=idFilter=true&idFilter=='red;" ??

Option 3 ?Option 4? Here is another example from another platform:

https://www.despegar.com.ar/autos/c-bue/alquiler-de-autos-en-buenos+aires?filter_number_of_passengers=4,7&filter_promotion=ANY&sorting=RECOMMENDED#/results (In that platform you can buy tickets for Travel,Rent Cars,and a lot of things)

This is maybe the same i want to do,in the link i added above,if you visit it,you will see in the left ,the filters you have in the URL ,applied. But as you can see,if you add filters,the will be added to the URL with custom names.

So ,are they implementing the Option number 1? They create some custom filters names ,for example "filter_number_of_passengers",will be sent when someone add that filter,and then the backend should extract that exact filter ,and then perform the sql query by name?What do you think?

I would really appreciate a help on how to solve this situation.
2 weeks ago
I am building a Sprint boot Application ,where i make a Request and then i get a Response. Before i make the request,i need to transform my data.But,the Destination class to transform could be different for the same Source class to transform. Example :

public Request getTransformedRequest(Request, String typeTransformation) {
Request transformedRequest= mapper.map(request,Request.class);
return transformedRequest;
}
If i am not using Converters,and i am using just normal Dozer mapping,i can have the following in my mapping.xml;

And then in my code,for the same Source class ,i can switch using the mapping Id;

ClassB mapper.map(request,Request.class,"Type1"); //Here ClassB extends Request
ClassC mapper.map(request,Request.class,"Type2"); //Here ClassC extends Request
My problem,it s i cant do the same with converters.I want to have different converters for the same source class:

So ,in my scenario,i would like to select (like in the mapping id example) ,the converter i wish. I really appreciate same help.Thanks in advance.
2 months ago

Les Morgan wrote:If your tables are sufficiently small and you don't have much change in the local table, then yes, it is possible.  I've not followed that very closely as the tables I deal with are hundreds of millions of records to billions of records, with change rates that are way too frequent to make a local copy practical.

2 months ago
Hi community!
I hope i can explain this in a proper way.

I have a Sql Server Database with serveral tables. In my Spring - Boot application,i need to query to those tables,there are a couple of tables that wont change ever.

For example,lets suppose for simplicity it s a Book table,and i query the books in different ways,by price,by id,by ISBN ,what ever.

So first thing i thought ,it s to use Redis,but that s not good for me.Why?

Well,Redis stores the data in a key-value pair,so if i catch the entire table,then in my code when i want to do same complex query to that data (Give me the book with this ISBN),that s not possible,i will need to create different Catched methods for each operations,so the next time i ask for same data ,if exist in the cache,it wont go to query to the Database.

Thats why i though about H2 memory database,i could fill my "Book" in memory table and make all kind of operation on it,because it works like a normal database and i could query anything.

Now,comes my questiion:

I know i can load initial data into H2 pointing to some script,that s ok. But i would like to populate my "Book" in memory database,with the same data that i already have in my SQL Server Book table.

What do you think? Is that possible?Any ideas?

3 months ago
Hi all!
I am styudy for SCWCD ,in first instance i am reading "Head first Servlets and Jsp",the book makes reference to J2EE 1.5
What i say is,if i go to give an exam,it will be related to the 1.6 versions or 1.5?
Is anyway that book ok?

7 years ago
Hi!
I am using Struts 1.3.8 and when i want to try some of the examples or when i want to develop something
i always have the same error in the line with "html:form."
This is a very simple example:

Inside Web-inf,i have a lib folder with the following libs:
commons-loggining,commons-validator,jstl-1.0.6,oro-2.0.8,standar-1.06,struts-core,struts-el,struts-extras,
struts-taglib,struts-tiles.

Struts-config.xml with this Information:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_0.dtd">
<struts-config>

<!-- === Form Bean Definitions -->

<form-beans>
<form-bean name="RegistroForm" type="app.RegistroForm"/>
</form-beans>

<!-- ===Action Mapping Definitions -->

<action-mappings>

<action path="/registro" type="app.RegistroAction"name="RegistroForm"
input="/registro.jsp"/>
<forward name="exito" path="/pages/succes.html"/>
<forward name="fracaso" path="/pages/error.html"/>
<action>
</action-mappings>

</struts-config>

Inside Web-inf-src i have a package "app" with 2 classes.

-------------------------------RegistroForm-------------------------------

In a folder call "Pages" i have a 2 .html "error.html" and "succes.html"
And of course i have the index.jsp page,i use this page to
start the application and there is where i have the error.

------------------------------------------index.jsp------------------------------------

The error is in <html:form action="/registro">

El servidor encontr� un error interno () que hizo que no pudiera rellenar este requerimiento.
excepci�n
That exeption in english it is:
The server found an error,and cant fill this requirement.
org.apache.jasper.JasperException: Exception in JSP: /index.jsp:16

I am using Tomcat 5.5.26