Jump to content

Recommended Posts

Posted (edited)

Alright as title says. Let's say we got an xml and we want to store objects which is a range of type. 

int[], ArrayLists, Strings e.t.c

 

Known ways:

 

1. Create ex. FastMap into FastMaps such as  FastMap<Integer, FastMap<String, int[]>>

which is complicated to put and retrieve objects.

 

2. Stats sets that contain other stats sets. We can add one statset into another and make a tree

 

Is there any other way and more efficient in order load items from xmls and  store them?

 

Ps. i would prefer an experienced person with java structure to answer and give other solutions that really make it easier and more dynamic.

Thanks

Edited by AccessDenied
Posted (edited)

A StatSet is nothing more than a extended HashMap with more methods, allowing you for a String key to retrieve any type of object. It allows easy fill on loading, for the cost of overhead. A StatSet shouldn't really be used because of the overhead generated by String key. You could for example move every single variable from L2PcInstance into a single StatsSet (which will allow you to drop every single getter and setter). Will you do it, knowing that you must .get( the Map when you could simply retrieve the correct boolean/int/String by yourself with a getter if that was written normally ? I don't think so.

 

Also, a FastMap got no use at all to load static data, you both don't need the potential concurrency from .shared(true), nor the ordered system. You just create overhead for nothing using a FastMap.

 

The proper way is to create you own class defining the object similar to... Everything else :P. For example, Castle is an object, filled by database on startup. On aCis I recently moved hardcoded or SQL data related to static stuff to XML, but basically the Castle object is filled with int, List<MercenaryTicket>, List<Integer>, etc etc...

 

So long answer short, create your own Object class holding properties, then either use a StatsSet to feed that object or put every single parameters in the constructor :

public class Castle
{
     int _castleId;
     String _name;

     // By feeding each parameters into constructor
     public Castle(int id, String name)
     {
          _castleId = id;
          _name = name;
     }


     // By feeding using a StatsSet
     public Castle(StatsSet data)
     {
          _castleId = data.getInteger("castleId");
          _name = data.getString("name");
     }
}

Obviously StatsSet is just more readable when you got 10, 15, 20 parameters to pass on the godamn constructor.

 

You can also feed your object using public setter. As you can see, the castle exemple simply got 2 properties when it normally got billions other (artifact id, circlet, list of mercenary tickets,...). The XML handles that scenario when parsing the XML :

...
if ("artifact".equalsIgnoreCase(cat.getNodeName()))
	castle.setArtifacts(cat.getAttributes().getNamedItem("val").getNodeValue());
...

And then, on Castle object :

public void setArtifacts(String idsToSplit)
{
	for (String idToSplit : idsToSplit.split(";"))
		_artifacts.add(Integer.parseInt(idToSplit));
}

That scenario is right for anything :

- ArmorSetTable uses ArmorSet as storage object.

- FishTable uses FishData

- CastleManager uses Castle

etc etc.

 

On aCis and latest L2J, you also have generic holders such as IntIntHolder which avoid to generate your own class but simply retrieve it from a id/value. IntIntHolder is useful to store skillId, skillLevel or itemId, price. Beware, IntIntHolder is still an object to create - it simply avoids you to write your own little inner classes when you need only to store a paired int/int.

Edited by Tryskell
Posted

A StatSet is nothing more than a extended HashMap with more methods, allowing you for a String key to retrieve any type of object. It allows easy fill on loading, for the cost of overhead. A StatSet shouldn't really be used because of the overhead generated by String key. You could for example move every single variable from L2PcInstance into a single StatsSet (which will allow you to drop every single getter and setter). Will you do it, knowing that you must .get( the Map when you could simply retrieve the correct boolean/int/String by yourself with a getter if that was written normally ? I don't think so.

 

Also, a FastMap got no use at all to load static data, you both don't need the potential concurrency from .shared(true), nor the ordered system. You just create overhead for nothing using a FastMap.

 

The proper way is to create you own class defining the object similar to... Everything else :P. For example, Castle is an object, filled by database on startup. On aCis I recently moved hardcoded or SQL data related to static stuff to XML, but basically the Castle object is filled with int, List<MercenaryTicket>, List<Integer>, etc etc...

 

So long answer short, create your own Object class holding properties, then either use a StatsSet to feed that object or put every single parameters in the constructor :

public class Castle
{
     int _castleId;
     String _name;

     // By feeding each parameters into constructor
     public Castle(int id, String name)
     {
          _castleId = id;
          _name = name;
     }


     // By feeding using a StatsSet
     public Castle(StatsSet data)
     {
          _castleId = data.getInteger("castleId");
          _name = data.getString("name");
     }
}

Obviously StatsSet is just more readable when you got 10, 15, 20 parameters to pass on the godamn constructor.

 

You can also feed your object using public setter. As you can see, the castle exemple simply got 2 properties when it normally got billions other (artifact id, circlet, list of mercenary tickets,...). The XML handles that scenario when parsing the XML :

...
if ("artifact".equalsIgnoreCase(cat.getNodeName()))
	castle.setArtifacts(cat.getAttributes().getNamedItem("val").getNodeValue());
...

And then, on Castle object :

public void setArtifacts(String idsToSplit)
{
	for (String idToSplit : idsToSplit.split(";"))
		_artifacts.add(Integer.parseInt(idToSplit));
}

That scenario is right for anything :

- ArmorSetTable uses ArmorSet as storage object.

- FishTable uses FishData

- CastleManager uses Castle

etc etc.

 

On aCis and latest L2J, you also have generic holders such as IntIntHolder which avoid to generate your own class but simply retrieve it from a id/value. IntIntHolder is useful to store skillId, skillLevel or itemId, price. Beware, IntIntHolder is still an object to create - it simply avoids you to write your own little inner classes when you need only to store a paired int/int.

 

 

First of all thanks for being serious. Afcourse Sset is more readable by user when you play with 10 different objects and variables example to store an Event Data which require let's say

1. team color (FastMap)

2. team name (FastMap)

3. map data which contain team position (FastMap into FastMap)

 

e.t.c and i don't know how many more variables can you store but since i made an event and i'm using FastMaps to store objects after 4 fastMaps it kinda start getting ridiculously hard. I mean only the idea

get(x).get(x).get(x).get(x) after 5 times it kill my brain.

 

Also i'm not really familiar when it come in Statset to load from xml. Everytime you load data from xml you have plenty of options and if they exist since you're using

 

 

 

if ("artifact".equalsIgnoreCase(cat.getNodeName()))

 

so since we don't know how many variables are loaded we can't set the statset. Maybe is complicated in my head thats why i asked any alternative idea. I want avoid making different classes

to make objects, i want keep all in 1 class and all in 1 method and make a simple style like    xxxx.getEvent(1).getData().getEventMap(1).getPositionForTeam(1); or something simple like that to avoid the 

mess i have right now with different classes. The idea behind this is to make a statsset that as you said extends HMs and contain other elements or other statsets inside if i'm right. The idea is pretty much easy.

I don't really want an example or anything i just wanted to know if the way i mention is better to be done with Sset or any other way in order to avoid making different classes and keep all in 1. 

 

Thanks again.

Posted

Are you trolling again or what? :lol:

No i'm actualy asking advice of someone more experienced to tell me if is ok to continue the idea i mentionted with the Sset or what. 

No searching for solution or examples just a yes or no and if is fine.

Posted

I answered you, StatsSet generates a overhead where basic properties don't. StatsSet should be kept only for data feeding.

 

And you obviously know what data you are loading for a raw stuff like Event. If you got a followup of get.get.get, it simply shows how terrible you structured your stuff. That's the sort of stuff to think BEFORE coding it.

 

An Event class probably has :

- int _id

- String _description

- List<L2PcInstance> _players

- List<Location> (or SpawnLocation) _spawnPoints

 

A Team class (can be edited for an extended enum) is different than a Event class. Don't melt everything. It probably has :

- int _id

- String _name

- int _color

 

etc etc.

Posted

It really depends what you want to do.

What should be taken into consideration:

- If object will change in time or loaded just once

- If it will be changed from multiple threads at the time

- How long(size, length) is it going to be

- What kind of access to it you want to have. It will be just fully iterated often, get(x), maybe you just want to take first index and then remove it?

 

Don't use FastList just because it is "fast".

 

If you want to load data from xml, i strongly suggest simple array(or obviously arrayList which might be later .trimToSize()).

 

Don't make FastMap<Integer, FastMap<String, int[]>>

Make:

ArrayList<MyContainer>();

class MyContainer
{
    private final int id;
    private final List<MySecondContainer> importantNameHere;
}

class MySecondContainer
{
    private final int String nameMaybe;
    private final int[] someKindOfData;
}

Thats most secure way.

- How long(size, length) is it going to be

Posted (edited)

It really depends what you want to do.

What should be taken into consideration:

- If object will change in time or loaded just once

- If it will be changed from multiple threads at the time

- How long(size, length) is it going to be

- What kind of access to it you want to have. It will be just fully iterated often, get(x), maybe you just want to take first index and then remove it?

 

Don't use FastList just because it is "fast".

 

If you want to load data from xml, i strongly suggest simple array(or obviously arrayList which might be later .trimToSize()).

 

Don't make FastMap<Integer, FastMap<String, int[]>>

Make:

ArrayList<MyContainer>();

class MyContainer
{
    private final int id;
    private final List<MySecondContainer> importantNameHere;
}

class MySecondContainer
{
    private final int String nameMaybe;
    private final int[] someKindOfData;
}

Thats most secure way.

- How long(size, length) is it going to be

 

Yeap kinda trying to make it like this

private final FastMap<Integer, ArrayList> _mapLocation = new FastMap<Integer, ArrayList>().shared();
	
	private class MapData
	{
		private String _mapName;
		private FastMap<Integer, ArrayList> mapLocation;
		
		private MapData(String mapName, FastMap<Integer, ArrayList> list)
		{
			_mapName = mapName;
			mapLocation = list;
		}
		
		public ArrayList getMapLocationByOwner(String owner)
		{
			ArrayList list = _mapLocation.get(owner);
			return list;
		}
		
		public String getMapName()
		{
			return _mapName;
		}
	}
	
	/**
	 * 
	 * @param id
	 * @return Selected map base on input id
	 */
	public MapData getMapById(int id)
	{
		if (_mapData.containsKey(id))
			return _mapData.get(id);
		else
			System.out.print("Error trying get null MAP");
		
		return null;
	}

Thats why i did until now but still is a bit fucked up..

 

And in ArrayList imma put HashMaps tho. Ps ignore the "_mapLocation.get(owner);"

Edited by AccessDenied
Posted

First of all, those locations are going to be just loaded and stay the same until server or xml restart yes? Then you dont need to make them .shared().

If you dont need shared, why bother to use FastMap at all, it is better to use HashMap.

 

Since you are querying the data by just .get(ID), map will be faster than list or set or other collections. 

You should notice that Map<Integer, something> creates Integer object for each record. Integer is not the same as int, it takes far more memory. If you have small collection, thats fine, why would we care. If you have big collection like all items, thats big deal.

Also in getMapById(int) int is cast to Integer, it takes additional time, but thats fine. You might use .getOrDefault in there, takes just 1 line.

 

