Skip to content

Commit

Permalink
IDE-198 Create abstract class EndBrickBase and inherit in Composite B…
Browse files Browse the repository at this point in the history
…ricks
  • Loading branch information
ma-zea committed Aug 28, 2023
1 parent 67b5f59 commit bc0f49d
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 311 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2023 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* http://developer.catrobat.org/license_additional_term
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.catrobat.catroid.content.bricks

import java.util.UUID

abstract class EndBrickBase(endBrickParent: BrickBaseType) : BrickBaseType() {

init {
parent = endBrickParent
}

override fun isCommentedOut(): Boolean = parent.isCommentedOut

override fun consistsOfMultipleParts(): Boolean = true

override fun getAllParts(): List<Brick?>? = parent.allParts

override fun addToFlatList(bricks: List<Brick?>?) {
parent.addToFlatList(bricks)
}

override fun getDragAndDropTargetList(): List<Brick?>? =
parent.parent.dragAndDropTargetList

override fun getPositionInDragAndDropTargetList(): Int =
parent.parent.dragAndDropTargetList.indexOf(parent)

override fun getBrickID(): UUID? = parent.brickID
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2023 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -36,7 +36,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class ForItemInUserListBrick extends UserDataBrick implements CompositeBrick {

Expand Down Expand Up @@ -166,40 +165,10 @@ public void addActionToSequence(Sprite sprite, ScriptSequenceAction sequence) {
sequence.addAction(action);
}

private static class EndBrick extends BrickBaseType {
private static class EndBrick extends EndBrickBase {

EndBrick(ForItemInUserListBrick parent) {
this.parent = parent;
}

@Override
public boolean isCommentedOut() {
return parent.isCommentedOut();
}

@Override
public boolean consistsOfMultipleParts() {
return true;
}

@Override
public List<Brick> getAllParts() {
return parent.getAllParts();
}

@Override
public void addToFlatList(List<Brick> bricks) {
parent.addToFlatList(bricks);
}

@Override
public List<Brick> getDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList();
}

@Override
public int getPositionInDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList().indexOf(parent);
super(parent);
}

@Override
Expand All @@ -210,10 +179,5 @@ public int getViewResource() {
@Override
public void addActionToSequence(Sprite sprite, ScriptSequenceAction sequence) {
}

@Override
public UUID getBrickID() {
return parent.getBrickID();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2023 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -36,7 +36,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class ForVariableFromToBrick extends UserVariableBrickWithFormula implements CompositeBrick {

Expand Down Expand Up @@ -185,40 +184,10 @@ public void addActionToSequence(Sprite sprite, ScriptSequenceAction sequence) {
sequence.addAction(action);
}

private static class EndBrick extends BrickBaseType {
private static class EndBrick extends EndBrickBase {

EndBrick(ForVariableFromToBrick parent) {
this.parent = parent;
}

@Override
public boolean isCommentedOut() {
return parent.isCommentedOut();
}

@Override
public boolean consistsOfMultipleParts() {
return true;
}

@Override
public List<Brick> getAllParts() {
return parent.getAllParts();
}

@Override
public void addToFlatList(List<Brick> bricks) {
parent.addToFlatList(bricks);
}

@Override
public List<Brick> getDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList();
}

@Override
public int getPositionInDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList().indexOf(parent);
super(parent);
}

@Override
Expand All @@ -229,10 +198,5 @@ public int getViewResource() {
@Override
public void addActionToSequence(Sprite sprite, ScriptSequenceAction sequence) {
}

@Override
public UUID getBrickID() {
return parent.getBrickID();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2023 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -33,7 +33,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class ForeverBrick extends BrickBaseType implements CompositeBrick {

Expand Down Expand Up @@ -159,40 +158,10 @@ public void addRequiredResources(final ResourcesSet requiredResourcesSet) {
}
}

private static class EndBrick extends BrickBaseType {
private static class EndBrick extends EndBrickBase {

EndBrick(ForeverBrick parent) {
this.parent = parent;
}

@Override
public boolean isCommentedOut() {
return parent.isCommentedOut();
}

@Override
public boolean consistsOfMultipleParts() {
return true;
}

@Override
public List<Brick> getAllParts() {
return parent.getAllParts();
}

@Override
public void addToFlatList(List<Brick> bricks) {
parent.addToFlatList(bricks);
}

@Override
public List<Brick> getDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList();
}

@Override
public int getPositionInDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList().indexOf(parent);
EndBrick(ForeverBrick endBrickParent) {
super(endBrickParent);
}

@Override
Expand All @@ -203,10 +172,5 @@ public int getViewResource() {
@Override
public void addActionToSequence(Sprite sprite, ScriptSequenceAction sequence) {
}

@Override
public UUID getBrickID() {
return parent.getBrickID();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2023 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -277,40 +277,10 @@ public UUID getBrickID() {
}

@VisibleForTesting
public static class EndBrick extends BrickBaseType {
public static class EndBrick extends EndBrickBase {

EndBrick(IfLogicBeginBrick ifBrick) {
parent = ifBrick;
}

@Override
public boolean isCommentedOut() {
return parent.isCommentedOut();
}

@Override
public boolean consistsOfMultipleParts() {
return true;
}

@Override
public List<Brick> getAllParts() {
return parent.getAllParts();
}

@Override
public void addToFlatList(List<Brick> bricks) {
parent.addToFlatList(bricks);
}

@Override
public List<Brick> getDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList();
}

@Override
public int getPositionInDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList().indexOf(parent);
super(ifBrick);
}

@Override
Expand All @@ -321,10 +291,5 @@ public int getViewResource() {
@Override
public void addActionToSequence(Sprite sprite, ScriptSequenceAction sequence) {
}

@Override
public UUID getBrickID() {
return parent.getBrickID();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class IfThenLogicBeginBrick extends FormulaBrick implements CompositeBrick {

Expand Down Expand Up @@ -178,40 +177,10 @@ public void addRequiredResources(final ResourcesSet requiredResourcesSet) {
}
}

private static class EndBrick extends BrickBaseType {
private static class EndBrick extends EndBrickBase {

EndBrick(IfThenLogicBeginBrick parent) {
this.parent = parent;
}

@Override
public boolean isCommentedOut() {
return parent.isCommentedOut();
}

@Override
public boolean consistsOfMultipleParts() {
return true;
}

@Override
public List<Brick> getAllParts() {
return parent.getAllParts();
}

@Override
public void addToFlatList(List<Brick> bricks) {
parent.addToFlatList(bricks);
}

@Override
public List<Brick> getDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList();
}

@Override
public int getPositionInDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList().indexOf(parent);
super(parent);
}

@Override
Expand All @@ -222,10 +191,5 @@ public int getViewResource() {
@Override
public void addActionToSequence(Sprite sprite, ScriptSequenceAction sequence) {
}

@Override
public UUID getBrickID() {
return parent.getBrickID();
}
}
}
Loading

0 comments on commit bc0f49d

Please sign in to comment.