Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2024. caoccao.com Sam Cao
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.caoccao.javet.interop.proxy.plugins;
import com.caoccao.javet.entities.JavetEntityPropertyDescriptor;
import com.caoccao.javet.exceptions.JavetException;
import com.caoccao.javet.interfaces.IJavetEntityPropertyDescriptor;
import com.caoccao.javet.interop.V8Runtime;
import com.caoccao.javet.interop.callback.IJavetDirectCallable;
import com.caoccao.javet.interop.callback.JavetCallbackContext;
import com.caoccao.javet.interop.callback.JavetCallbackType;
import com.caoccao.javet.utils.ArrayUtils;
import com.caoccao.javet.utils.SimpleList;
import com.caoccao.javet.utils.SimpleSet;
import com.caoccao.javet.utils.V8ValueUtils;
import com.caoccao.javet.values.V8Value;
import com.caoccao.javet.values.reference.V8ValueFunction;
import com.caoccao.javet.values.reference.V8ValueObject;
import com.caoccao.javet.values.reference.builtin.V8ValueBuiltInSymbol;
import com.caoccao.javet.values.virtual.V8VirtualIterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
* The type Javet proxy plugin set.
*
* @since 3.0.4
*/
@SuppressWarnings("unchecked")
public class JavetProxyPluginSet extends BaseJavetProxyPluginSingle> {
/**
* The constant NAME.
*
* @since 3.0.4
*/
public static final String NAME = Set.class.getName();
protected static final String ADD = "add";
protected static final String CLEAR = "clear";
protected static final String DELETE = "delete";
protected static final String ENTRIES = "entries";
protected static final String ERROR_TARGET_OBJECT_MUST_BE_AN_INSTANCE_OF_SET =
"Target object must be an instance of Set.";
protected static final String FOR_EACH = "forEach";
protected static final String HAS = "has";
protected static final String KEYS = "keys";
protected static final String OBJECT_SET = "[object Set]";
protected static final String SIZE = "size";
/**
* The constant DEFAULT_PROXYABLE_METHODS.
*
* @since 3.0.4
*/
protected static final String[] DEFAULT_PROXYABLE_METHODS = new String[]{
ADD, CLEAR, FOR_EACH, SIZE, TO_STRING};
protected static final String VALUES = "values";
private static final JavetProxyPluginSet instance = new JavetProxyPluginSet();
/**
* The Override methods.
*
* @since 3.0.4
*/
protected final Set proxyableMethods;
public JavetProxyPluginSet() {
super();
proxyableMethods = SimpleSet.of(DEFAULT_PROXYABLE_METHODS);
proxyGetByStringMap.put(ADD, this::add);
proxyGetByStringMap.put(CLEAR, this::clear);
proxyGetByStringMap.put(DELETE, this::delete);
proxyGetByStringMap.put(ENTRIES, this::entries);
proxyGetByStringMap.put(FOR_EACH, this::forEach);
proxyGetByStringMap.put(HAS, this::has);
proxyGetByStringMap.put(KEYS, this::values);
proxyGetByStringMap.put(SIZE, this::size);
proxyGetByStringMap.put(TO_JSON, this::toJSON);
proxyGetByStringMap.put(TO_STRING, this::toString);
proxyGetByStringMap.put(VALUE_OF, this::valueOf);
proxyGetByStringMap.put(VALUES, this::values);
proxyGetBySymbolMap.put(V8ValueBuiltInSymbol.SYMBOL_PROPERTY_ITERATOR, this::values);
}
/**
* Gets instance.
*
* @return the instance
* @since 3.0.4
*/
public static JavetProxyPluginSet getInstance() {
return instance;
}
/**
* Polyfill Set.prototype.add().
* The add() method of Set instances inserts a new element with a specified value in to this set,
* if there isn't an element with the same value already in this set
*
* @param v8Runtime the V8 runtime
* @param targetObject the target object
* @return the V8 value
* @throws JavetException the javet exception
* @since 3.0.4
*/
public V8Value add(V8Runtime v8Runtime, Object targetObject) throws JavetException {
final Set