diff --git a/src/ControlledVocabulary/CvParam.fs b/src/ControlledVocabulary/CvParam.fs index 8a7e737..ef0766c 100644 --- a/src/ControlledVocabulary/CvParam.fs +++ b/src/ControlledVocabulary/CvParam.fs @@ -45,7 +45,7 @@ type CvParam(cvAccession : string, cvName : string, cvRef : string, paramValue : CvParam (cvTerm,ParamValue.Value v) member this.Equals (term : CvTerm) = - CvBase.equalsTerm term this + Param.equalsTerm term this member this.Equals (cv : ICvBase) = CvBase.equals cv this @@ -53,6 +53,88 @@ type CvParam(cvAccession : string, cvName : string, cvRef : string, paramValue : member this.Equals (cvp : CvParam) = this.Equals(cvp :> ICvBase) + //---------------------- IParam implementations ----------------------// + + /// Returns the value of the Param as a ParamValue + static member getParamValue (cvp: CvParam) = Param.getParamValue cvp + + /// Returns the value of the Param as IConvertible + static member getValue (cvp: CvParam) = Param.getValue cvp + + /// Returns the value of the Param as string + static member getValueAsString (cvp: CvParam) = Param.getValueAsString cvp + + /// Returns the value of the Param as int if possible, else fails + static member getValueAsInt (cvp: CvParam) = Param.getValueAsInt cvp + + /// Returns the value of the Param as a term + static member getValueAsTerm (cvp: CvParam) = Param.getValueAsTerm cvp + + static member tryGetValueAccession (cvp: CvParam) = Param.tryGetValueAccession cvp + + static member tryGetValueRef (cvp: CvParam) = Param.tryGetValueRef cvp + + static member tryGetCvUnit (cvp: CvParam) : CvUnit option = Param.tryGetCvUnit cvp + + static member tryGetCvUnitValue (cvp: CvParam) = Param.tryGetCvUnitValue cvp + + static member tryGetCvUnitTermName (cvp: CvParam) = Param.tryGetCvUnitTermName cvp + + static member tryGetCvUnitTermAccession (cvp: CvParam) = Param.tryGetCvUnitTermAccession cvp + + static member tryGetCvUnitTermRef (cvp: CvParam) = Param.tryGetCvUnitTermRef cvp + + static member mapValue (f : ParamValue -> ParamValue) (cvp: CvParam) = Param.mapValue f cvp :?> CvParam + + static member tryMapValue (f : ParamValue -> ParamValue option) (cvp: CvParam) = + Param.tryMapValue f cvp + |> Option.map (fun v -> v :?> CvParam) + + static member tryAddName (name : string) (cvp: CvParam) = + Param.tryAddName name cvp + |> Option.map (fun v -> v :?> CvParam) + + static member tryAddAccession (acc : string) (cvp: CvParam) = + Param.tryAddAccession acc cvp + |> Option.map (fun v -> v :?> CvParam) + + static member tryAddReference (ref : string) (cvp: CvParam) = + Param.tryAddReference ref cvp + |> Option.map (fun v -> v :?> CvParam) + + static member tryAddUnit (unit : CvUnit) (cvp: CvParam) = + Param.tryAddUnit unit cvp + |> Option.map (fun v -> v :?> CvParam) + + /// Returns the id of the cv item + static member getCvAccession (cvp: CvParam) = Param.getCvAccession cvp + + /// Returns the name of the cv item + static member getCvName (cvp: CvParam) = Param.getCvName cvp + + /// Returns the reference of the cv item + static member getCvRef (cvp: CvParam) = Param.getCvRef cvp + + /// Returns the full term of the cv item + static member getTerm (cvp: CvParam) = Param.getTerm cvp + + /// Returns true, if the given term matches the term of the cv item + static member equalsTerm (term : CvTerm) (cvp: CvParam) = Param.equalsTerm term cvp + + /// Returns true, if the terms of the given param items match + static member equals (cvp1 : CvParam) (cvp2 : CvParam) = Param.equals cvp1 cvp2 + + /// Returns true, if the names of the given param items match + static member equalsName (cvp1 : CvParam) (cvp2 : CvParam) = Param.equalsName cvp1 cvp1 + + /// Returns Some Value of type 'T, if the given param item can be downcast, else returns None + static member inline tryAs<'T when 'T :> IParam> (cvp: CvParam) = Param.tryAs<'T> cvp + + /// Returns true, if the given param item can be downcast + static member inline is<'T when 'T :> IParam> (cvp: CvParam) = Param.is<'T> cvp + + //---------------------- CvParam specific implementations ----------------------// + /// Create a CvParam from a category and a simple value static member fromValue (category : CvTerm) (v : 'T) = CvParam(category, ParamValue.Value (v :> IConvertible)) @@ -65,28 +147,9 @@ type CvParam(cvAccession : string, cvName : string, cvRef : string, paramValue : static member fromValueWithUnit (category : CvTerm) (v : 'T) (unit : CvUnit) = CvParam(category, ParamValue.WithCvUnitAccession (v :> IConvertible,unit)) - static member mapValue (f : ParamValue -> ParamValue) (param : CvParam) = - Param.mapValue f param - - static member tryMapValue (f : ParamValue -> ParamValue option) (param : CvParam) = - Param.tryMapValue f param - - static member tryAddName (value : string) (param : CvParam) = - Param.tryAddName value param - - static member tryAddAccession (id : string) (param : CvParam) = - Param.tryAddAccession id param - - static member tryAddReference (ref : string) (param : CvParam) = - Param.tryAddReference ref param - - static member tryAddUnit (unit : CvUnit) (param : CvParam) = - Param.tryAddUnit unit param - static member getAttributes (param : CvParam) = param.Values |> Seq.cast - override this.ToString() = $"CvParam: {(this :> ICvBase).Name}\n\tID: {(this :> ICvBase).Accession}\n\tRefUri: {(this :> ICvBase).RefUri}\n\tValue: {(this :> IParamBase).Value}\n\tAttributes: {this.Keys |> Seq.toList}" diff --git a/src/ControlledVocabulary/UserParam.fs b/src/ControlledVocabulary/UserParam.fs index 3fea704..6ecc493 100644 --- a/src/ControlledVocabulary/UserParam.fs +++ b/src/ControlledVocabulary/UserParam.fs @@ -29,6 +29,86 @@ type UserParam(name : string, paramValue : ParamValue, attributes : IDictionary< new (name,pv) = UserParam (name,pv,Seq.empty) + //---------------------- IParam implementations ----------------------// + + /// Returns the value of the Param as a ParamValue + static member getParamValue (up: UserParam) = Param.getParamValue up + + /// Returns the value of the Param as IConvertible + static member getValue (up: UserParam) = Param.getValue up + + /// Returns the value of the Param as string + static member getValueAsString (up: UserParam) = Param.getValueAsString up + + /// Returns the value of the Param as int if possible, else fails + static member getValueAsInt (up: UserParam) = Param.getValueAsInt up + + /// Returns the value of the Param as a term + static member getValueAsTerm (up: UserParam) = Param.getValueAsTerm up + + static member tryGetValueAccession (up: UserParam) = Param.tryGetValueAccession up + + static member tryGetValueRef (up: UserParam) = Param.tryGetValueRef up + + static member tryGetCvUnit (up: UserParam) : CvUnit option = Param.tryGetCvUnit up + + static member tryGetCvUnitValue (up: UserParam) = Param.tryGetCvUnitValue up + + static member tryGetCvUnitTermName (up: UserParam) = Param.tryGetCvUnitTermName up + + static member tryGetCvUnitTermAccession (up: UserParam) = Param.tryGetCvUnitTermAccession up + + static member tryGetCvUnitTermRef (up: UserParam) = Param.tryGetCvUnitTermRef up + + static member mapValue (f : ParamValue -> ParamValue) (up: UserParam) = Param.mapValue f up :?> CvParam + + static member tryMapValue (f : ParamValue -> ParamValue option) (up: UserParam) = + Param.tryMapValue f up + |> Option.map (fun v -> v :?> UserParam) + + static member tryAddName (name : string) (up: UserParam) = + Param.tryAddName name up + |> Option.map (fun v -> v :?> UserParam) + + static member tryAddAccession (acc : string) (up: UserParam) = + Param.tryAddAccession acc up + |> Option.map (fun v -> v :?> UserParam) + + static member tryAddReference (ref : string) (up: UserParam) = + Param.tryAddReference ref up + |> Option.map (fun v -> v :?> UserParam) + + static member tryAddUnit (unit : CvUnit) (up: UserParam) = + Param.tryAddUnit unit up + |> Option.map (fun v -> v :?> UserParam) + + /// Returns the id of the cv item + static member getCvAccession (up: UserParam) = Param.getCvAccession up + + /// Returns the name of the cv item + static member getCvName (up: UserParam) = Param.getCvName up + + /// Returns the reference of the cv item + static member getCvRef (up: UserParam) = Param.getCvRef up + + /// Returns the full term of the cv item + static member getTerm (up: UserParam) = Param.getTerm up + + /// Returns true, if the given term matches the term of the cv item + static member equalsTerm (term : CvTerm) (up: UserParam) = Param.equalsTerm term up + + /// Returns true, if the terms of the given param items match + static member equals (up1: UserParam) (up2: UserParam) = Param.equals up1 up2 + + /// Returns true, if the names of the given param items match + static member equalsName (up1: UserParam) (up2: UserParam) = Param.equalsName up1 up2 + + /// Returns Some Value of type 'T, if the given param item can be downcast, else returns None + static member inline tryAs<'T when 'T :> IParam> (up: UserParam) = Param.tryAs<'T> up + + /// Returns true, if the given param item can be downcast + static member inline is<'T when 'T :> IParam> (up: UserParam) = Param.is<'T> up + override this.ToString() = $"Name: {(this :> ICvBase).Name}\n\tValue: {(this :> IParamBase).Value}\n\tQualifiers: {this.Keys |> Seq.toList}"