ArrayList thing in MapData i skip.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



  • Posts

    • I was looking for  server with a low rates,eventually i found l2 elixir.I Joined beta and after so many years since 2008 i found  a friend that we played together, memories came back. i cant wait for the grand oppening!. dont miss it!
    • Seems legit, for sure deserves a try!
    • SOCNET VERIFICATION SERVICE — is a universal solution for those who value security, convenience, and quality. We turn the verification process into a convenient, fast, and highly confidential experience. Thanks to our service, any of your accounts receive identity confirmation, an increased level of trust from platforms and users, as well as protection from bans, fraud, and risks.   Promotion: Pay for your first verification and get a 10% discount on the second one! 💎 We help with verification on Fragment, crypto exchanges ByBit, Gate, Bitget, OKX, Binance, PayPal, KuCoin, and social networks LinkedIn, Facebook, Instagram, Twitter (X) and many other platforms! 💎 Verification for any service: crypto exchanges, trading platforms, hosting providers, casinos and other websites. Why choose us:   Premium quality — we use the most advanced verification methods. High processing speed — accelerated verification on leading platforms, online services and social networks. Full confidentiality — your personal information is protected. Increased trust and status — a verified account boosts influence and improves conversion. Individual approach — we work with bloggers, brands, businesses, and private clients. Simplifying complexity — we handle issues when dealing with foreign services. Important! Services related to illegal activities are strictly prohibited! 💳 Service pricing   ✅ Verification of individuals — from $30 (the exact cost depends on the required location and service/app/website). Learn more 👨‍💼 The cost of business verification for companies or legal entities is discussed individually with the service administration. Learn more If you want us to register your account on the required service and verify it — you will need to additionally pay 10% of the transaction amount. Available payment methods: cryptocurrency, credit cards, PayPal, and other payment methods in our online store and Telegram bot.   ⭐ Our Online Store ⭐ SOCNET.STORE ⭐ Telegram Store ⭐ SOCNET.SHOP ⭐ Our SMS Service ⭐ SOCNET.APP ⭐ Our Telegram Bot for buying Telegram Stars ⭐ SOCNET.CC ⭐ Our SMM Panel ⭐ SOCNET.PRO   ✅ News Resources ➡ Telegram Channel ➡ WhatsApp Channel ➡ Discord Server     ⭐ We invite you to COOPERATE and EARN with us ⭐ Would you like to sell your product or service in our stores and earn money? Become our partner or offer mutually beneficial collaboration? You can contact us via the CONTACTS listed in this topic. ✅ Contacts & Support ➡ Telegram Support ➡ WhatsApp Support ➡ Discord Support: socnet_support ➡ Email Support: solomonbog@socnet.store   Terms of Use and Refund Policy If you have any questions or issues, our fast support service is ready to respond to your requests! A refund for a completed service that does not fully meet the requirements or the declared quality is possible only if the product description includes a warranty and a valid warranty period. In other cases, a full refund for the service will not be provided! By purchasing such a service, you automatically agree to our refund rules for non-provided services! Refunds for countries selected by mistake are not provided after verification. To complete verification, you must provide full access to your account. We currently accept cryptocurrency, credit cards, PayPal, and other payment methods in our online store and Telegram bot! We value every client and provide replacements in case of invalid accounts via our contact channels! Attention: Your order will be delivered to your personal Google Drive/Mega.nz via a link (check the link, click “View content”) within 24 hours after the order confirmation! If you purchased more than 1 item at once, your entire order will be delivered via the first link! The remaining links will be empty! You will automatically receive an email notification after delivery! If you pay on our website via PayPal, you must pay an additional 20% commission (minimum $1). To avoid this commission, you can pay me directly via PayPal — instructions are available on the website! Refunds for items purchased by mistake or due to “I chose the wrong product and did not use it” are not accepted! You are fully responsible for your actions before and after purchase.
    • SOCNET VERIFICATION SERVICE — is a universal solution for those who value security, convenience, and quality. We turn the verification process into a convenient, fast, and highly confidential experience. Thanks to our service, any of your accounts receive identity confirmation, an increased level of trust from platforms and users, as well as protection from bans, fraud, and risks.   Promotion: Pay for your first verification and get a 10% discount on the second one! 💎 We help with verification on Fragment, crypto exchanges ByBit, Gate, Bitget, OKX, Binance, PayPal, KuCoin, and social networks LinkedIn, Facebook, Instagram, Twitter (X) and many other platforms! 💎 Verification for any service: crypto exchanges, trading platforms, hosting providers, casinos and other websites. Why choose us:   Premium quality — we use the most advanced verification methods. High processing speed — accelerated verification on leading platforms, online services and social networks. Full confidentiality — your personal information is protected. Increased trust and status — a verified account boosts influence and improves conversion. Individual approach — we work with bloggers, brands, businesses, and private clients. Simplifying complexity — we handle issues when dealing with foreign services. Important! Services related to illegal activities are strictly prohibited! 💳 Service pricing   ✅ Verification of individuals — from $30 (the exact cost depends on the required location and service/app/website). Learn more 👨‍💼 The cost of business verification for companies or legal entities is discussed individually with the service administration. Learn more If you want us to register your account on the required service and verify it — you will need to additionally pay 10% of the transaction amount. Available payment methods: cryptocurrency, credit cards, PayPal, and other payment methods in our online store and Telegram bot.   ⭐ Our Online Store ⭐ SOCNET.STORE ⭐ Telegram Store ⭐ SOCNET.SHOP ⭐ Our SMS Service ⭐ SOCNET.APP ⭐ Our Telegram Bot for buying Telegram Stars ⭐ SOCNET.CC ⭐ Our SMM Panel ⭐ SOCNET.PRO   ✅ News Resources ➡ Telegram Channel ➡ WhatsApp Channel ➡ Discord Server     ⭐ We invite you to COOPERATE and EARN with us ⭐ Would you like to sell your product or service in our stores and earn money? Become our partner or offer mutually beneficial collaboration? You can contact us via the CONTACTS listed in this topic. ✅ Contacts & Support ➡ Telegram Support ➡ WhatsApp Support ➡ Discord Support: socnet_support ➡ Email Support: solomonbog@socnet.store   Terms of Use and Refund Policy If you have any questions or issues, our fast support service is ready to respond to your requests! A refund for a completed service that does not fully meet the requirements or the declared quality is possible only if the product description includes a warranty and a valid warranty period. In other cases, a full refund for the service will not be provided! By purchasing such a service, you automatically agree to our refund rules for non-provided services! Refunds for countries selected by mistake are not provided after verification. To complete verification, you must provide full access to your account. We currently accept cryptocurrency, credit cards, PayPal, and other payment methods in our online store and Telegram bot! We value every client and provide replacements in case of invalid accounts via our contact channels! Attention: Your order will be delivered to your personal Google Drive/Mega.nz via a link (check the link, click “View content”) within 24 hours after the order confirmation! If you purchased more than 1 item at once, your entire order will be delivered via the first link! The remaining links will be empty! You will automatically receive an email notification after delivery! If you pay on our website via PayPal, you must pay an additional 20% commission (minimum $1). To avoid this commission, you can pay me directly via PayPal — instructions are available on the website! Refunds for items purchased by mistake or due to “I chose the wrong product and did not use it” are not accepted! You are fully responsible for your actions before and after purchase.
    • +8? Isnt +5 max per one stat?
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock