/// /// <summary> * get the sum of all matching AmountPool/PartAmount/@attName as a double PartAmounts match if all attributes /// * match those in PartAmount, i.e. mPart is a submap of the searche PartAmount elements /// * /// * </summary> /// * <param name="attName"> the Attribute name , e.g Amount, ActualAmount </param> /// * <param name="mPart"> </param> /// * <returns> double - the element </returns> /// * <exception cref="JDFException"> if the element can not be cast to double </exception> /// public static double getAmountPoolDouble(IAmountPoolContainer poolParent, string attName, JDFAttributeMap mPart) { double d = 0; int n = 0; bool bFound = false; JDFAmountPool ap = poolParent.getAmountPool(); while (true) { string w = getAmountPoolAttribute(poolParent, attName, null, mPart, n); if (isWildCard(w)) { if (ap == null || ap.getPartAmount(mPart, n) == null) { return(bFound ? d : -1); } n++; continue; } double dd = StringUtil.parseDouble(w, -1.234567); if (dd == -1.234567) { throw new JDFException("JDFResourceLink.getAmountPoolDouble: Attribute " + attName + " has an invalid value"); } d += dd; bFound = true; n++; } }
/// /// <summary> * returns the attribute occurence in PartAmount, or the default in the ResourceLink /// * </summary> /// * <param name="attrib"> the attribute name </param> /// * <param name="nameSpaceURI"> the XML-namespace </param> /// * <param name="vPart"> defines which part of this ResourceLink the Amount belongs to. If null get the ResourceLink root /// * attribute. </param> /// * <returns> value of attribute found, null if not available /// * @since 071103 </returns> /// public static string getAmountPoolAttribute(IAmountPoolContainer poolParent, string attrib, string nameSpaceURI, VJDFAttributeMap vPart) { // want a map but already in a partamount - snafu if (poolParent is JDFPartAmount) { if (vPart != null) { throw new JDFException("JDFResourceLink.getAmountPoolAttribute: calling method on PartAmount object"); } return(poolParent.getAttribute(attrib, nameSpaceURI, null)); } // default to attribute if no amountpool JDFAmountPool amountPool = poolParent.getAmountPool(); if (amountPool == null || vPart == null) { return(poolParent.getAttribute(attrib, nameSpaceURI, null)); } JDFPartAmount pa = amountPool.getPartAmount(vPart); if (pa != null) // we have a pa; if it has the attribute return its // value, else get the link attribute { string ret = pa.getAttribute(attrib, nameSpaceURI, null); if (ret != null) { return(ret); } } return(poolParent.getAttribute(attrib, nameSpaceURI, null)); }
/// /// <summary> * get an amountmap for the Amountpool of poolParent </summary> /// * <param name="poolParent"> the pool parent </param> /// * <param name="vPartIDKeys"> </param> /// * <returns> the AmountMap for the Amountpool, null if no amountpool exists </returns> /// public static AmountMap getAmountMap(IAmountPoolContainer poolParent, VString vPartIDKeys) { if (poolParent == null || poolParent.getAmountPool() == null) { return(null); } return(poolParent.getAmountPool().getAmountMap(vPartIDKeys)); }
/// /// <summary> * get double attribute MaxAmount, defaults to getAmount if MinAmount is not set /// * </summary> /// * <param name="mPart"> partition map to retrieve MinAmount for </param> /// * <returns> the MinAmount value /// * @default getAmount(null) </returns> /// public static double getMaxAmount(IAmountPoolContainer poolParent, JDFAttributeMap mPart) { double d = getAmountPoolDouble(poolParent, AttributeName.MAXAMOUNT, mPart); if (d == -1) { return(getAmount(poolParent, mPart)); } return(d); }
/// /// <summary> * sets the attribute occurence in the appropriate PartAmount when called for a resourceLink and creates the /// * AmountPool and/or PartAmount(s) if they are not yet there /// * </summary> /// * <param name="attrib"> the attribute name </param> /// * <param name="value"> value to set in string form. </param> /// * <param name="nameSpaceURI"> the XML-namespace </param> /// * <param name="vPart"> defines which part of this ResourceLink the Amount belongs to, if empty set the ResourceLink /// * root attribute. </param> /// * <exception cref="JDFException"> when called directly on a PartAmount /// * @since 060630 </exception> /// public static void setAmountPoolAttribute(IAmountPoolContainer poolParent, string attrib, string @value, string nameSpaceURI, VJDFAttributeMap vPart) { // ideally the method would be hidden in PartAmount if ((vPart == null) || (vPart.IsEmpty()) || vPart.Count == 1 && vPart[0].Count == 0) { poolParent.setAttribute(attrib, @value, nameSpaceURI); return; } poolParent.removeAttribute(attrib, nameSpaceURI); // either in the // pool or the // link, not both JDFAmountPool ap = poolParent.getCreateAmountPool(); JDFPartAmount pa0 = ap.getCreatePartAmount(vPart); pa0.setAttribute(attrib, @value, nameSpaceURI); }
/// /// <summary> * get the exactly matching AmountPool/PartAmount/@AttName as a double /// * </summary> /// * <param name="attName"> </param> /// * <param name="vPart"> </param> /// * <returns> double - </returns> /// * <exception cref="JDFException"> if the element can not be cast to double </exception> /// public static double getAmountPoolDouble(IAmountPoolContainer poolParent, string attName, VJDFAttributeMap vPart) { double d = 0; string w = getAmountPoolAttribute(poolParent, attName, null, vPart); if (w == null) { return(-1); } d = StringUtil.parseDouble(w, -1.234567); if (d == -1.234567) { throw new JDFException("JDFResourceLink.getAmountPoolDouble: Attribute " + attName + " has an invalid value"); } return(d); }
/// /// <summary> * sets the attribute occurence in the appropriate PartAmount when called for a resourceLink and creates the /// * AmountPool and/or PartAmount if it is not yet there /// * </summary> /// * <param name="attrib"> the attribute name </param> /// * <param name="value"> value to set in string form. </param> /// * <param name="nameSpaceURI"> the XML-namespace </param> /// * <param name="mPart"> defines which part of this ResourceLink the Amount belongs to, if empty set the ResourceLink /// * root attribute </param> /// * <exception cref="JDFException"> when called directly on a PartAmount /// * @since 071103 </exception> /// public static void setAmountPoolAttribute(IAmountPoolContainer poolParent, string attrib, string @value, string nameSpaceURI, JDFAttributeMap mPart) { // ideally the method would be hidden in PartAmount if ((mPart == null) || (mPart.IsEmpty())) { poolParent.setAttribute(attrib, @value, nameSpaceURI); return; } if (poolParent is JDFPartAmount) { throw new JDFException("JDFResourceLink.setAmountPoolAttribute: calling method on PartAmount object"); } VJDFAttributeMap v = new VJDFAttributeMap(); v.Add(mPart); setAmountPoolAttribute(poolParent, attrib, @value, nameSpaceURI, v); }
/// /// <summary> * get double attribute Amount, defaults to the value of Amount for the linked partition /// * </summary> /// * <param name="mPart"> partition map to retrieve Amount for </param> /// * <returns> the amount, -1 if none is specified /// * /// * @default getAmount(null) </returns> /// public static double getAmount(IAmountPoolContainer poolParent, JDFAttributeMap mPart) { double d = getAmountPoolDouble(poolParent, AttributeName.AMOUNT, mPart); if (d == -1) { JDFResource target = poolParent.getLinkRoot(); if (target != null) { target = target.getPartition(mPart, null); if (target != null) { return(target.getAmount()); } } } else { return(d); } return(-1.0); }
/// /// /// <summary> * gets the sum of all matching tags, with the assumpzion that no condition defaults to good /// * </summary> /// * <param name="poolParent"> </param> /// * <param name="attName"> </param> /// * <param name="vPart"> </param> /// * <returns> the sum /// * </returns> /// public static double getAmountPoolSumDouble(IAmountPoolContainer poolParent, string attName, VJDFAttributeMap vPart) { VJDFAttributeMap vPartLocal = vPart; if (vPartLocal == null) { vPartLocal = poolParent.getPartMapVector(); } if (poolParent.hasAttribute(attName)) { return(poolParent.getRealAttribute(attName, null, 0)); } VJDFAttributeMap vm = vPartLocal == null ? null : new VJDFAttributeMap(vPartLocal); JDFResource linkRoot = poolParent.getLinkRoot(); if (linkRoot != null && vm != null) { SupportClass.SetSupport <string> @set = linkRoot.getPartIDKeys().getSet(); @set.Add(AttributeName.CONDITION); // retain good / waste vm.reduceMap(@set); } if (vm == null) { vm = new VJDFAttributeMap(); vm.Add((JDFAttributeMap)null); } double dd = 0; JDFAmountPool ap = poolParent.getAmountPool(); if (ap == null) { return(poolParent.getRealAttribute(attName, null, 0.0)); } VElement vParts = ap.getChildElementVector(ElementName.PARTAMOUNT, null); if (vParts.IsEmpty()) { return(poolParent.getRealAttribute(attName, null, 0.0)); } bool isWaste = vPartLocal != null && vPartLocal.subMap(new JDFAttributeMap(AttributeName.CONDITION, "Waste")); if (!isWaste && (vPartLocal == null || !vPartLocal.subMap(new JDFAttributeMap(AttributeName.CONDITION, "*")))) { vPartLocal = new VJDFAttributeMap(vPartLocal); vPartLocal.Add(new JDFAttributeMap(AttributeName.CONDITION, "Good")); } for (int j = 0; j < vParts.Count; j++) { JDFPartAmount pa = (JDFPartAmount)vParts[j]; VJDFAttributeMap partMapVector = pa.getPartMapVector(); if (isWaste) { bool hasCondition = partMapVector.subMap(new JDFAttributeMap(AttributeName.CONDITION, "*")); if (!hasCondition) { continue; } } if (!partMapVector.overlapsMap(vm)) { continue; } string ret = null; ret = pa.getAttribute(attName, null, null); if (ret == null) { ret = poolParent.getAttribute(attName, null, null); } dd += StringUtil.parseDouble(ret, 0.0); } return(dd); }