-
Notifications
You must be signed in to change notification settings - Fork 1
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
Remove weirdness from Fingerprint methods #40
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
* @since 1.0 | ||
* @license GPL-2.0+ | ||
* @author H. Snater < [email protected] > | ||
* @author Bene* < [email protected] > | ||
* | ||
* @constructor | ||
* | ||
|
@@ -74,12 +75,11 @@ $.extend( SELF.prototype, { | |
}, | ||
|
||
/** | ||
* @param {string} languageCode | ||
* @param {wikibase.datamodel.Term} label | ||
* @return {boolean} | ||
*/ | ||
hasLabel: function( languageCode, label ) { | ||
return this._labels.hasItem( languageCode, label ); | ||
hasLabel: function( label ) { | ||
return this._labels.hasItem( label.getLanguageCode(), label ); | ||
}, | ||
|
||
/** | ||
|
@@ -91,23 +91,21 @@ $.extend( SELF.prototype, { | |
}, | ||
|
||
/** | ||
* @param {string} languageCode | ||
* @param {wikibase.datamodel.Term|null} term | ||
* @param {wikibase.datamodel.Term|null} label | ||
*/ | ||
setLabel: function( languageCode, term ) { | ||
if ( term === null || term.getText() === '' ) { | ||
this._labels.removeItemByKey( languageCode ); | ||
setLabel: function( label ) { | ||
if ( label === null || label.getText() === '' ) { | ||
this._labels.removeItemByKey( label.getLanguageCode() ); | ||
} else { | ||
this._labels.setItem( languageCode, term ); | ||
this._labels.setItem( label.getLanguageCode(), label ); | ||
} | ||
}, | ||
|
||
/** | ||
* @param {string} languageCode | ||
* @param {wikibase.datamodel.Term} label | ||
*/ | ||
removeLabel: function( languageCode, label ) { | ||
this._labels.removeItem( languageCode, label ); | ||
removeLabel: function( label ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also have Edit: Even |
||
this._labels.removeItem( label.getLanguageCode(), label ); | ||
}, | ||
|
||
/** | ||
|
@@ -133,12 +131,11 @@ $.extend( SELF.prototype, { | |
}, | ||
|
||
/** | ||
* @param {string} languageCode | ||
* @param {wikibase.datamodel.Term} description | ||
* @return {boolean} | ||
*/ | ||
hasDescription: function( languageCode, description ) { | ||
return this._descriptions.hasItem( languageCode, description ); | ||
hasDescription: function( description ) { | ||
return this._descriptions.hasItem( description.getLanguageCode(), description ); | ||
}, | ||
|
||
/** | ||
|
@@ -150,23 +147,21 @@ $.extend( SELF.prototype, { | |
}, | ||
|
||
/** | ||
* @param {string} languageCode | ||
* @param {wikibase.datamodel.Term|null} term | ||
* @param {wikibase.datamodel.Term|null} description | ||
*/ | ||
setDescription: function( languageCode, term ) { | ||
if ( term === null || term.getText() === '' ) { | ||
this._descriptions.removeItemByKey( languageCode ); | ||
setDescription: function( description ) { | ||
if ( description === null || description.getText() === '' ) { | ||
this._descriptions.removeItemByKey( description.getLanguageCode() ); | ||
} else { | ||
this._descriptions.setItem( languageCode, term ); | ||
this._descriptions.setItem( description.getLanguageCode(), description ); | ||
} | ||
}, | ||
|
||
/** | ||
* @param {string} languageCode | ||
* @param {wikibase.datamodel.Term} description | ||
*/ | ||
removeDescription: function( languageCode, description ) { | ||
this._descriptions.removeItem( languageCode, description ); | ||
removeDescription: function( description ) { | ||
this._descriptions.removeItem( description.getLanguageCode(), description ); | ||
}, | ||
|
||
/** | ||
|
@@ -192,12 +187,11 @@ $.extend( SELF.prototype, { | |
}, | ||
|
||
/** | ||
* @param {string} languageCode | ||
* @param {wikibase.datamodel.MultiTerm} aliases | ||
* @return {boolean} | ||
*/ | ||
hasAliases: function( languageCode, aliases ) { | ||
return this._aliases.hasItem( languageCode, aliases ); | ||
hasAliases: function( aliases ) { | ||
return this._aliases.hasItem( aliases.getLanguageCode(), aliases ); | ||
}, | ||
|
||
/** | ||
|
@@ -209,37 +203,16 @@ $.extend( SELF.prototype, { | |
}, | ||
|
||
/** | ||
* @param {string|wikibase.datamodel.MultiTermMap} languageCodeOrAliases | ||
* @param {wikibase.datamodel.MultiTerm|null} [aliases] | ||
* | ||
* @throws {Error} when passing a MultiTerm without a language code. | ||
* @throws {Error} when passing a MultiTermMap with a language code. | ||
* @throws {Error} when neither passing a MultiTerm nor a MultiTermMap object. | ||
* @param {wikibase.datamodel.MultiTerm|wikibase.datamodel.MultiTermMap} aliases | ||
*/ | ||
setAliases: function( languageCodeOrAliases, aliases ) { | ||
var languageCode; | ||
|
||
if( typeof languageCodeOrAliases === 'string' ) { | ||
languageCode = languageCodeOrAliases; | ||
} else { | ||
aliases = languageCodeOrAliases; | ||
} | ||
|
||
if( aliases === null || aliases instanceof wb.datamodel.MultiTerm ) { | ||
if( !languageCode ) { | ||
throw new Error( 'Language code the wb.datamodel.MultiTerm object should be set ' | ||
+ 'for needs to be specified' ); | ||
} | ||
if ( aliases === null || aliases.isEmpty() ) { | ||
this._aliases.removeItemByKey( languageCode ); | ||
setAliases: function( aliases ) { | ||
if ( aliases instanceof wb.datamodel.MultiTerm ) { | ||
if ( aliases.isEmpty() ) { | ||
this._aliases.removeItemByKey( aliases.getLanguageCode() ); | ||
} else { | ||
this._aliases.setItem( languageCode, aliases ); | ||
this._aliases.setItem( aliases.getLanguageCode(), aliases ); | ||
} | ||
} else if( aliases instanceof wb.datamodel.MultiTermMap ) { | ||
if( languageCode ) { | ||
throw new Error( 'Unable to handle language code when setting a ' | ||
+ 'wb.datamodel.MultiTermMap' ); | ||
} | ||
this._aliases = aliases; | ||
} else { | ||
throw new Error( 'Aliases need to be specified as wb.datamodel.MultiTerm or ' | ||
|
@@ -248,11 +221,10 @@ $.extend( SELF.prototype, { | |
}, | ||
|
||
/** | ||
* @param {string} languageCode | ||
* @param {wikibase.datamodel.MultiTerm} aliases | ||
*/ | ||
removeAliases: function( languageCode, aliases ) { | ||
this._aliases.removeItem( languageCode, aliases ); | ||
removeAliases: function( aliases ) { | ||
this._aliases.removeItem( aliases.getLanguageCode(), aliases ); | ||
}, | ||
|
||
/** | ||
|
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.
As @JeroenDeDauw said this should be hasLabel: function( languageCode ).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.
Note that we already have
hasLabelFor
below which does exactly that. We could just remove this method but I think it is useful if you don't only want to check if a label is set but also compare it to the value passed here.