最近用了E4A,发现里面的核心函数太少了,比如数组这一块,还是自己手动一下

接口:数组扩展.java
E4A工程(栗子):数组扩展.e4a

贴代码

接口代码:

/**
 * 数组扩展
 * @author 小さな手は
 */
package com.e4a.runtime.api;//包名必须固定为这个,不能自己修改

import com.e4a.runtime.annotations.SimpleFunction;
import com.e4a.runtime.annotations.SimpleObject;
import com.e4a.runtime.annotations.UsesPermissions;

import com.e4a.runtime.android.mainActivity;

//java包
import java.util.Arrays;
import java.lang.reflect.Array;

import android.widget.Toast;

@UsesPermissions(permissionNames = "android.permission.INTERNET")//安卓权限标记,如果接口函数中需要额外的安卓权限,可在此填写,多个权限可以用逗号隔开
@SimpleObject
public final class 数组扩展{

    @SimpleFunction//导出函数标记
    /**
     * 将文本数组按一定顺序进行排序
     * @param str 欲操作的文本数组
     * @return void 
     */
    public static void 文本数组排序(String[] str){ 
        Arrays.sort(str);
    }

    @SimpleFunction//导出函数标记
    /**
     * 返回数组中第一次被寻找文本出现的的位置
     * @param str  欲操作的文本数组
     * @param searchStr  被寻找的文本
     * @return int  数组中第一次被寻找文本出现的的位置,没有返回-1
     */
    public static int 数组寻找文本(String[] str,String searchStr){ 
        for(int i = 0; i < str.length;i++){
            if(str[i].indexOf(searchStr) != -1){
            return i;
            }
        }
        return -1;
    }

    @SimpleFunction//导出函数标记
    /**
     * 插入成员
     * 
     * @param obj 数组对象
     * @param index 插入位置
     * @param addObj 新增的成员
     * @return 返回数组
     */
    public static Object insertMunber(Object obj,int index,Object addObj){
        int i = Array.getLength(obj) + 1;
        if (index <= i + 1 && index >= 1){
            Object arr = obj;
            arr = resetArray(arr,i);
            System.arraycopy(obj,0,arr,0,index - 1);
            System.arraycopy(obj,index - 1,arr,index,i - index);
            Array.set(arr,index - 1,addObj);
            return arr;
        }
        return obj;
    }

    @SimpleFunction//导出函数标记
    /**
     * 加入成员
     * 
     * @param obj 数组对象
     * @param addObj 新增的成员
     * @return 返回数组
     */
    public static Object addMunber(Object obj,Object addObj){
        return insertMunber(obj,Array.getLength(obj) + 1,addObj);
    }

    @SimpleFunction//导出函数标记
    /**
     * 删除成员
     * 
     * @param obj 数组对象
     * @param index 删除位置
     * @return 返回数组
     */
    public static Object removeMunber(Object obj,int index){
        int length = Array.getLength(obj) - 1;
        Object newobj = Array.newInstance(obj.getClass().getComponentType(),length);
        System.arraycopy(obj,0,newobj,0,index - 1);
        System.arraycopy(obj,index,newobj,index - 1,length + 1 - index);
        return newobj;
    }

    @SimpleFunction//导出函数标记
    /**
     * 重定义数组
     * 
     * @param obj 数组对象
     * @param length 长度
     * @return 返回数组
     */
    public static Object resetArray(Object obj,int length){
        return Array.newInstance(obj.getClass().getComponentType(),length);
    }

}

全局模块代码:

静态 过程 插入成员(传址 数组 为 对象,位置 为 整数型,新成员 为 对象)
    数组 = 数组扩展.insertMunber(数组,位置,新成员)
结束 过程
静态 过程 加入成员(传址 数组 为 对象,新成员 为 对象)
    数组 = 数组扩展.addMunber(数组,新成员)
结束 过程
静态 过程 删除成员(传址 数组 为 对象,位置 为 整数型)
    数组 = 数组扩展.removeMunber(数组,位置)
结束 过程
静态 过程 重定义(传址 数组 为 对象,长度 为 整数型)
    数组 = 数组扩展.resetArray(数组,长度)
结束 过程
静态 过程 文本数组排序(传址 数组 为 文本型())
    数组扩展.文本数组排序(数组)
结束 过程
静态 函数 数组寻找文本(数组 为 文本型(),被寻找文本 为 文本型) 为 整数型
    数组寻找文本 = 数组扩展.数组寻找文本(数组,被寻找文本)
结束 函数

支付宝红包

支付宝

微信

标签: none

添加新评论

注意:已开启评论过滤器,无中文无法评论!
泡泡表情