Jump to content
  • 0

Help With A Parsing Code!


Alianza

Question

Hello guys,
I'm here with a new code I'm trying to make that I cannot get it out of my head  :rage:
So, here's my problem: I have two tables with information. Both of them have the same structure (ID, Value) but one of them has more repeated values than the other one. For example:
|----------------------|                    |----------------------|

| ID              Val   |                    | ID             Val    |

|----------------------|                    |----------------------|

| 1                 0    |                    | 1                 0    |

| 1                 0    |                    | 1                 0    |

| 2                 5    |                    | 1                 0    |

| 2                 5    |                    | 1                 0    |

| 2                 5    |                    | 2                 5    |

| 2                 5    |                    | 2                 5    |

| 3                 1    |                    | 2                 5    |

| 3                 1    |                    | 2                 5    |

-----------------------                     | 3                 1    |

                                                | 3                 1    |

                                                ------------------------

 

Here you can see two tables with the same structure but one of them has more repeated values than the other one (as I said before). What I'm trying to make, is the following: take the ID from the first table (ID = 1) and copy the value from the second table (Val = 0), but just copy it as many times as the ID in the first table exists. For example: if the ID 1 in the first table exists 2 times, copy the Val from the second table 2 times, skip the other two, and go to the next ID by doing the same.

I've tried to do it. The class I've made loads both tables and fills two ArrayLists with its information by putting them into an IntIntHolder class (thks aCis) in order to compare them later. So far, this is the code I've written, but it throws NoSuchElementException. And running it without the (see below), it prints some data but not all (if total data is 8, it prints 4).

while (elementA.getId() != elementB.getId())

Here's my code:

public void compareAndPrint()
{
	Iterator<IntIntHolder> iterA = listA.iterator();
	Iterator<IntIntHolder> iterB = listB.iterator();
	while (listA.hasNext())
	{
		IntIntHolder elementA = iterA.next();
		IntIntHolder elementB = iterB.next();
		if (elementA.getId() == elementB.getId())
			System.out.println(elementB.getValue());
		else
		{
                        while (elementA.getId() != elementB.getId())
			        iterB.next();
		}
	}
}

So ye... that's all. I'm trying to parse some data from the system so that's why I'm trying to do this.

Thanks for reading, and I'm looking forward to your answers!

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Okay mate. I will try to do so and I'll keep you updated.

Thank you!

 

EDIT: hehe, I've solved it following your steps.

Here's the code:

private final static Map<Integer, Integer> MAP = new LinkedHashMap<>();

public void compareAndGenerate()
{
	int i = 1;
	for (IntIntHolder aElement : listA)
	{
		if (!MAP.containsKey(aElement.getId()))
			i = 1;
		
		MAP.put(aElement.getId(), i++);
	}
	
	for (Entry<Integer, Integer> map : MAP.entrySet())
	{
		int ii = map.getValue();
		for (IntIntHolder bElement : listB)
		{
			if (bElement.getId() == map.getKey())
			{
				while (ii > 0)
				{
					System.out.println(bElement.getValue());
					ii--;
				}
			}
		}
	}
}

Thank you, very much.

You disserve a cookie. Here ya' go

 

Cookie-Download-PNG.png

Edited by Alianza
Link to comment
Share on other sites

  • 0

What happens if a same id got different values ?

 

What is supposed to be the third table, since I didn't understand anything (I don't see the point between the 2 tables at all, until you want to increment it but it's probably far better to simply use a Map<Integer, Integer> and increment it directly the second parameter) :D.

Link to comment
Share on other sites

  • 0

Hello Tryskell, and thanks for replying!

Well, I'm trying to parse some system data as I said before, so I need to maintain those values as they appear there. I need to copy something from a higher chronicle to Interlude, which has less data.

For example:

post-208767-0-08541200-1499956043_thumb.png

 

Those are both tables. I'm trying to copy the values from the B table to the A table. Sometimes, the B table has more repeated values which increment its size compared to A table. What I'm trying to do, its to past through those repeated values and keep copying the other values that are not repeated and match with the A table (original Interlude data).

Is it clearer now?

 

EDIT: I forgot to say that I need to maintain the size. I cannot use a Map<Integer, Integer> because that will affect its size. I just need to copy values from table B to the IDs of  table A.

Edited by Alianza
Link to comment
Share on other sites

  • 0

No clue if there is an easier solution, I would count occurences of each id type on table A (with a stream() you can use .count() and can generate a temporary map holding id/occurences count), then on table B you for loop the whole thing, verify the current id and current occurence number. If occurence counter is superior to occurence count of the temp map, you "continue;". Once you changed of id you reset the occurence counter to 0.

