Skip to content
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

Add Literals.getLabel method that accepts Optional input value #688

Closed
abrokenjester opened this issue Dec 6, 2016 · 6 comments · Fixed by #2279
Closed

Add Literals.getLabel method that accepts Optional input value #688

abrokenjester opened this issue Dec 6, 2016 · 6 comments · Fixed by #2279
Assignees
Labels
📶 enhancement issue is a new feature or improvement good first issue issue is a good choice for getting started as an rdf4j contributor help wanted we could use your help in fixing this issue M1 Fixed in milestone 1
Milestone

Comments

@abrokenjester
Copy link
Contributor

Literals.getLabel only accepts actual Value objects (with a fallback when the Value is null or not a Literal).

In combination with, for example, Models.object() this leads to slightly convulated code:

String label = Literals.getLabel(Models.object(m.filter(...)).orElse(null), fallback);

If Literals.getLabel also accepted an Optional value directly, we could do this instead:

String label = Literals.getLabel(Models.object(m.filter(...)), fallback);
@abrokenjester abrokenjester added the 📶 enhancement issue is a new feature or improvement label Dec 6, 2016
@abrokenjester abrokenjester self-assigned this Dec 6, 2016
@catch-point catch-point added the help wanted we could use your help in fixing this issue label Nov 3, 2017
@abrokenjester abrokenjester added the good first issue issue is a good choice for getting started as an rdf4j contributor label Oct 21, 2018
@abrokenjester abrokenjester removed their assignment May 3, 2020
@raghav17083
Copy link

raghav17083 commented May 26, 2020

in the implementation of getLabel(), it is overloaded.

public static String getLabel(Literal l, String fallback) {
		return l != null ? l.getLabel() : fallback;
	}

	/**
	 * Returns the result of {@link #getLabel(Literal, String) getLabel((Literal)v, fallback} in case the supplied value
	 * is a literal, returns the fallback value otherwise.
	 */
	public static String getLabel(Value v, String fallback) {
		return v instanceof Literal ? getLabel((Literal) v, fallback) : fallback;
	}

Is this issue fixed, since getLabel can now handle null values also?

@abrokenjester
Copy link
Contributor Author

@raghav17083 not really - this issue is about having a Literals.getLabel method that accepts a java.util.Optional instead of only a Value or Literal as its first argument.

This:

 String label = Literals.getLabel(Models.object(m.filter(...)), fallback);

won't work right now, because the result of the Models.object call is an Optional, not a Value or Literal.

It's a fairly minor thing but having this option will make for slightly cleaner and easier to read code when using these functions.

@raghav17083
Copy link

So, does this mean that we just have to overload the getLabel() method to account for an 'Optional' call?

SakshiSaini17092 added a commit to raghav17083/rdf4j that referenced this issue May 27, 2020
Signed-off-by: SakshiSaini17092 <sakshi17092@iiitd.ac.in>
@abrokenjester
Copy link
Contributor Author

Yes, exactly

@abrokenjester
Copy link
Contributor Author

@SakshiSaini17092 thanks for the pull request. Are you and @raghav17083 working together on this?

@raghav17083
Copy link

@SakshiSaini17092 thanks for the pull request. Are you and @raghav17083 working together on this?

Yes!

SakshiSaini17092 added a commit to raghav17083/rdf4j that referenced this issue May 28, 2020
Signed-off-by: SakshiSaini17092 <sakshi17092@iiitd.ac.in>
abrokenjester pushed a commit that referenced this issue May 28, 2020
* GH-688: Added getLabel OptionalMethod for Optional

Signed-off-by: SakshiSaini17092 <sakshi17092@iiitd.ac.in>

* GH-688: Fixed the getLabel for Optional

Signed-off-by: SakshiSaini17092 <sakshi17092@iiitd.ac.in>
@abrokenjester abrokenjester added this to the 3.3.0 milestone May 28, 2020
@hmottestad hmottestad added the M1 Fixed in milestone 1 label Jun 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📶 enhancement issue is a new feature or improvement good first issue issue is a good choice for getting started as an rdf4j contributor help wanted we could use your help in fixing this issue M1 Fixed in milestone 1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants