
com.tangosol.internal.util.collection.PortableSet Maven / Gradle / Ivy
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
package com.tangosol.internal.util.collection;
import com.tangosol.io.ExternalizableLite;
import com.tangosol.io.pof.PofReader;
import com.tangosol.io.pof.PofWriter;
import com.tangosol.io.pof.PortableObject;
import com.tangosol.util.ExternalizableHelper;
import com.tangosol.util.WrapperCollections;
import com.tangosol.util.function.Remote;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import javax.json.bind.annotation.JsonbProperty;
/**
* A wrapper Set that controls wrapped set's serialization.
*
* @param the element type
*
* @author as 2014.11.19
* @since 12.2.1
*/
@SuppressWarnings({"unchecked", "SuspiciousToArrayCall", "NullableProblems"})
public class PortableSet
extends WrapperCollections.AbstractWrapperSet
implements PortableObject, ExternalizableLite
{
// ---- constructors ----------------------------------------------------
/**
* Construct RemoteSet instance which wraps an instance of a {@link HashSet}.
*/
public PortableSet()
{
}
/**
* Construct RemoteSet instance with a specified supplier.
*
* @param supplier a wrapped set supplier
*/
public PortableSet(Remote.Supplier> supplier)
{
m_supplier = supplier;
}
/**
* Return the supplier for this collection.
*
* @return the supplier.
*/
public Remote.Supplier> getSupplier()
{
return m_supplier == null ? DEFAULT_SUPPLIER : m_supplier;
}
@Override
protected Set getDelegate()
{
return m_colDelegate == null ? (Set) (m_colDelegate = getSupplier().get())
: (Set) m_colDelegate;
}
// ---- ExternalizableLite implementation -------------------------------
@Override
public void readExternal(DataInput in) throws IOException
{
m_supplier = ExternalizableHelper.readObject(in);
ExternalizableHelper.readCollection(in, getDelegate(), null);
}
@Override
public void writeExternal(DataOutput out) throws IOException
{
ExternalizableHelper.writeObject(out, m_supplier);
ExternalizableHelper.writeCollection(out, getDelegate());
}
// ---- PortableObject implementation -----------------------------------
@Override
public void readExternal(PofReader in) throws IOException
{
m_supplier = in.readObject(0);
m_colDelegate = in.readCollection(1, getDelegate());
}
@Override
public void writeExternal(PofWriter out) throws IOException
{
out.writeObject(0, m_supplier);
out.writeCollection(1, getDelegate());
}
// ---- static members -------------------------------------------------
/**
* Default supplier for the wrapped Collection instance, used for
* interoperability with .NET and C++ clients which are not able to handle
* lambda-based Java suppliers.
*/
protected static final Remote.Supplier DEFAULT_SUPPLIER = HashSet::new;
// ---- data members ----------------------------------------------------
/**
* Supplier for the wrapped Set instance.
*/
@JsonbProperty("supplier")
protected Remote.Supplier> m_supplier;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy