public override BaseElement Clone() { StringDataObject clone = new StringDataObject { Values = this }; return(clone); }
/// <summary> /// Searching function /// </summary> /// <param name="text">Input strings.</param> /// <param name="playBackSpeed">Alghorithm speed.</param> /// <returns>New input string instance with async changed border and prefix.</returns> public StringDataObject BoyerMooreMatch(StringDataObject text, int playBackSpeed) { _text = text; Task.Factory.StartNew(() => { //Visualize _text.CurrentStep = 0; //Algorithm main branch Prepare(); /* Searching */ var index = 0; while (index <= _textLength - _patternLength) { //Algorithm main branch int unmatched = _patternLength - 1; //Visualize _text.CurrentChar = unmatched + index + _patternLength + 1; _text.MainString.ElementAt(unmatched + index + _patternLength + 1).IsBorder = true; //Algorithm main branch while (unmatched >= 0 && _pattern[unmatched] == _mainString[unmatched + index]) { //Visualize SetStepBorder(unmatched, index); //Algorithm main branch --unmatched; //Progress bar _text.CurrentStep = index + (_patternLength - unmatched) + 1; Thread.Sleep(playBackSpeed * 100); } if (unmatched < 0) { //Visualize ++_text.NumberOfOccurrences; //Algorithm main branch index += _goodSuffixShift[0]; } else { //Algorithm main branch _text.MainString.ElementAt(unmatched + index + _patternLength + 1).Prefix = 0; //Visualize Thread.Sleep(playBackSpeed * 100); var startIndex = index + _patternLength + unmatched; ClearBorder(startIndex, startIndex + (_patternLength - unmatched) + 1); //Algorithm main branch index += Math.Max(_goodSuffixShift[unmatched], _badCharacterShift[_mainString[unmatched + index]] - _patternLength + 1 + unmatched); } //Visualize ClearBorder(0, _patternLength); //Progress bar _text.CurrentStep = index + _patternLength + 1; } //Visualize _text.CurrentStep = _text.MaximumProgressBar; OnAlgorythmFinished(); }); return(_text); }
protected internal override BaseElement ConvertXMLToElement(XMLStreamReader xtr, BpmnModel model) { ValuedDataObject dataObject = null; ItemDefinition itemSubjectRef = new ItemDefinition(); string structureRef = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_DATA_ITEM_REF); if (!string.IsNullOrWhiteSpace(structureRef) && structureRef.Contains(":")) { string dataType = structureRef.Substring(structureRef.IndexOf(':') + 1); if (dataType.Equals("string")) { dataObject = new StringDataObject(); } else if (dataType.Equals("int")) { dataObject = new IntegerDataObject(); } else if (dataType.Equals("long")) { dataObject = new LongDataObject(); } else if (dataType.Equals("double")) { dataObject = new DoubleDataObject(); } else if (dataType.Equals("boolean")) { dataObject = new BooleanDataObject(); } else if (dataType.Equals("datetime")) { dataObject = new DateDataObject(); } else { logger.LogError($"Error converting {xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_DATA_NAME)}, invalid data type: {dataType}"); } } else { // use String as default type dataObject = new StringDataObject(); structureRef = "xsd:string"; } if (dataObject != null) { dataObject.Id = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_DATA_ID); dataObject.Name = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_DATA_NAME); BpmnXMLUtil.AddXMLLocation(dataObject, xtr); itemSubjectRef.StructureRef = structureRef; dataObject.ItemSubjectRef = itemSubjectRef; ParseChildElements(XMLElementName, dataObject, model, xtr); dataObject.ExtensionElements.TryGetValue("value", out IList <ExtensionElement> valuesElement); if (valuesElement != null && valuesElement.Count > 0) { ExtensionElement valueElement = valuesElement[0]; if (!string.IsNullOrWhiteSpace(valueElement.ElementText)) { if (dataObject is DateDataObject) { try { dataObject.Value = DateTime.Parse(valueElement.ElementText, new DateTimeFormatInfo() { FullDateTimePattern = sdf }); } catch (Exception e) { logger.LogError(e, $"Error converting {dataObject.Name} \r\n {e.Message}"); } } else { dataObject.Value = valueElement.ElementText; } } // remove value element dataObject.ExtensionElements.Remove("value"); } } return(dataObject); }
/// <summary> /// Searching function /// </summary> /// <param name="text">Input strings.</param> /// <param name="playBackSpeed">Alghorithm speed.</param> /// <returns>New input string instance with async changed border and prefix.</returns> public StringDataObject KmpMatch(StringDataObject text, int playBackSpeed) { _text = text; Task.Factory.StartNew(() => { _text.CurrentStep = 0; var mainString = new string(_text.MainString .Select(x => x.Char) .ToArray <char>()); //Initialize var n = mainString.Length; //Algorythm for (var i = 1; i < n; i++) { //Algorithm main branch _text.CurrentChar = (i < mainString.IndexOf('@')) ? mainString.IndexOf('@') + 1 : i; var j = _text.MainString.ElementAt(i - 1).Prefix; //Vizualize var prevJ = j; SetStepBorder(i, j); //Algorithm main branch while ((j > 0) && (mainString[i] != mainString[j])) { //Vizualize _text.MainString.ElementAt(j).IsBorder = false; //Decrement substring index j = _text.MainString.ElementAt(j - 1).Prefix; //Vizualize _text.MainString.ElementAt(j).IsBorder = true; Thread.Sleep(playBackSpeed * 100); } //Vizualize if (prevJ.Equals(j)) { Thread.Sleep(playBackSpeed * 100); } //Vizualize if (i == n - 1 || mainString[i] != mainString[j]) { if (prevJ != mainString.IndexOf('@')) { ClearBorder(i - prevJ, i + prevJ); } ClearBorder(i, i + j + 1); } //Algorithm main branch if (mainString[i] == mainString[j]) { //Increment substring index ++j; //Vizualize _text.MainString.ElementAt(j - 1).IsBorder = false; } //Algorithm main branch _text.MainString.ElementAt(i).Prefix = j; //Vizualize _text.NumberOfOccurrences += (j == mainString.IndexOf('@')) ? 1 : 0; _text.CurrentStep = i; } //Vizualize ClearBorder(0, mainString.IndexOf('@') + 1); //Progress bar _text.CurrentStep = _text.MaximumProgressBar; OnAlgorythmFinished(); }); return(_text); }