当前位置: 首页>>代码示例>>Java>>正文


Java DataView.get方法代码示例

本文整理汇总了Java中org.spongepowered.api.data.DataView.get方法的典型用法代码示例。如果您正苦于以下问题:Java DataView.get方法的具体用法?Java DataView.get怎么用?Java DataView.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.spongepowered.api.data.DataView的用法示例。


在下文中一共展示了DataView.get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getByteArray

import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
/**
 * Attempts to get a byte array from the {@link DataView}
 * for the specific {@link DataQuery} path.
 *
 * @param dataView The data view
 * @param path The path
 * @return The byte array
 */
public static Optional<byte[]> getByteArray(DataView dataView, DataQuery path) {
    final Optional<Object> optObject = dataView.get(path);
    if (optObject.isPresent() && optObject.get() instanceof byte[]) {
        return (Optional) optObject;
    }
    return dataView.getByteList(path).map(list -> {
        if (list instanceof ByteList) {
            return ((ByteList) list).toByteArray();
        }
        final byte[] array = new byte[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);
        }
        return array;
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:DataViewHelper.java

示例2: getIntArray

import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
/**
 * Attempts to get a int array from the {@link DataView}
 * for the specific {@link DataQuery} path.
 *
 * @param dataView The data view
 * @param path The path
 * @return The int array
 */
public static Optional<int[]> getIntArray(DataView dataView, DataQuery path) {
    final Optional<Object> optObject = dataView.get(path);
    if (optObject.isPresent() && optObject.get() instanceof int[]) {
        return (Optional) optObject;
    }
    return dataView.getIntegerList(path).map(list -> {
        if (list instanceof IntList) {
            return ((IntList) list).toIntArray();
        }
        final int[] array = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);
        }
        return array;
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:DataViewHelper.java

示例3: getLongArray

import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
/**
 * Attempts to get a long array from the {@link DataView}
 * for the specific {@link DataQuery} path.
 *
 * @param dataView The data view
 * @param path The path
 * @return The long array
 */
public static Optional<long[]> getLongArray(DataView dataView, DataQuery path) {
    final Optional<Object> optObject = dataView.get(path);
    if (optObject.isPresent() && optObject.get() instanceof long[]) {
        return (Optional) optObject;
    }
    return dataView.getLongList(path).map(list -> {
        if (list instanceof LongList) {
            return ((LongList) list).toLongArray();
        }
        final long[] array = new long[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);
        }
        return array;
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:DataViewHelper.java

示例4: getDoubleArray

import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
/**
 * Attempts to get a long array from the {@link DataView}
 * for the specific {@link DataQuery} path.
 *
 * @param dataView The data view
 * @param path The path
 * @return The long array
 */
public static Optional<double[]> getDoubleArray(DataView dataView, DataQuery path) {
    final Optional<Object> optObject = dataView.get(path);
    if (optObject.isPresent() && optObject.get() instanceof double[]) {
        return (Optional) optObject;
    }
    return dataView.getDoubleList(path).map(list -> {
        if (list instanceof DoubleList) {
            return ((DoubleList) list).toDoubleArray();
        }
        final double[] array = new double[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);
        }
        return array;
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:DataViewHelper.java

示例5: getFloatArray

import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
/**
 * Attempts to get a long array from the {@link DataView}
 * for the specific {@link DataQuery} path.
 *
 * @param dataView The data view
 * @param path The path
 * @return The long array
 */
public static Optional<float[]> getFloatArray(DataView dataView, DataQuery path) {
    final Optional<Object> optObject = dataView.get(path);
    if (optObject.isPresent() && optObject.get() instanceof float[]) {
        return (Optional) optObject;
    }
    return dataView.getFloatList(path).map(list -> {
        if (list instanceof FloatList) {
            return ((FloatList) list).toFloatArray();
        }
        final float[] array = new float[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);
        }
        return array;
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:DataViewHelper.java

示例6: jsonFromDataView

import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
/**
 * Converts a DataView object into a JsonObject.
 *
 * @param view DataView
 * @return JsonObject JsonObject representation of the DataView
 */
public static JsonObject jsonFromDataView(DataView view) {
    JsonObject json = new JsonObject();

    Set<DataQuery> keys = view.getKeys(false);
    for (DataQuery query : keys) {
        Optional<Object> optional = view.get(query);
        if (optional.isPresent()) {
            String key = query.asString(".");

            if (optional.get() instanceof List) {
                List<?> list = (List<?>) optional.get();
                Iterator<?> iterator = list.iterator();
                while (iterator.hasNext()) {
                    Object object = iterator.next();

                    if (object instanceof DataView) {
                        json.add(key, jsonFromDataView((DataView) object));
                    }
                    else if (DataUtil.isPrimitiveType(object)) {
                        Gson gson = new GsonBuilder().create();
                        JsonArray array = gson.toJsonTree(optional.get()).getAsJsonArray();
                        json.add(key, array);
                        break;
                    }
                    else {
                        SafeGuard.getLogger().error("Unsupported list data type: " + object.getClass().getName());
                    }
                }
            }
            else if (optional.get() instanceof DataView) {
                json.add(key, jsonFromDataView((DataView) optional.get()));
            }
            else {
                Object obj = optional.get();

                if (obj instanceof String) {
                    json.addProperty(key, (String) obj);
                }
                else if (obj instanceof Number) {
                    json.addProperty(key, (Number) obj);
                }
                else if (obj instanceof Boolean) {
                    json.addProperty(key, (Boolean) obj);
                }
                else if (obj instanceof Character) {
                    json.addProperty(key, (Character) obj);
                }
            }
        }
    }

    return json;
}
 
开发者ID:prism,项目名称:SafeGuard,代码行数:60,代码来源:DataUtil.java

示例7: get

import org.spongepowered.api.data.DataView; //导入方法依赖的package包/类
@Override
public Optional<Object> get(DataQuery path) {
    checkNotNull(path, "path");
    final List<String> queryParts = path.getParts();

    int sz = queryParts.size();
    if (sz == 0) {
        return Optional.of(this);
    }

    final String key = queryParts.get(0);
    if (sz == 1) {
        final Object object = this.map.get(key);
        if (object == null) {
            return Optional.empty();
        }
        if (this.safety == SafetyMode.ALL_DATA_CLONED) {
            if (object.getClass().isArray()) {
                if (object instanceof byte[]) {
                    return Optional.of(ArrayUtils.clone((byte[]) object));
                } else if (object instanceof short[]) {
                    return Optional.of(ArrayUtils.clone((short[]) object));
                } else if (object instanceof int[]) {
                    return Optional.of(ArrayUtils.clone((int[]) object));
                } else if (object instanceof long[]) {
                    return Optional.of(ArrayUtils.clone((long[]) object));
                } else if (object instanceof float[]) {
                    return Optional.of(ArrayUtils.clone((float[]) object));
                } else if (object instanceof double[]) {
                    return Optional.of(ArrayUtils.clone((double[]) object));
                } else if (object instanceof boolean[]) {
                    return Optional.of(ArrayUtils.clone((boolean[]) object));
                } else {
                    return Optional.of(ArrayUtils.clone((Object[]) object));
                }
            }
        }
        return Optional.of(object);
    }
    final Optional<DataView> subViewOptional = getUnsafeView(key);
    if (!subViewOptional.isPresent()) {
        return Optional.empty();
    }
    final DataView subView = subViewOptional.get();
    return subView.get(path.popFirst());

}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:48,代码来源:MemoryDataView.java


注:本文中的org.spongepowered.api.data.DataView.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。