When I print array same object occurs in array please check.When I print obj then obj.dataArray contains same temp object occurs - jackson

Please check if I print obj then in data array same elements gets inserted twice instead of different. If n =2 then the first element gets pushed twice.
genLLEles(n, orgObj, homeSecObj, defaultElementObj, previousElements, socket) {
let that = this;
let arr = [];
let obj = {
dataArray: [],
socketId: socket.USER_ID,
requestId: "/sync#" + socket.id + socket.USER_ID + "#" + new Date().getTime(),
moduleName: "ORG",
action: "INSERT",
userId: socket.USER_ID
};
console.log("\n\ should be oce");
for (let i = 0; i < n; i++) { //n defines count of how many elements to be created
let temp = defaultElementObj; //selected object to insert
let _id = homeSecObj.KEY_VAL + "_TSK:" + defaultElementObj.SUB_KEY_TYPE + "_" + Date.now() + "_" + Math.floor(Math.random() * (10000 - 1)) + 1;
console.log(obj.dataArray.length);
if (obj.dataArray.length == 0) {
temp.CML_PREVIOUS_ID = previousElements.length <= 0 ? "-1" : that.getPreObj(previousElements).KEY_VAL;
temp.CML_NEXT_ID = "1";
temp.ORG_ID = orgObj.ORG_ID;
temp.DEPT_ID = orgObj.DEPT_ID;
temp.KEY_VAL = _id;
temp.CML_ID = _id;
temp.CML_REF_ID = homeSecObj.KEY_VAL;
temp.ACTIVE_STATUS = "1";
temp.CML_IMAGE_PATH = "";
temp.SYNC_PENDING_STATUS = "1";
} else {
obj.dataArray[obj.dataArray.length - 1].CML_NEXT_ID = _id;
console.log("HERE", obj.dataArray[obj.dataArray.length - 1]);
temp.CML_PREVIOUS_ID = obj.dataArray.length < 0 ? "-1" : obj.dataArray[obj.dataArray.length - 1].KEY_VAL;
temp.CML_NEXT_ID = "1";
temp.ORG_ID = orgObj.ORG_ID;
temp.DEPT_ID = orgObj.DEPT_ID;
temp.KEY_VAL = _id;
temp.CML_ID = _id;
temp.CML_REF_ID = homeSecObj.KEY_VAL;
temp.ACTIVE_STATUS = "1";
temp.CML_IMAGE_PATH = "";
temp.SYNC_PENDING_STATUS = "1";
}
obj.dataArray.push(temp);
}
console.log("\n\genLLEles ==> ", obj, "\n\n");
/*return obj;*/
}

from the above code, the values in both the if and else are coming from same parameters. So you are inserting the same values multiple times into the dataArray.

Related

QMSClient.SaveCALConfiguration doesn't seem to be working

Can anyone help me understand why this below would not remove named cals. It seems to work fine until the very last line where it does the save. I don't get any exceptions or error messages.
When i look in QV Management console under System>Licenses i still see the ones that were supposed to be removed (Named user CALs)
Client Build Number: 11.20.13314.0
QMSClient Client;
string QMS = "http://localhost:4799/QMS/Service";
Client = new QMSClient("BasicHttpBinding_IQMS", QMS);
string key = Client.GetTimeLimitedServiceKey();
ServiceKeyClientMessageInspector.ServiceKey = key;
List<ServiceInfo> MyQVS = Client.GetServices(ServiceTypes.QlikViewServer);
Client.ClearQVSCache(QVSCacheObjects.All);
CALConfiguration myCALs = Client.GetCALConfiguration(MyQVS[0].ID, CALConfigurationScope.NamedCALs);
List<AssignedNamedCAL> currentNamedCALs = myCALs.NamedCALs.AssignedCALs.ToList();
List<int> indexToRemove = new List<int>();
int cnt = 1;
for (int i = 0; i < currentNamedCALs.Count; i++)
{
if ((currentNamedCALs[i].QuarantinedUntil < System.DateTime.Now)
&& (currentNamedCALs[i].LastUsed < DateTime.Now.AddDays(daysFromToday)))
{
Console.WriteLine("[" + cnt + "] " + currentNamedCALs[i].UserName +
"; Last used: " + currentNamedCALs[i].LastUsed);
indexToRemove.Add(i);
cnt++;
}
}
Console.WriteLine();
for (int i = indexToRemove.Count; i > 0; i--)
{
if (currentNamedCALs[indexToRemove[i - 1]] != null)
{
currentNamedCALs.RemoveAt(indexToRemove[i - 1]);
}
}
Console.WriteLine("\nDone");
myCALs.NamedCALs.AssignedCALs = currentNamedCALs;
Client.SaveCALConfiguration(myCALs);