Link to comment
Share on other sites

  • 0

I cant see the logic there, sorry (I'm half stupid).

My logic is: when the ID of the A table and the ID of the B table are different, I just use iterB.next() to find the ID that matches the ID of the table A again and continue with the code. Am I wrong?

For some reason I cant do it (maybe because I'm half stupid).

Thanks again, Tryskell.

Link to comment
Share on other sites

  • 0

If id/values are correct on table 2, you only have to filter the number of IntIntHolder from this table to fit the count of table 1.

 

So you count occurences of table 1 : id 1 got 2 matches, id 2 got 4 matches, id 3 got 2 matches. You keep result in a temporary map.

 

Then you for loop the table 2 ; based on temporary map, you find id 1. Based on your temp map, it should have 2 occurences, but you find more. You add the 2 first, and don't bother about leftover (continue). Then you got on another id, etc etc.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Posts

    • Hello everyone,   We're shifting our focus away from implementing as much as possible from the Essence gameplay. Instead, the server will now be Interlude, but using the Essence client.   This should be good news for everyone.   The Beta phase will most likely take place in November, with the grand opening to follow shortly after.   Cheers!
    • We remind you that the opening will take place today, on September 28 at: 19:00 (UTC+3) - server time Check current server time(UTC +3) On 17:00 (UTC +3) We allow you login to create character! Dear friends, this topic important! So please take time to read it. First we want to thank all players who took part in the Open Beta testing, was good activity and nice Olympiad Event yesterday, we all get a lot of fun  Thanks to all who conducted tests with us and prepared this game world! You are amazing!  On 17:00 (UTC +3) We allow you to login for create character! To restrict your name and transfer ToDs/Season Pack to your character. Make it before start! On start, we can have problems with WEB! Everything you need to start on the server: It is IMPORTANT to prepare everything for starting the game RIGHT NOW, do not postpone for later, during the opening there may be problems with the web part of the project, and you simply can not register. - Registration and files Download archive unzip it, run launcher, choose SEASON x25 server and press FULL CHECK What you need to know at the start: Registration for 7 seals from Monday, September 30, full cycle 1 week. First Mammons on Friday October 4 All Epic Raid Bosses dead on start. First epic QA will appear on Monday, next day Core + Zaken + QA and so on by schedule All other RBs alive on server start (including Sub and Nobl RB) - Full RoadMap   About possible attacks on server start. We have prepared as good as we can. We will control the start of the server together with you. Want to ask you, in the case of a problem, don't panic, panic is the worst possible thing that could be, even worse than any attack. We have enough specialists to solve any problems, all that will need from you is patience and trust. Wish you all a smooth start and months of enjoyable play in new Season Interlude x25! Have a fun!
    • 🚨🇦🇷🇧🇷🇪🇸🇸🇰🇺🇳🇨🇱🚨 Devianne - Lineage 2 Interlude  Client - Classic. 🔷Rates 🔸Experience (EXP) - 10x 🔸Skill Points (SP) - 10x 🔸Adena - 6x 🔸Drop Items - 3x 🔸Spoil - 3x 🔸Quest Experience (EXP) - 1x 🔸Quest Skill Points (SP) - 1x 🔸Quest Adena - 1x 🔸Quest Items Drop - 1x 🔸Seal stone Drop - 1x 🔸Epic raid - 1x 🔸Raid Drop - 2.0x 🔸Manor - 5x 🔷Dynamic Rates XP/SP 🔸Lv. 1-52 EXP/SP X10 (x7 without VIP or vote reward) 🔸Lv. 52-61 EXP/SP X7(x5 without VIP or vote reward) 🔸Lv. 61-76 EXP-SP X5 (x3 without VIP or vote reward) 🔸Lv. 76-78 EXP/SP X3 (x2 without VIP or vote reward) 🔸Lv. 78-80 EXP/SP X2 (x1 without VIP or vote reward) ⚠️Extra Settings⚠️ 🔸Server time, site - GMT -3 🔸Buffs, Dances, and Songs duration - 1 hour 🔸Max Buffs Slots - 22 + 4 divine 🔸Maximum Slots Dances and Songs - 12 🔸GmShop Grade - C 🔸Global teleport 🔸Grade B-A-S - Craft 🔸Mana potion recharge 🔸1000 (9 seconds delay) 🔸Raid HP - x1.4 🔸Raid epic HP - x1 🔸Blacksmith Mammon - 24/7 🔸Champions System - Yes chance respawn 0.5% 🔸Offline mode Shop - Yes 🔸Auto Learn Skills - Yes 🔸Auto Learn Loot - Yes 🔸Auto Learn Raid & Grand 🔸Boss Loot - No 🔸Buffer offline - Yes 🔸Wedding System - Yes 🔸Max level diff distribution drop in party - 14 🔸Limit the number of active gaming clients on one PC - 2 🔸Limit the number of active gaming clients on one PC for Premium - 3 🔸The clan leader will be replaced after server restart ⚠️Class and Subclass Change⚠️ 🔸1st profession Quest - No 🔸2nd profession Quest - No 🔸3rd profession Quest - Yes 🔸Sub Class Quest- Yes 🔸Sub Class Raid - 8 hours +-30m random 🔸Nobility and Olympiads Nobility Quest - Yes 🔸Olympiads (duration) - 14 days 🔸Max enchant - +6 🔸Respawn Barakiel 6 hours - +-15 min random 🔸Olympiad schedule - 13:00 to 00:00 🔸Minimum players to start olympiad - 11 Clans and Sieges Penalty duration - 8 hours 🔸Sieges every - 15 days Max Ally - 2 🔸Max Members - 36 🔸Slots for academies in clan - 40 ⚠️Enchants Rate⚠️ 🔸Blessed Scroll chance 60% 1-10 11-16 40% 🔸Crystal Scroll chance 65% 1-10 11-16 40% 🔸Normal Scroll chance - 55% 🔸Safe Enchant - +4 ⚠️Premium Info⚠️ 🔅+20% xp sp drop spoil adena 🔅+5% additional enchant rate (premium 30 days)   Free autofarm ⚠️Starter Pack⚠️ 🔅Free Premium - 24 hours 🔅Free Autofarm - 24 hours ❇️Raid boss Info❇️ 🔸Anakim/Lilith respawn 18 hours +1:30min random 🔸Tyrannosaurus - respawn 8 min drop Tl 76 🔸Queen Ant (LVL 80) - Respawn Monday and Saturday 22:00 🔸CORE (LVL 80) - Respawn Tuesday-Friday 20:00 🔸ORFEN (LVL 80) - Respawn Tuesday-Friday 21:00 🔸BAIUM (LVL 80) - Respawn Saturday 21:00 🔸ZAKEN (LVL 80) - Respawn Wednesday-Thursday 22:00 🔸FRINTEZZA (LVL 85) - Sunday 19:45 ⚔️Quest Details⚔️ QUEST WEAPON RECIPES: - Relics of the Old Empire x1: - Gather the Flames x1 x1: QUEST ARMOR RECIPES: - Alliance with Varka Silenos x1 - Alliance with Ketra Orcs x1 - War with Ketra x1 - War with Varka x1 - Gather the Exploration of the Giants’ Cave Part 1 x3 - Exploration of the Giants’ Cave Part 2 x1 - Whispers of Dream part 2 x2 - Legacy of Insolence x1 QUEST RECIPES JEWERLY - The Finest Food x1 QUEST RESOURCES - The Zero Hour x2 - Golden Ram Mercenary x2 - An Ice Merchant dream x2 QUEST FOR FABRIC: - Whispers of Dream part 1 x1 BEAST FARM : - Delicious Top Choice Meat x2 👁️OTHER QUEST👁️ 👁️- Yoke of the Past x2 👁️- In Search of Fragments of Dimension x2 👁️- The finest Ingredients x3 👁️- Supplier of reagents x3 - 👁️3rd class Halisha Marks drop x3 - 👁️Into the flames x3 - 👁️Audience with the land dragon x3 - 👁️An Arrogant Search x3 - 👁️Last Imperial Prince x3 🚨Soul Crystal Details🚨 🔸- Level up crystals to 11, 12, 13 🔸- All epics can level up crystals for the whole party (Queen Ant, Core, Orfen, Zaken, Baium, Antharas, Valakas, Frintezza). - 🔸Bosses in PVP zone: Master Anays, High Priest Van Halter. 👁️🔸- Anakim/Lilith, Uruka. - You can level up crystals in Rift, but only 1 party can challenge Anakazel (10%)PARTY_RANDOM at the same time (if one party is in the boss, you need wait them to go out). 👁️🔸- You can level up crystals in Primeval Island by killing tyrannosaurus with 10% chance PARTY_ALL for the person who cast the crystal and makes last hit. ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️ WEB: https://devianne-l2.com/ DISCORD: https://discord.gg/Q3HAMzasUk 🔥🔥SERVER TEST OPEN !!🔥🔥🔥
    • I am here for the plank jumps and the cookies any news about that?
  • Topics

×
×
  • Create New...