/// /// <summary> * fitsValueDurationList - tests, if the duration of the defined /// * <code>rangelist</code> value matchest the ValueDurationList, specified /// * for this State /// * </summary> /// * <param name="rangelist"> /// * range list to test </param> /// * <param name="valuelist"> /// * switches between AllowedValueList and PresentValueList </param> /// * <returns> boolean - true, if the duration of the defined rangelist is in /// * <code>valueList</code> or if ValueDurationList is not specified </returns> /// private bool fitsValueDurationList(JDFDateTimeRangeList rangelist, EnumFitsValue valuelist) { JDFDurationRangeList list; if (valuelist.Equals(EnumFitsValue.Allowed)) { list = getAllowedValueDurationList(); } else { list = getPresentValueDurationList(); } if (list == null) { return(true); } int siz = rangelist.Count; for (int i = 0; i < siz; i++) { JDFDateTimeRange range = (JDFDateTimeRange)rangelist[i]; int duration = (int)((range.Right.TimeInMillis - range.Left.TimeInMillis) / 1000); JDFDuration d = new JDFDuration(); d.setDuration(duration); if (!list.inRange(d)) { return(false); } } return(true); }
/// /// <summary> * Construct a JDFDurationRange from a string /// * </summary> /// * <exception cref="FormatException"> - if the String has not a valid format </exception> /// public JDFDurationRange(string s) { string[] strArray = s.Split("~".ToCharArray()); if (strArray.Length <= 0 || strArray.Length > 2) { throw new FormatException("JDFDurationRange illegal string: " + s); } try { // the min and the max values are equal if (strArray.Length == 1) { m_left = new JDFDuration(strArray[0].Trim()); m_right = new JDFDuration(strArray[0].Trim()); } // two different values else { m_left = new JDFDuration(strArray[0].Trim()); m_right = new JDFDuration(strArray[1].Trim()); } } catch (FormatException) { throw new FormatException("JDFDurationRange illegal string: " + s); } }
public void testNegativeDuration() { JDFDuration d = new JDFDuration(" -PT5M "); Assert.AreEqual("-PT5M", d.getDurationISO()); try { new JDFDuration("--PT5M90.95S"); Assert.Fail("bad duration string"); } catch (Exception) { // nop } d = new JDFDuration("-P3M"); Assert.AreEqual("-P3M", d.getDurationISO()); Assert.AreEqual(-3 * 30 * 24 * 60 * 60, d.Duration); d = new JDFDuration("-P3MT4M"); Assert.AreEqual("-P3MT4M", d.getDurationISO()); Assert.AreEqual(-3 * 30 * 24 * 60 * 60 - 4 * 60, d.Duration); d = new JDFDuration("-P13M"); Assert.AreEqual("-P1Y1M", d.getDurationISO()); d = new JDFDuration("-P365D"); Assert.AreEqual("-P1Y", d.getDurationISO()); d = new JDFDuration("-P395D"); Assert.AreEqual("-P1Y1M", d.getDurationISO()); d = new JDFDuration("-PT3600S"); Assert.AreEqual("-PT1H", d.getDurationISO()); Assert.AreEqual("-PT0.95S", new JDFDuration("-PT0.95S").getDurationISO()); Assert.AreEqual("-PT5M30.45S", new JDFDuration("-PT5M30.45S").getDurationISO()); Assert.AreEqual("-PT6M30.95S", new JDFDuration("-PT5M90.95S").getDurationISO()); }
public void testAddSeconds() { JDFDuration duration = new JDFDuration(); Assert.AreEqual(5.234, duration.addSeconds(5.234), 0.0001); Assert.AreEqual("PT5.234S", duration.getDurationISO()); }
/// /// <summary> * inRange - returns true if 'x' is within the range defined by 'this' /// * </summary> /// * <param name="x"> JDFDuration that is to be compared with 'this' </param> /// * <returns> boolean - true if 'x' is within the range defined by 'this' </returns> /// public virtual bool inRange(JDFDuration x) { JDFDuration min = this.LowerValue; JDFDuration max = this.UpperValue; return((x.isLonger(min) || x.Equals(min)) && (x.isShorter(max) || x.Equals(max))); }
public void testJDFDateTimeRangeJDFDateTimeRange() { try { JDFDateTimeRange r = new JDFDateTimeRange(new JDFDate("2004-12-01T09:30:00Z"), new JDFDate("2004-12-01T09:35:00Z")); JDFDateTimeRange test_r = new JDFDateTimeRange("2004-12-01T09:30:00Z ~ 2004-12-01T09:35:00Z"); Assert.IsTrue(r.Equals(test_r), "Bad Constructor: " + r.ToString()); int duration = (int)((test_r.Right.TimeInMillis - test_r.Left.TimeInMillis) / 1000); JDFDuration d = new JDFDuration(); d.setDuration(duration); // System.out.println(duration); JDFDateTimeRange r2 = new JDFDateTimeRange(new JDFDate("2004-12-01T09:30:00Z")); JDFDateTimeRange r3 = new JDFDateTimeRange(r2); r3.Right = r.Right; Assert.IsTrue(r3.Equals(r), "Bad Constructor: " + r3.ToString()); } catch (FormatException dfe) { Console.WriteLine(dfe.ToString()); } }
/// /// <summary> * isPartOfRange - is range 'r' within this range? /// * </summary> /// * <param name="r"> the range to test /// * </param> /// * <returns> boolean - true if range 'r' is within this range, else false </returns> /// public override bool isPartOfRange(JDFRange ra) { JDFDurationRange r = (JDFDurationRange)ra; JDFDuration min = this.LowerValue; JDFDuration r_min = r.LowerValue; JDFDuration max = this.UpperValue; JDFDuration r_max = r.UpperValue; return((r_min.isLonger(min) || r_min.Equals(min)) && (r_max.isShorter(max) || r_max.Equals(max))); }
public void testSetDuration() { JDFDuration duration = new JDFDuration(); duration.setDuration(65); Assert.AreEqual("PT1M5S", duration.getDurationISO()); duration.setDuration(60 * 60 * 24 * 63); Assert.AreEqual("P2M3D", duration.getDurationISO()); duration.addSeconds(65.5); Assert.AreEqual("P2M3DT1M5.5S", duration.getDurationISO()); duration.addSeconds(60 * 60 * 3); Assert.AreEqual("P2M3DT3H1M5.5S", duration.getDurationISO()); duration.addSeconds(60 * 60 * 3); Assert.AreEqual("P2M3DT6H1M5.5S", duration.getDurationISO()); }
// **************************************** Methods // ********************************************* /// /// <summary> * inRange - returns true if the given JDFDuration value is in one of the ranges of the range list /// * </summary> /// * <param name="x"> the given JDFDuration (duration) value to compare /// * </param> /// * <returns> boolean - true if in range otherwise false </returns> /// public virtual bool inRange(JDFDuration x) { int sz = rangeList.Count; for (int i = 0; i < sz; i++) { JDFDurationRange r = (JDFDurationRange)rangeList[i]; if (r.inRange(x)) { return(true); } } return(false); }
/// /// <summary> * (20) get JDFDuration attribute MinCleanup </summary> /// * <returns> JDFDuration the value of the attribute, null if a the /// * attribute value is not a valid to create a JDFDuration </returns> /// public virtual JDFDuration getMinCleanup() { string strAttrName = ""; JDFDuration nPlaceHolder = null; strAttrName = getAttribute(AttributeName.MINCLEANUP, null, JDFConstants.EMPTYSTRING); try { nPlaceHolder = new JDFDuration(strAttrName); } catch (FormatException) { return(null); } return(nPlaceHolder); }
/// /// <summary> * (20) get JDFDuration attribute AverageSetup </summary> /// * <returns> JDFDuration the value of the attribute, null if a the /// * attribute value is not a valid to create a JDFDuration </returns> /// public virtual JDFDuration getAverageSetup() { string strAttrName = ""; JDFDuration nPlaceHolder = null; strAttrName = getAttribute(AttributeName.AVERAGESETUP, null, JDFConstants.EMPTYSTRING); try { nPlaceHolder = new JDFDuration(strAttrName); } catch (FormatException) { return(null); } return(nPlaceHolder); }
/// /// <summary> * (20) get JDFDuration attribute RestTime </summary> /// * <returns> JDFDuration the value of the attribute, null if a the /// * attribute value is not a valid to create a JDFDuration </returns> /// public virtual JDFDuration getRestTime() { string strAttrName = ""; JDFDuration nPlaceHolder = null; strAttrName = getAttribute(AttributeName.RESTTIME, null, JDFConstants.EMPTYSTRING); try { nPlaceHolder = new JDFDuration(strAttrName); } catch (FormatException) { return(null); } return(nPlaceHolder); }
/// /// <summary> * (20) get JDFDuration attribute HourCounter </summary> /// * <returns> JDFDuration the value of the attribute, null if a the /// * attribute value is not a valid to create a JDFDuration </returns> /// public virtual JDFDuration getHourCounter() { string strAttrName = ""; JDFDuration nPlaceHolder = null; strAttrName = getAttribute(AttributeName.HOURCOUNTER, null, JDFConstants.EMPTYSTRING); try { nPlaceHolder = new JDFDuration(strAttrName); } catch (FormatException) { return(null); } return(nPlaceHolder); }
/// /// <summary> * (20) get JDFDuration attribute ExtraDuration </summary> /// * <returns> JDFDuration the value of the attribute, null if a the /// * attribute value is not a valid to create a JDFDuration </returns> /// public virtual JDFDuration getExtraDuration() { string strAttrName = ""; JDFDuration nPlaceHolder = null; strAttrName = getAttribute(AttributeName.EXTRADURATION, null, JDFConstants.EMPTYSTRING); try { nPlaceHolder = new JDFDuration(strAttrName); } catch (FormatException) { return(null); } return(nPlaceHolder); }
/// /// <summary> * isUniqueOrdered - tests if 'this' is UniqueOrdered RangeList /// * </summary> /// * <returns> boolean - true if 'this' is UniqueOrdered RangeList </returns> /// public override bool isUniqueOrdered() { int siz = rangeList.Count; if (siz == 0) { return(false); // attempt to operate on a null element } List <JDFDuration> v = new List <JDFDuration>(); // vector of ranges for (int i = 0; i < siz; i++) { JDFDurationRange r = (JDFDurationRange)rangeList[i]; v.Add(r.Left); if (!r.Left.Equals(r.Right)) { v.Add(r.Right); } } int n = v.Count - 1; if (n == 0) { return(true); // single value } JDFDuration first = v[0]; JDFDuration last = v[n]; if (first.Equals(last)) { return(false); } for (int j = 0; j < n; j++) { JDFDuration @value = v[j]; JDFDuration nextvalue = v[j + 1]; if (((first.isShorter(last) && @value.isShorter(nextvalue)) || (first.isLonger(last) && @value.isLonger(nextvalue))) == false) { return(false); } } return(true); }
public virtual void testDuration() { JDFDoc d = new JDFDoc(ElementName.JDF); JDFNode n = d.getJDFRoot(); n.setType("ConventionalPrinting", true); JDFNodeInfo ni = n.getCreateNodeInfo(); JDFDuration duration = new JDFDuration("PT1H20M30S"); ni.setTotalDuration(duration); Assert.AreEqual(duration, ni.getTotalDuration()); try { ni.setCleanupDuration(new JDFDuration("PS1L20M30S")); Assert.Fail("bad duration"); } catch (System.Exception) { // nop } }
public void testJDFDurationString() { JDFDuration d = new JDFDuration(" PT5M "); Assert.AreEqual("PT5M", d.getDurationISO()); try { new JDFDuration("PT5M90.95aS"); Assert.Fail("bad duration string"); } catch (Exception) { // nop } try { new JDFDuration("PTM90.95aS"); Assert.Fail("bad duration string"); } catch (Exception) { // nop } d = new JDFDuration("P3M"); Assert.AreEqual("P3M", d.getDurationISO()); Assert.AreEqual(3 * 30 * 24 * 60 * 60, d.Duration); d = new JDFDuration("P3MT4M"); Assert.AreEqual("P3MT4M", d.getDurationISO()); Assert.AreEqual(3 * 30 * 24 * 60 * 60 + 4 * 60, d.Duration); d = new JDFDuration("P13M"); Assert.AreEqual("P1Y1M", d.getDurationISO()); d = new JDFDuration("P365D"); Assert.AreEqual("P1Y", d.getDurationISO()); d = new JDFDuration("P395D"); Assert.AreEqual("P1Y1M", d.getDurationISO()); d = new JDFDuration("PT3600S"); Assert.AreEqual("PT1H", d.getDurationISO()); }
// // * // Element getter / Setter // // // * // FitsValue Methods // // // * (non-Javadoc) // * // * @see // * org.cip4.jdflib.resource.devicecapability.JDFAbstractState#addValue(java // * .lang.String, org.cip4.jdflib.datatypes.JDFBaseDataTypes.EnumFitsValue) // public override void addValue(string @value, EnumFitsValue testlists) { if (fitsValue(@value, testlists)) { return; } JDFDuration duration; try { duration = new JDFDuration(@value); } catch (FormatException) { return; // nop for bad values } if (testlists == null || EnumFitsValue.Allowed.Equals(testlists)) { JDFDurationRangeList list = getAllowedValueList(); if (list == null) { list = new JDFDurationRangeList(); } list.Append(duration); setAllowedValueList(list); } if (testlists == null || EnumFitsValue.Present.Equals(testlists)) { JDFDurationRangeList list = getPresentValueList(); if (list == null || !hasAttribute(AttributeName.PRESENTVALUELIST)) { list = new JDFDurationRangeList(); } list.Append(duration); setPresentValueList(list); } }
/// /// <summary> * fitsValueDurationList - tests, if the duration of the defined 'rangelist' /// * value matches ValueDurationList, specified for this State /// * </summary> /// * <param name="rangelist"> /// * range list to test </param> /// * <returns> boolean - true, if the duration of the defined /// * <code>rangelist</code> is in the ValueList or if /// * ValueDurationList is not specified </returns> /// private bool fitsValueDurationList(JDFDateTimeRangeList rangelist) { if (hasAttribute(AttributeName.VALUEDURATIONLIST)) { JDFDurationRangeList list = getValueDurationList(); int siz = rangelist.Count; for (int i = 0; i < siz; i++) { JDFDateTimeRange range = (JDFDateTimeRange)rangelist[i]; int duration = (int)((range.Right.TimeInMillis - range.Left.TimeInMillis) / 1000); JDFDuration d = new JDFDuration(); d.setDuration(duration); if (!list.inRange(d)) { return(false); } } return(true); } return(true); }
public void testJDFDuration() { JDFDuration d = new JDFDuration("PT5M"); JDFDuration d1 = new JDFDuration("PT50M"); try { new JDFDuration("P0T5M"); Assert.Fail("invalid duration String"); } catch (FormatException) { // } try { new JDFDuration("PT5MS"); Assert.Fail("invalid duration String"); } catch (FormatException) { // } JDFDuration p1 = new JDFDuration("P1Y2M3DT50M"); JDFDuration p11 = new JDFDuration("P01Y02M03DT50M"); Assert.AreEqual(p1, p11); JDFDuration p2 = new JDFDuration("P01Y02M03D"); JDFDuration p3 = new JDFDuration("P1Y2M3DT10H30M"); Assert.IsTrue(d.Duration == 300, "Bad Constructor d"); Assert.IsTrue(d1.Duration == 3000, "Bad Constructor d1"); Assert.IsTrue(p1.getDurationISO().Equals("P1Y2M3DT50M"), "Bad Constructor p1"); Assert.IsTrue(p2.getDurationISO().Equals("P1Y2M3D"), "Bad Constructor p2"); Assert.IsTrue(p3.getDurationISO().Equals("P1Y2M3DT10H30M"), "Bad Constructor p2"); }
public virtual void setDefaultValue(JDFDuration @value) { setAttribute(AttributeName.DEFAULTVALUE, @value.getDurationISO(), null); }
// // * // Attribute getter/ Setter // public virtual void setCurrentValue(JDFDuration @value) { setAttribute(AttributeName.CURRENTVALUE, @value.getDurationISO(), null); }
// --------------------------------------------------------------------- // Methods for Attribute MinDuration // --------------------------------------------------------------------- /// /// <summary> * (36) set attribute MinDuration </summary> /// * <param name="value">: the value to set the attribute to </param> /// public virtual void setMinDuration(JDFDuration @value) { setAttribute(AttributeName.MINDURATION, @value, null); }
/// /// <summary> * Initialization </summary> /// protected internal virtual void init(JDFDuration xmin, JDFDuration xmax) { Left = xmin; Right = xmax; }
/// /// <summary> * Constructor - creates a Duration range defined by xmin to xmax </summary> /// public JDFDurationRange(JDFDuration xmin, JDFDuration xmax) { init(xmin, xmax); }
// --------------------------------------------------------------------- // Methods for Attribute MinSetup // --------------------------------------------------------------------- /// /// <summary> * (36) set attribute MinSetup </summary> /// * <param name="value">: the value to set the attribute to </param> /// public virtual void setMinSetup(JDFDuration @value) { setAttribute(AttributeName.MINSETUP, @value, null); }
// --------------------------------------------------------------------- // Methods for Attribute RestTime // --------------------------------------------------------------------- /// /// <summary> * (36) set attribute RestTime </summary> /// * <param name="value">: the value to set the attribute to </param> /// public virtual void setRestTime(JDFDuration @value) { setAttribute(AttributeName.RESTTIME, @value, null); }
// --------------------------------------------------------------------- // Methods for Attribute ExtraDuration // --------------------------------------------------------------------- /// /// <summary> * (36) set attribute ExtraDuration </summary> /// * <param name="value">: the value to set the attribute to </param> /// public virtual void setExtraDuration(JDFDuration @value) { setAttribute(AttributeName.EXTRADURATION, @value, null); }
/// /// <summary> * Constructor - creates a Duration range defined by x </summary> /// public JDFDurationRange(JDFDuration x) { init(x, x); }
/// /// <summary> * set the default values specified in this in element /// * </summary> /// * <param name="element"> /// * the element to set the defaults on </param> /// * <returns> true if successful </returns> /// public virtual bool setDefaultsFromCaps(KElement element, bool bAll) { string def = getAttribute(AttributeName.DEFAULTVALUE, null, null); if (!bAll && def == null) { return(false); } if (def == null) { def = getAttribute(AttributeName.CURRENTVALUE, null, null); } if (def == null) { def = getAttribute(AttributeName.ALLOWEDVALUELIST, null, null); if (def != null && (def.IndexOf("~") >= 0 || def.IndexOf(" ") >= 0)) // allowedvaluelist // is // a // list // or // range { string lt = getListType().getName(); if (!lt.EndsWith("List") && def.IndexOf(" ") >= 0) { def = StringUtil.token(def, 0, " "); } else if (lt.IndexOf("Range") < 0 && def.IndexOf("~") >= 0) { def = null; } } if (def == null) { def = getXPathAttribute("Value/@AllowedValue", null); } } if (def == null) { if ((this is JDFIntegerState) || (this is JDFNumberState)) { def = "1"; } else if (this is JDFXYPairState) { def = "1 1"; } else if (this is JDFBooleanState) { def = "true"; } else if (this is JDFMatrixState) { def = JDFMatrix.unitMatrix.ToString(); } else if (this is JDFShapeState) { def = "1 2 3"; } else if (this is JDFDateTimeState) { def = new JDFDate().DateTimeISO; } else if (this is JDFDurationState) { def = new JDFDuration(42).getDurationISO(); } else { def = "some_value"; // TODO add better type dependent value // generator } } object theValue = getMatchingObjectInNode(element); if (theValue != null) { return(false); } string nam = getName(); string nsURI = getDevNS(); if (nsURI.Equals(JDFElement.getSchemaURL())) { nsURI = null; } if (nsURI != null) { string prefix = KElement.xmlnsPrefix(nam); if (prefix == null) { nam = StringUtil.token(nsURI, -1, "/") + ":" + nam; } } if (getListType().Equals(EnumListType.Span)) { JDFIntentResource ir = (JDFIntentResource)element; JDFSpanBase span = ir.appendSpan(nam, null); span.setAttribute(AttributeName.PREFERRED, def); } else // some attribute... { element.setAttribute(nam, def, nsURI); } return(true); }