Why result of GetPageLabels is different from the Adobe Acrobat

I edit page number of pdf in Adobe Acrobat X Pro.
Test PDF
result:
1-FrontCover
2-FrontFold
3-i
4-ii
5-iii
6-1
7-2
8-3
9-4
10-5
11-BackFold
12-BackCover
But this result of GetPageLabels is wrong
page number:
0-FrontCover1
1-FrontFold1
2-FrontFoldi
3-FrontFoldii
4-FrontFoldiii
5-FrontFold1
6-FrontFold2
7-FrontFold3
8-FrontFold4
9-FrontFold5
10-BackFold1
11-BackCover1
C# Code:
objLabels = PdfPageLabels.GetPageLabels(objReader);
TextBox1.Text += "page number:" + Environment.NewLine;
if (objLabels != null) {
for (i = 0; i <= objLabels.Length - 1; i++) {
TextBox1.Text += i + "-" + objLabels(i) + Environment.NewLine;
}
}
How to get the correct result like Adobe Acrobat X Pro?
There is a small bug in PdfPageLabels.GetPageLabels(PdfReader). When encountering a new page label dictionary without a P (prefix) entry, it does not reset the current prefix value:
int pagecount = 1;
String prefix = "";
char type = 'D';
for (int i = 0; i < n; i++) {
if (numberTree.ContainsKey(i)) {
PdfDictionary d = (PdfDictionary)PdfReader.GetPdfObjectRelease(numberTree[i]);
if (d.Contains(PdfName.ST)) {
pagecount = ((PdfNumber)d.Get(PdfName.ST)).IntValue;
}
else {
pagecount = 1;
}
if (d.Contains(PdfName.P)) {
prefix = ((PdfString)d.Get(PdfName.P)).ToUnicodeString();
}
if (d.Contains(PdfName.S)) {
type = ((PdfName)d.Get(PdfName.S)).ToString()[1];
}
else {
type = 'e';
}
}
...
}
You can fix this by adding the following else clause to the if in question:
if (d.Contains(PdfName.P)) {
prefix = ((PdfString)d.Get(PdfName.P)).ToUnicodeString();
}
else
{
prefix = "";
}
Whith this change I get I get
page number:
0 - FrontCover
1 - FrontFold
2 - i
3 - ii
4 - iii
5 - 1
6 - 2
7 - 3
8 - 4
9 - 5
10 - BackFold
11 - BackCover
PS: The same issue is present in the Java iText version, tested in ReadPageLabels.java.
Thank you for helping to solve my problem,
Here is my complete program.
public string[] ReadPageLabel(PdfReader objReader, int intPageCount)
{
PdfDictionary objDictionary ;
Dictionary<int, PdfObject> objTree ;
string[] arrLabels ;
int i ;
char chrLabelKind ;
string strLabelPrefix ;
int intLableNumber ;
//PdfPageLabels is wrong
//arrLabels = PdfPageLabels.GetPageLabels(objReader)
arrLabels = new string[intPageCount];
if (objReader.Catalog.Get(PdfName.PAGELABELS) != null) {
objTree = PdfNumberTree.ReadTree(PdfReader.GetPdfObjectRelease(objReader.Catalog.Get(PdfName.PAGELABELS)));
chrLabelKind = 'D';
strLabelPrefix = "";
intLableNumber = 1;
for (i = 0; i <= intPageCount - 1; i++) {
if (objTree.ContainsKey(i)) { //if reset page number
objDictionary = PdfReader.GetPdfObjectRelease(objTree[i]);
//PdfName.S:Number Kind
if (objDictionary.Contains(PdfName.S)) {
chrLabelKind = ((PdfName)objDictionary.Get(PdfName.S)).ToString()(1);
//PdfName.S:/R,/r,/A,/a,/e,/D,ToString()(1)get alphabet of Index=1
} else {
chrLabelKind = 'e';
}
//PdfName.P:Prefix
if (objDictionary.Contains(PdfName.P)) {
strLabelPrefix = ((PdfString)objDictionary.Get(PdfName.P)).ToUnicodeString();
} else {
strLabelPrefix = "";
}
//PdfName.ST:Start Number
if (objDictionary.Contains(PdfName.ST)) {
intLableNumber = ((PdfNumber)objDictionary.Get(PdfName.ST)).IntValue;
} else {
intLableNumber = 1;
}
}
switch (chrLabelKind) {
case 'R':
//I,II,III
arrLabels[i] = strLabelPrefix + factories.RomanNumberFactory.GetUpperCaseString(intLableNumber);
break;
case 'r':
//i,ii,iii
arrLabels[i] = strLabelPrefix + factories.RomanNumberFactory.GetLowerCaseString(intLableNumber);
break;
case 'A':
//A,B,C
arrLabels[i] = strLabelPrefix + factories.RomanAlphabetFactory.GetUpperCaseString(intLableNumber);
break;
case 'a':
//a,b,c
arrLabels[i] = strLabelPrefix + factories.RomanAlphabetFactory.GetLowerCaseString(intLableNumber);
break;
case 'e':
//no number kind
arrLabels[i] = strLabelPrefix;
break;
default:
//1,2,3
arrLabels[i] = strLabelPrefix + intLableNumber;
break;
}
intLableNumber += 1;
}
} else {
for (i = 0; i <= intPageCount - 1; i++) {
arrLabels[i] = i + 1;
}
}
return arrLabels;
}

How to get modified values from dojo table

I have a Dojo table with list of key value pairs. Both fields are editable, once a value is modified i am doing:
var items = grid.selection.getSelected();
However, the modified value is not picked up only the old value is picked.
I tried the following:
dojo.parser.parse()
dojo.parser.instantiate([dojo.byId("tableDiv")]);
but none of them worked. Can any one sugggest a solution for this.
function getAllItems() {
var returnData = "";
//dojo.parser.parse();
//dojo.parser.instantiate([dojo.byId("tableDiv")]);
//grid._refresh();
var items = grid.selection.getSelected();
function gotItems(items, request) {
var i;
for (i = 0; i < items.length; i++) {
var item = items[i];
var paramName = grid.store.getValues(item, "paramName");
var paramValue = grid.store.getValues(item, "paramValue");
if (returnData == "") {
returnData = paramName + "&" + paramValue;
} else {
returnData = returnData + "#" + paramName + "&"
+ paramValue;
} document.getElementById("returnData").value = returnData;
document.getElementById("successFlag").value = "true";
}
}
//Called when loop fails
function fetchFailed(error, request) {
alert("Error reading table data");
}
//Fetch the data.
jsonStore.fetch({
onComplete : gotItems,
onError : fetchFailed
});
}

Reducing score in relation to countdown timer

