-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String → Identifier #238
String → Identifier #238
Conversation
Current coverage is 14.26% (diff: 28.48%)@@ master #238 diff @@
==========================================
Files 393 398 +5
Lines 10984 11076 +92
Methods 0 0
Messages 0 0
Branches 1580 1585 +5
==========================================
+ Hits 1569 1580 +11
- Misses 9329 9405 +76
- Partials 86 91 +5
|
You may disagree but I believe this thing should NPE everywhere. |
You need to learn how to use a damn immutable object. And a constructor for such an immutable object. |
Ive yet to understand why you'd need these. Interned strings are enough of an identifier to me... You know, something like this: interface Identifier {
public static String of(String str) { return String.intern(str); }
public static String of(UUID uuid) { return String.intern(uuid.toString()); }
public static String of(Class<?> clazz) { return String.intern(clazz.getName()); }
} Or if you don't like this because of the pitfall that you have to call Identifier.of() to make sure that it is an interned String... class Identifier {
private String interned;
private Identifier(String id) { this.interned = String.intern(id); }
@Override
public boolean equals(Object o) {
// Look at how simple equality becomes
if (o instanceof Identifier)
return ((Identifier)o).interned == this.interned;
return false;
}
@Override
public int hashCode() { return interned.hashCode(); }
public static Identifier of(String str) { return new Identifier(str); }
public static Identifier of(UUID uuid) { return new Identifier(uuid.toString()); }
public static Identifier of(Class<?> clazz) { return new Identifier(clazz.getName()); }
} Downside of that is that you can't compare them with |
@Override | ||
public abstract boolean equals(Object other); | ||
|
||
protected static final <T extends Identifier> boolean equalsImpl(Identifier _this, Object other, Class<T> superclass, Function<T,Object> getter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self
instead of _this
? Is there a convention on this like clazz
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done now.
/** | ||
* @author ExE Boss | ||
*/ | ||
public enum EnumExample { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change shouldn't be in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was done to allow testing of EnumIdentifier
using my EnumExample
class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, okay.
@Victorious3 wouldn't interned strings technically work with |
…s in base identifier types final
@RX14 Yes they do see my 0815 implementation. Hence why I said interned strings are all you need for identifers. And Identifier.of("foo") == Identifier.of(new String(new char[] {'f', 'o', 'o'}))); Not if you go with the simple wrapper class approach tho. Which is more safe because you wont accidentally forget to call |
@Victorious3 The issue is Identifier.of("net.minecraft.block.Block") == Identifier.of(net.minecraft.block.Block.class). That should NEVER be able to happen. BUT OTHER THAN THAT, THEY SHOULD ACT LIKE THE String CLASS: THEY SHOULD BE IMMUTABLE. Imagine you have an Identifier in 20 different places, including hashmap keys and stuff, then you accidentally call .load() on it. For one it'd break the hashmap contract. And it's just plain insane! @ExE-Boss Could you at least TALK TO ME ABOUT IT before doing something completely messed up?! |
@SoniEx2 How about you calm the fuck down and suggest improvements nicely instead of shouting at people. It won't make them take your input more seriously. |
@RX14 I'll happily shout at someone who's touching code I wrote without any idea of what the code should do. |
@SoniEx2 Well, if you keep doing it you won't be commenting on this issue tracker any more. You talk nicely or don't talk at all. |
@RX14 Fine. Part of the reason I made the PR was so I could put different kinds of identifiers in the same HashMap without having them conflict. Something I couldn't do with strings. A NamespacedStringIdentifier should contain an inner static class called NamespacedStringData, and that class should be used as the identifier type. The equals and hashCode methods should be final, since otherwise equals wouldn't be symmetric. This is also why we can't/shouldn't have null IDs. |
And string is useless for older Minecraft versions. |
@SoniEx2 This is Nova CORE it doesn't CARE about "Minecraft Versions" |
And the Minecraft wrappers are directly integrated into NOVA Core (kinda why they're in the same repo instead of being in their own repos). |
@SoniEx2 If you manage to name one problem that this overbloated PR supposedly solves, then go for it. You are shooting with cannons at ants. I'm for simplicity and ease of use and things like |
Please make Mojang remove Minecraft's ResourceLocation. It's bloated. |
@SoniEx2 Besides this being completely off point, ResourceLocation is NOT an identifier. It serves the purpose of being able to locate files within the jar or resource packs which use completely different file paths. |
@Victorious3 It is actually NO different from a NamespacedStringIdentifier. It identifies block names, item names, etc. |
@Victorious3 While I share your opinion, that doesn't mean I won't remove you from the project or issue tracker if you continue to be rude. |
You just need to talk to some java pros about it. Maybe even @calclavia (altho I'm not sure how "pro" they are). |
On the NOVA discord server, I’ve discussed this with RX14 and we decided the following: I would continue working on my version of the Identifier API and once all the versions of the Identifier API are fully implemented, we will compare them and decide which implementation is the best and end up using that. |
I need something I can use with HashMaps and stuff. I cannot use this implementation, and strings are unsuitable due to their conflicting nature. |
@SoniEx2 You dont throw two different types of Objects into the same map. Just dont do it. Then you are fine. |
I can throw String and Class and UUID all into the same Map just fine. They don't conflict with eachother. I want it to also work for Identifiers. It has its uses. (Also, part of the reason I made the PR was so mods could extend Identifier and create their own Identifiers for their own purposes. Like using Identifier for a programming language/compiler. That is where being able to mix Identifiers together in a Map is a really useful feature to have. I agree that @ExE-Boss 's version is bloated. It's also unsuitable for my use-case. Unlike my version.) |
And then its a
Mhm. Sounds like something I'd do every day. |
@loordgek And so might any other object that implements |
I miss @calclavia, the only professional/sane java dev we had on this POS. |
@SoniEx2 can you stop crying ranting plz |
@ExE-Boss What's the NOVA discord server? I'd like to join just to see what you guys are up to. |
@calclavia The server is https://discord.gg/Sh63S4H |
@loordgek Never. If you don't like it, why do you keep doing things that cause it? |
@SoniEx2 goodbye |
@SoniEx2 has pretty much abandoned his PR, so I’m taking over.
For a detailed description of what this does, see #227.
To do list:
String
serialization.IdentifierFactory
(or whatever I called it) and replace it with theStorable
interface.Completed:
StringIdentifier
,ClassIdentifier
andUUIDIdentifier
(SoniEx2)NamespacedStringIdentifier
andEnumIdentifier
null
. That throws aNullPointerException
.Identifier
everywhereString
→StringIdentifier
method inFactoryManager
Should we keep it or not?
Closes #227