Skip to content

Commit

Permalink
wip: add clonable(With Java Generics) interface for bean and implemen…
Browse files Browse the repository at this point in the history
…t clone for regular block bean
  • Loading branch information
SyntaxGalaxy committed Nov 21, 2024
1 parent 53d8713 commit 357f6c9
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import java.util.ArrayList;

/** ActionBlockBean, BlockBean that perform action. */
public abstract class ActionBlockBean extends BlockBean implements Serializable {
public abstract class ActionBlockBean<T> extends BlockBean<T> implements Serializable {

public static final long serialVersionUID = SerializationUIDConstants.ACTION_BLOCK_BEAN;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package com.icst.android.appstudio.beans;

import com.icst.android.appstudio.beans.utils.BeanArrayCloneUtils;
import com.icst.android.appstudio.beans.utils.SerializationUIDConstants;
import java.io.Serializable;
import java.util.ArrayList;
Expand All @@ -40,7 +41,7 @@
* TerminatorBlockBean. Used to store the
* nested BlockBeans, and does not hold BlockElementBean directly into it.
*/
public class ActionBlockLayerBean extends LayerBean implements Serializable {
public class ActionBlockLayerBean extends LayerBean<ActionBlockLayerBean> implements Serializable {

public static final long serialVersionUID = SerializationUIDConstants.ACTION_ELEMENT_LAYER_BEAN;

Expand All @@ -53,4 +54,11 @@ public ArrayList<ActionBlockBean> getActionBlockBean() {
public void setActionBlockBean(ArrayList<ActionBlockBean> actionBlockBean) {
this.actionBlockBean = actionBlockBean;
}

@Override
public ActionBlockLayerBean cloneBean() {
ActionBlockLayerBean clone = new ActionBlockLayerBean();
clone.setActionBlockBean(BeanArrayCloneUtils.clone(getActionBlockBean()));
return clone;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* does not return any
* code from it.
*/
public abstract class BaseBlockBean extends BlockBean implements Serializable {
public abstract class BaseBlockBean<T> extends BlockBean<T> implements Serializable {

public static final long serialVersionUID = SerializationUIDConstants.BASE_BLOCK_BEAN;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* Abstract class representing the base block supposed to be used within the
* LogicEditor.
*/
public abstract class BlockBean implements Serializable {
public abstract class BlockBean<T> implements Serializable, CloneableBean<T> {

public static final long serialVersionUID = SerializationUIDConstants.BLOCK_BEAN;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
* block elements but
* does not hold nested blocks.
*/
public class BlockElementLayerBean extends LayerBean implements Serializable {
public class BlockElementLayerBean extends LayerBean<BlockElementLayerBean>
implements Serializable {

public static final long serialVersionUID = SerializationUIDConstants.BLOCK_ELEMENT_LAYER_BEAN;

Expand All @@ -53,4 +54,9 @@ public ArrayList<BlockElementBean> getBlockElementBeans() {
public void setBlockElementBeans(ArrayList<BlockElementBean> blockElementBeans) {
this.blockElementBeans = blockElementBeans;
}

@Override
public BlockElementLayerBean cloneBean() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This file is part of Android AppStudio [https://github.com/Innovative-CST/AndroidAppStudio].
*
* License Agreement
* This software is licensed under the terms and conditions outlined below. By accessing, copying, modifying, or using this software in any way, you agree to abide by these terms.
*
* 1. ** Copy and Modification Restrictions **
* - You are not permitted to copy or modify the source code of this software without the permission of the owner, which may be granted publicly on GitHub Discussions or on Discord.
* - If permission is granted by the owner, you may copy the software under the terms specified in this license agreement.
* - You are not allowed to permit others to copy the source code that you were allowed to copy by the owner.
* - Modified or copied code must not be further copied.
* 2. ** Contributor Attribution **
* - You must attribute the contributors by creating a visible list within the application, showing who originally wrote the source code.
* - If you copy or modify this software under owner permission, you must provide links to the profiles of all contributors who contributed to this software.
* 3. ** Modification Documentation **
* - All modifications made to the software must be documented and listed.
* - the owner may incorporate the modifications made by you to enhance this software.
* 4. ** Consistent Licensing **
* - All copied or modified files must contain the same license text at the top of the files.
* 5. ** Permission Reversal **
* - If you are granted permission by the owner to copy this software, it can be revoked by the owner at any time. You will be notified at least one week in advance of any such reversal.
* - In case of Permission Reversal, if you fail to acknowledge the notification sent by us, it will not be our responsibility.
* 6. ** License Updates **
* - The license may be updated at any time. Users are required to accept and comply with any changes to the license.
* - In such circumstances, you will be given 7 days to ensure that your software complies with the updated license.
* - We will not notify you about license changes; you need to monitor the GitHub repository yourself (You can enable notifications or watch the repository to stay informed about such changes).
* By using this software, you acknowledge and agree to the terms and conditions outlined in this license agreement. If you do not agree with these terms, you are not permitted to use, copy, modify, or distribute this software.
*
* Copyright © 2024 Dev Kumar
*/

package com.icst.android.appstudio.beans;

public interface CloneableBean<T> {

T cloneBean();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@
import com.icst.android.appstudio.beans.utils.SerializationUIDConstants;
import java.io.Serializable;

public class EventBlockBean extends BaseBlockBean implements Serializable {
public class EventBlockBean extends BaseBlockBean<EventBlockBean> implements Serializable {

public static final long serialVersionUID = SerializationUIDConstants.EVENT_BLOCK_BEAN;

public void getValueFromKey(String key) {
// TODO: Implementation to get the values from block element using key...
}

@Override
public EventBlockBean cloneBean() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
import com.icst.android.appstudio.beans.utils.SerializationUIDConstants;
import java.io.Serializable;

public class ExpressionBlockBean extends BaseBlockBean implements BlockElementBean, Serializable {
public class ExpressionBlockBean extends BaseBlockBean<ExpressionBlockBean>
implements BlockElementBean, Serializable {

public static final long serialVersionUID = SerializationUIDConstants.EXPRESSION_BLOCK_BEAN;

Expand All @@ -57,4 +58,9 @@ public DatatypeBean[] getReturnDatatypes() {
public void setReturnDatatypes(DatatypeBean[] returnDatatypes) {
this.returnDatatypes = returnDatatypes;
}

@Override
public ExpressionBlockBean cloneBean() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
* rendered below from point of new layer (e.g: Like we press enter to put long
* text on next line)
*/
public abstract class LayerBean implements Serializable {
public abstract class LayerBean<T> implements Serializable, CloneableBean<T> {
public static final long serialVersionUID = SerializationUIDConstants.LAYER_BEAN;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@

package com.icst.android.appstudio.beans;

import com.icst.android.appstudio.beans.utils.BeanArrayCloneUtils;
import com.icst.android.appstudio.beans.utils.SerializationUIDConstants;
import java.io.Serializable;

/**
* RegularBlockBean: Can hold RegularBlockBean (nested blocks), BlockElementBean
*/
public class RegularBlockBean extends ActionBlockBean implements Serializable {
public class RegularBlockBean extends ActionBlockBean<RegularBlockBean>
implements Serializable {

public static final long serialVersionUID = SerializationUIDConstants.BLOCK_BEAN;

Expand All @@ -50,4 +52,16 @@ public String getCodeSyntax() {
public void setCodeSyntax(String codeSyntax) {
this.codeSyntax = codeSyntax;
}

@Override
public RegularBlockBean cloneBean() {
RegularBlockBean clone = new RegularBlockBean();
clone.setBlockBeanKey(getBlockBeanKey() == null ? null : new String(getBlockBeanKey()));
clone.setCodeSyntax(getCodeSyntax() == null ? null : new String(getCodeSyntax()));
clone.setColor(getColor() == null ? null : new String(getColor()));
clone.setDragAllowed(new Boolean(isDragAllowed()));
clone.setLayers(BeanArrayCloneUtils.clone(getLayers()));
clone.setValueReadOnly(new Boolean(isValueReadOnly()));
return clone;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
* action block can be
* placed.
*/
public class TerminatorBlockBean extends ActionBlockBean implements Serializable {
public class TerminatorBlockBean extends ActionBlockBean<TerminatorBlockBean>
implements Serializable {

public static final long serialVersionUID = SerializationUIDConstants.BLOCK_BEAN;

Expand All @@ -54,4 +55,9 @@ public String getCodeSyntax() {
public void setCodeSyntax(String codeSyntax) {
this.codeSyntax = codeSyntax;
}

@Override
public TerminatorBlockBean cloneBean() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This file is part of Android AppStudio [https://github.com/Innovative-CST/AndroidAppStudio].
*
* License Agreement
* This software is licensed under the terms and conditions outlined below. By accessing, copying, modifying, or using this software in any way, you agree to abide by these terms.
*
* 1. ** Copy and Modification Restrictions **
* - You are not permitted to copy or modify the source code of this software without the permission of the owner, which may be granted publicly on GitHub Discussions or on Discord.
* - If permission is granted by the owner, you may copy the software under the terms specified in this license agreement.
* - You are not allowed to permit others to copy the source code that you were allowed to copy by the owner.
* - Modified or copied code must not be further copied.
* 2. ** Contributor Attribution **
* - You must attribute the contributors by creating a visible list within the application, showing who originally wrote the source code.
* - If you copy or modify this software under owner permission, you must provide links to the profiles of all contributors who contributed to this software.
* 3. ** Modification Documentation **
* - All modifications made to the software must be documented and listed.
* - the owner may incorporate the modifications made by you to enhance this software.
* 4. ** Consistent Licensing **
* - All copied or modified files must contain the same license text at the top of the files.
* 5. ** Permission Reversal **
* - If you are granted permission by the owner to copy this software, it can be revoked by the owner at any time. You will be notified at least one week in advance of any such reversal.
* - In case of Permission Reversal, if you fail to acknowledge the notification sent by us, it will not be our responsibility.
* 6. ** License Updates **
* - The license may be updated at any time. Users are required to accept and comply with any changes to the license.
* - In such circumstances, you will be given 7 days to ensure that your software complies with the updated license.
* - We will not notify you about license changes; you need to monitor the GitHub repository yourself (You can enable notifications or watch the repository to stay informed about such changes).
* By using this software, you acknowledge and agree to the terms and conditions outlined in this license agreement. If you do not agree with these terms, you are not permitted to use, copy, modify, or distribute this software.
*
* Copyright © 2024 Dev Kumar
*/

package com.icst.android.appstudio.beans.utils;

import com.icst.android.appstudio.beans.CloneableBean;
import java.util.ArrayList;

public final class BeanArrayCloneUtils {
public static <T extends CloneableBean> ArrayList<T> clone(ArrayList<T> beans) {
if (beans == null)
return null;
ArrayList<T> clone = new ArrayList<>();
for (int i = 0; i < beans.size(); ++i) {
clone.add((T) beans.get(i).cloneBean());
}
return clone;
}
}

0 comments on commit 357f6c9

Please sign in to comment.