I have a quiz written in actionscript 2. Everything is going swimmingly except that I can't figure out how to get the score to reduce by one point for every second it takes to answer the question.
So... max score is 30 points for each question and there is a 30 sec timer... and so that the quiz is more challenging I'd like it to reduce by 1 point for every second it takes to answer.
Here is my code... and thanks in advance...
Answer0Button.enabled=false; button0._visible=false;
Answer1Button.enabled=false; button1._visible=false;
Answer2Button.enabled=false; button2._visible=false;
Answer3Button.enabled=false; button3._visible=false;
Answer4Button.enabled=false; button4._visible=false;
Answer5Button.enabled=false; button5._visible=false;
function countdown() {
counter--;
countdown_txt.text = counter;
if (counter == 0) {
Answer0Button.enabled=false;
Answer1Button.enabled=false;
Answer2Button.enabled=false;
Answer3Button.enabled=false;
Answer4Button.enabled=false;
Answer5Button.enabled=false;
clearInterval(intID);
AnswerPopUp_mc.gotoAndPlay(1);
AnswerPopUp_mc.AnswerPopUp.DisplayResult.htmlText = "" + TimeIsUp + "";
}
}
// defining variables for data
var ChosenNumberOfQuestions = int(0); // Number of questions in quiz
var TotalNumberOfQuestions = int(0); // Total number of questions in XML file
var NumberOfQuestions = int(0); // min of two above
var QuestionCounter = int(0); // for dynamicaly showing questions
var CurrentQuestion = QuestionCounter + 1; // for dynamicaly showing questions
var Points = 0; // for each question
var TotalPoints = 0; // Max Points
var Score = 0; // display total score
var NumberOfCorrectAnswers = 0; // counter for questions answered correctly
var RandOrderQuestions = new Array();
var Questions = new Array();
var Images = new Array();
var CorrectAnswers = new Array();
var Answers = new Array();
var ExplanationsIfCorrect = new Array();
var ExplanationsIfNotCorrect = new Array();
var TimesForSolving = new Array();
var NumberOfPoints = new Array();
// roll over states for buttons
button0.onEnterFrame = function() {
if (mouse_over_button0) {
_root.button0.nextFrame();
} else {
_root.button0.prevFrame();
}
};
button1.onEnterFrame = function() {
if (mouse_over_button1) {
_root.button1.nextFrame();
} else {
_root.button1.prevFrame();
}
};
button2.onEnterFrame = function() {
if (mouse_over_button2) {
_root.button2.nextFrame();
} else {
_root.button2.prevFrame();
}
};
button3.onEnterFrame = function() {
if (mouse_over_button3) {
_root.button3.nextFrame();
} else {
_root.button3.prevFrame();
}
};
button4.onEnterFrame = function() {
if (mouse_over_button4) {
_root.button4.nextFrame();
} else {
_root.button4.prevFrame();
}
};
button5.onEnterFrame = function() {
if (mouse_over_button5) {
_root.button5.nextFrame();
} else {
_root.button5.prevFrame();
}
};
// Label Color
var changeColor2 = new Color(label_mc.coloredLabel);
changeColor2.setRGB(labelColor);
// Change Buttons Color
var changeColorA = new Color(button0.letterA_mc.letterA);
changeColorA.setRGB(labelColor);
var changeColorB = new Color(button1.letterB_mc.letterB);
changeColorB.setRGB(labelColor);
var changeColorC = new Color(button2.letterC_mc.letterC);
changeColorC.setRGB(labelColor);
var changeColorD = new Color(button3.letterD_mc.letterD);
changeColorD.setRGB(labelColor);
var changeColorE = new Color(button4.letterE_mc.letterE);
changeColorE.setRGB(labelColor);
var changeColorF = new Color(button5.letterF_mc.letterF);
changeColorF.setRGB(labelColor);
// Change Color of points, counter...
var changeColorCounter = new Color(countdown_txt);
changeColorCounter.setRGB(labelColor);
var changeSlashColor = new Color(slash);
changeSlashColor.setRGB(labelColor);
var changeCurrQColor = new Color(DisplayCurrQ);
changeCurrQColor.setRGB(labelColor);
var changeTotalQColor = new Color(DisplayTotalQ);
changeTotalQColor.setRGB(labelColor);
var changePointsColor = new Color(DisplayPoints);
changePointsColor.setRGB(labelColor);
var changeScoreColor = new Color(DisplayScore);
changeScoreColor.setRGB(labelColor);
// Background Color
new Color (BackGround.bg).setRGB(BackgroundColor);
new Color (FadeIn.bg1.bg).setRGB(BackgroundColor);
// loading data from XML
var xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = function () {
// Default Time for solving
DefaultTimeInSeconds = this.firstChild.attributes.DefaultTimeInSeconds;
trace ("DefaultTime: " + DefaultTimeInSeconds);
// Default Points
DefaultPoints = this.firstChild.attributes.DefaultPoints;
trace ("DefaultPoints: " + DefaultPoints);
// Default comment on answers
DefaultIfCorrectAnswer = this.firstChild.attributes.DefaultIfCorrectAnswer;
DefaultIfWrongAnswer = this.firstChild.attributes.DefaultIfWrongAnswer;
// Default if time is up
TimeIsUp = this.firstChild.attributes.TimeIsUp;
// Random order of questions or not
RandomQuestions = this.firstChild.attributes.RandomQuestions;
trace ("RandomQuestions: " + RandomQuestions);
// Number Of Questions
ChosenNumberOfQuestions = this.firstChild.attributes.NumberOfQuestions;
trace ("ChosenNumberOfQuestions: " + ChosenNumberOfQuestions);
// Counting total number of Questions in XML file
var nodes = this.firstChild.childNodes;
for (var a=0; a<nodes.length; a++){
TotalNumberOfQuestions = a+1;
}
trace ("TotalNumberOfQuestions: " + TotalNumberOfQuestions);
// Finaly - number of questions in QUIZ - min of two above
if (ChosenNumberOfQuestions < TotalNumberOfQuestions) {
NumberOfQuestions = ChosenNumberOfQuestions;
} else {
NumberOfQuestions = TotalNumberOfQuestions;
}
// Random order Questions or not
// first we populate array with question numbers
for(i=0; i<TotalNumberOfQuestions; i++){
RandOrderQuestions[i] = i;
trace(RandOrderQuestions);
}
// if we want random questions we use random sorting of number of questions
if (RandomQuestions == "TRUE") {
RandOrderQuestions.sort(function () {
return random(2) ? true : false;
});
trace(RandOrderQuestions);
}
///////////////////////////
// POPULATING FROM XML
for (var i=0; i < NumberOfQuestions; i++ )
{
// Chose the number of question from RandOrderQuestions array
var numInXML = RandOrderQuestions[i];
trace("Question number in XML: " + numInXML);
// populating questions from XML
Questions[i] = this.firstChild.childNodes[numInXML].childNodes[0].firstChild.nodeValue;
//trace(Questions);
//populating Correct Answers from XML
CorrectAnswers[i] = this.firstChild.childNodes[numInXML].childNodes[1].attributes.correctAnswer;
//trace(CorrectAnswers);
// populating options for answers from XML
var NewArray = new Array(); // temp array for answers for each question
for (var j=0; j < this.firstChild.childNodes[numInXML].childNodes[1].childNodes.length; j++ )
{
trace(i + " "+ j);
NewArray[j] = this.firstChild.childNodes[numInXML].childNodes[1].childNodes[j].firstChild.nodeValue;
//trace(NewArray);
NewArray.sort(function () {
return random(2) ? true : false;
});
}
Answers.push(NewArray); // push answers for this i question in main Answers array
//populating additional options from XML
ExplanationsIfCorrect[i] = this.firstChild.childNodes[numInXML].childNodes[2].attributes.explanationIfCorrect;
ExplanationsIfNotCorrect[i] = this.firstChild.childNodes[numInXML].childNodes[2].attributes.explanationIfNotCorrect;
TimesForSolving[i] = this.firstChild.childNodes[numInXML].childNodes[2].attributes.timeInSeconds;
NumberOfPoints[i] = this.firstChild.childNodes[numInXML].childNodes[2].attributes.points;
Images[i] = this.firstChild.childNodes[numInXML].childNodes[2].attributes.imageIfCorrect;
Images[i] = this.firstChild.childNodes[numInXML].childNodes[2].attributes.imageIfIncorrect;
}
trace("Questions: " + Questions); trace("Correct Answers: " + CorrectAnswers);
trace(NewArray);
trace(ExplanationsIfCorrect); trace(ExplanationsIfNotCorrect); trace(TimesForSolving); trace(NumberOfPoints); trace(Images);
// show first question (QuestionCounter=0)
QuestionNumber.text = "Question #" + 1;
QuestionDisplay.htmlText = Questions[QuestionCounter];
// show answers for first question (QuestionCounter=0)
if (0 < Answers[QuestionCounter].length){ Answer0Display.text = Answers[QuestionCounter][0]; Answer0Button.enabled=true; button0._visible=true;} else { button0._visible=false;}
if (1 < Answers[QuestionCounter].length){ Answer1Display.text = Answers[QuestionCounter][1]; Answer1Button.enabled=true; button1._visible=true;} else { button1._visible=false;}
if (2 < Answers[QuestionCounter].length){ Answer2Display.text = Answers[QuestionCounter][2]; Answer2Button.enabled=true; button2._visible=true;} else { button2._visible=false;}
if (3 < Answers[QuestionCounter].length){ Answer3Display.text = Answers[QuestionCounter][3]; Answer3Button.enabled=true; button3._visible=true;} else { button3._visible=false;}
if (4 < Answers[QuestionCounter].length){ Answer4Display.text = Answers[QuestionCounter][4]; Answer4Button.enabled=true; button4._visible=true;} else { button4._visible=false;}
if (5 < Answers[QuestionCounter].length){ Answer5Display.text = Answers[QuestionCounter][5]; Answer5Button.enabled=true; button5._visible=true;} else { button5._visible=false;}
// show image if defined
if (Images[QuestionCounter]){ loadMovie(Images[QuestionCounter],"imgContainer"); } else { }
// determine the number of points
if (NumberOfPoints[QuestionCounter]){ Points = NumberOfPoints[QuestionCounter] } else { Points = DefaultPoints }
// start counter
if (TimesForSolving[QuestionCounter]){
countdown_time = TimesForSolving[QuestionCounter]
} else {
countdown_time = DefaultTimeInSeconds
} // now call the function
counter = countdown_time;
countdown_txt.text = countdown_time;
clearInterval(intID);
intID = setInterval(countdown,1000);
}
I don't see where you added your scores, but I believe you can set score = counter since your counter is the time remaining.

Refactoring a method containing conditional with extremely different code blocks that are the same ;)

So I have this stinky method, the two conditional blocks do almost the exact same thing, but with radically different parameters (at least in my eyes). I want to clean it Uncle Bob style, but can't for the life of me figure out a tidy way of doing it. So I come to you, my fabulous nerd friends, to see how you might distill this down to something that doesn't make one want to gouge out their eyes. The code is AS3, but that doesn't really make a difference in my opinion.
/**
* Splits this group into two groups based on the intersection of the group
* with another group. The group is split in a direction to fill empty
* cells left by the splitting group.
*
* #param onGroup
* #param directionToMoveSplitCells
* #return
*
*/
public function split(onGroup:CellGroup, directionToMoveSplitCells:String):CellGroup
{
if (!hasIntersection(onGroup))
return this;
var numCellsToSplit:int = 0;
var splitCells:Array;
var newGroup:CellGroup;
var numberOfCellsToSplit:int;
var splitStartIndex:int;
var resultingGroupStartIndex:int;
if (directionToMoveSplitCells == "RIGHT")
{
numberOfCellsToSplit = endIndex - onGroup.startIndex + 1;
splitStartIndex = length - numberOfCellsToSplit;
splitCells = trimCells(splitStartIndex, numberOfCellsToSplit);
resultingGroupStartIndex = onGroup.endIndex + 1;
if (splitCells.length > 0)
{
newGroup = row.createGroup(splitCells, resultingGroupStartIndex)
newGroup.nextGroup = nextGroup;
if (newGroup.nextGroup)
newGroup.nextGroup.previousGroup = newGroup;
newGroup.previousGroup = this;
nextGroup = newGroup;
}
}
else
{
numberOfCellsToSplit = onGroup.endIndex - startIndex + 1;
splitStartIndex = 0;
splitCells = trimCells(splitStartIndex, numberOfCellsToSplit);
resultingGroupStartIndex = onGroup.startIndex - splitCells.length;
if (splitCells.length > 0)
{
newGroup = row.createGroup(splitCells, resultingGroupStartIndex)
newGroup.previousGroup = previousGroup;
if (newGroup.previousGroup)
newGroup.previousGroup.nextGroup = newGroup
previousGroup = newGroup;
newGroup.nextGroup = this;
var newX:int = (onGroup.endIndex + 1) * cellSize.width;
x = newX;
}
}
removeArrayOfCellsFromGroup(splitCells);
row.joinGroups();
row.updateGroupIndices();
repositionCellsInGroup();
return newGroup;
}
public function split(onGroup:CellGroup, directionToMoveSplitCells:String):CellGroup
{
if (!hasIntersection(onGroup))
return this;
var newGroup:CellGroup;
if (directionToMoveSplitCells == "RIGHT")
{
newGroup = splitGroupAndMoveSplitCellsRight(onGroup);
if (!newGroup)
return;
insertAsNextGroupInLinkedList(newGroup);
}
else
{
newGroup = splitGroupAndMoveSplitCellsLeft(onGroup);
if (!newGroup)
return;
insertAsPreviousGroupInLinkedList(newGroup);
x = (onGroup.endIndex + 1) * cellSize.width;
}
removeArrayOfCellsFromGroup(splitCells);
row.joinGroups();
row.updateGroupIndices();
repositionCellsInGroup();
return newGroup;
}
private function splitGroupAndMoveSplitCellsRight(onGroup:CellGroup):CellGroup
{
var numCellsToSplit:int = endIndex - onGroup.startIndex + 1;
var splitStartIndex:int = length - numberOfCellsToSplit;
var splitCells:Array = trimCells(splitStartIndex, numberOfCellsToSplit);
if (!splitCells.length)
return null;
var resultingGroupStartIndex:int = onGroup.endIndex + 1;
return row.createGroup(splitCells, resultingGroupStartIndex);
}
private function splitGroupAndMoveSplitCellsLeft(onGroup:CellGroup):CellGroup
{
var numCellsToSplit:int = onGroup.endIndex - startIndex + 1;
var splitStartIndex:int = 0;
var splitCells:Array = trimCells(splitStartIndex, numberOfCellsToSplit);
if (!splitCells.length)
return null;
var resultingGroupStartIndex:int = onGroup.startIndex - splitCells.length;
return row.createGroup(splitCells, resultingGroupStartIndex);
}
private function insertAsNextGroupInLinkedList(group:CellGroup):void
{
var currentNextGroup:CellGroup = nextGroup;
if (currentNextGroup)
{
group.nextGroup = currentNextGroup;
currentNextGroup.previousGroup = group;
}
group.previousGroup = this;
nextGroup = group;
}
private function insertAsPreviousGroupInLinkedList(group:CellGroup):void
{
var currentPreviousGroup:CellGroup = previousGroup;
if (currentPreviousGroup)
{
group.previousGroup = currentPreviousGroup;
currentPreviousGroup.nextGroup = group;
}
group.nextGroup = this;
previousGroup = group;
}
/**
* Splits this group into two groups based on the intersection of the group
* with another group. The group is split in a direction to fill empty
* cells left by the splitting group.
*
* #param onGroup
* #param directionToMoveSplitCells
* #return
*
*/
public function split(onGroup:CellGroup, directionToMoveSplitCells:String):CellGroup
{
if(!hasIntersection(onGroup)) return this;
var numCellsToSplit:int = 0;
var splitCells:Array;
var newGroup:CellGroup;
var numberOfCellsToSplit:int;
var splitStartIndex:int;
var resultingGroupStartIndex:int;
numberOfCellsToSplit = (directionToMoveSplitCells == "RIGHT" ? (endIndex - onGroup.startIndex) : (onGroup.endIndex - startIndex)) + 1;
splitStartIndex = directionToMoveSplitCells == "RIGHT" ? (length - numberOfCellsToSplit) : 0;
splitCells = trimCells(splitStartIndex, numberOfCellsToSplit);
resultingGroupStartIndex = directionToMoveSplitCells == "RIGHT" ? (onGroup.startIndex - splitCells.length) : (onGroup.endIndex + 1);
if (splitCells.length > 0)
{
newGroup = row.createGroup(splitCells, resultingGroupStartIndex)
newGroup.nextGroup = nextGroup; //not sure how to not set this from jump
newGroup.previousGroup = previousGroup; //not sure how to not set this from jump
if (newGroup.previousGroup){
newGroup.previousGroup.nextGroup = newGroup;
previousGroup = newGroup;
var newX:int = (onGroup.endIndex + 1) * cellSize.width;
x = newX;
}
if (newGroup.nextGroup) newGroup.nextGroup.previousGroup = newGroup;
else{
newGroup.nextGroup = this;
newGroup.previousGroup = this;
nextGroup = newGroup;
}
}
removeArrayOfCellsFromGroup(splitCells);
row.joinGroups();
row.updateGroupIndices();
repositionCellsInGroup();
return newGroup;
}
This is all that occurs to me. The linked list is really a seperate detail... so maybe it can be refactored out....
public function split(onGroup:CellGroup, directionToMoveSplitCells:String):CellGroup
{
if (!hasIntersection(onGroup))
return this;
valr splitCells:Array;
var newGroup:CellGroup ;
var numberOfCellsToSplit:int;
var splitStartIndex:int;
var resultingGroupStartIndex:int;
if (directionToMoveSplitCells == "RIGHT")
{
numberOfCellsToSplit = this.endIndex - onGroup.startIndex + 1;
splitStartIndex = this.length - numberOfCellsToSplit;
splitCells = trimCells(splitStartIndex, numberOfCellsToSplit);
resultingGroupStartIndex = onGroup.endIndex + 1;
if (splitCells.length > 0)
{
newGroup = row.createGroup(splitCells, resultingGroupStartIndex);
nextGroup=insertGroup(newGroup,this,nextGroup);
}
}
else
{
numberOfCellsToSplit = onGroup.endIndex - startIndex + 1;
splitStartIndex = 0;
splitCells = trimCells(splitStartIndex, numberOfCellsToSplit);
resultingGroupStartIndex = onGroup.startIndex - splitCells.length;
if (splitCells.length > 0)
{
newGroup = row.createGroup(splitCells, resultingGroupStartIndex);
previousGroup=insertGroup(newGroup,previousGroup,this);
var newX:int = (onGroup.endIndex + 1) * cellSize.width;
x = newX;
}
}
removeArrayOfCellsFromGroup(splitCells);
row.joinGroups();
row.updateGroupIndices();
repositionCellsInGroup();
return newGroup;
}
private function insertGroup(toInsert:CellGroup,prior:CellGroup,next:CellGroup):CellGroup
{
toInsert.nextGroup = next;
toInsert.previousGroup = prior;
if (toInsert.nextGroup )
toInsert.nextGroup.previousGroup = toInsert;
if (toInsert.previousGroup )
toInsert.previousGroup.nextGroup = toInsert;
return toInsert;
}
My unindenting of splitCells assigment is to indicate that it is the inoly non-conditional line in the block.
I looked at doing what Anon proposed but I can't see any way to make the code actually better that way.
var groupThatWillReceiveCells = this;
var groupThatWontReceiveCells = onGroup;
if (directionToMoveSplitCells == "RIGHT")
{
groupThatWillReceiveCells = onGroup;
groupThatWontReceiveCells = this;
}
Rename stuff as needed.