All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.qt.core.QSet Maven / Gradle / Ivy

There is a newer version: 6.8.0
Show newest version
/****************************************************************************
**
** Copyright (C) 2009-2024 Dr. Peter Droste, Omix Visualization GmbH & Co. KG. All rights reserved.
**
** This file is part of Qt Jambi.
**
** $BEGIN_LICENSE$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
** 
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
** $END_LICENSE$

**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
package io.qt.core;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;

import io.qt.NativeAccess;
import io.qt.QNoImplementationException;
import io.qt.QNoNativeResourcesException;
import io.qt.QtUninvokable;

/**
 * 

Java wrapper for Qt class QSet

*/ public class QSet extends AbstractSequentialContainer implements Set, Cloneable { static { QtJambi_LibraryUtilities.initialize(); } /** * Constructor for internal use only. * @param p expected to be null. * @hidden */ @NativeAccess protected QSet(QPrivateConstructor p) { super(p); } /** * Creating a container with given element type. *

See QSet::QSet()

* @param elementType the type T */ public QSet(Class elementType) { super(null); QMetaType metaType = QMetaType.fromType(elementType); initialize(elementType, QtJambi_LibraryUtilities.internal.nativeId(metaType), null); } /** * Creating a container with given element type. *

See QSet::QSet()

* @param metaType the type T */ public QSet(QMetaType.Type metaType) { this(new QMetaType(metaType)); } /** * Creating a container with given element type. *

See QSet::QSet()

* @param metaType the type T */ public QSet(QMetaType metaType) { super(null); initialize(metaType.javaType(), QtJambi_LibraryUtilities.internal.nativeId(metaType), null); } /** * Creating a container with given content. *

See QSet::QSet(const QSet<T> &)

* @param other container */ public QSet(Collection other) { super(null); QMetaType metaType = QList.findElementMetaType(Objects.requireNonNull(other)); initialize(metaType.javaType(), QtJambi_LibraryUtilities.internal.nativeId(metaType), other); } @QtUninvokable private native void initialize(Class elementType, long elementMetaType, Collection other); /** * Creates and returns a copy of this object. */ @Override public QSet clone(){ return new QSet<>(this); } /** * Provides a constant C++ iterator to the containers begin. *

See QSet::constBegin()const

* @return begin */ @QtUninvokable protected final QSequentialConstIterator constBegin() { return constBegin(QtJambi_LibraryUtilities.internal.nativeId(this)); } @QtUninvokable private static native QSequentialConstIterator constBegin(long __this__nativeId); /** *

See QSet::capacity()const

*/ @QtUninvokable public final int capacity() { return capacity(QtJambi_LibraryUtilities.internal.nativeId(this)); } @QtUninvokable private static native int capacity(long __this__nativeId); /** *

See QSet::clear()

*/ @QtUninvokable public final void clear() { clear(QtJambi_LibraryUtilities.internal.nativeId(this)); } @QtUninvokable private static native void clear(long __this__nativeId); /** *

See QSet::contains(T)const

*/ @QtUninvokable public final boolean contains(Object t) { try { return contains(QtJambi_LibraryUtilities.internal.nativeId(this), t); }catch(QNoNativeResourcesException e) { throw e; }catch(IllegalArgumentException e) { return false; }catch(RuntimeException e) { RuntimeException e1 = QSet.handleException(e, elementMetaType(), t); if(e1==e) throw e; return false; } } @QtUninvokable private static native boolean contains(long __this__nativeId, T t); /** *

See QSet::count()const

*/ @QtUninvokable public final int count() { return size(); } /** * Provides a constant C++ iterator to the containers end. *

See QSet::constEnd()const

* @return end */ @QtUninvokable protected final QSequentialConstIterator constEnd() { return constEnd(QtJambi_LibraryUtilities.internal.nativeId(this)); } @QtUninvokable private static native QSequentialConstIterator constEnd(long __this__nativeId); /** *

See QSet::insert(T)

*/ @QtUninvokable public final void insert(T t) { try { insert(QtJambi_LibraryUtilities.internal.nativeId(this), t); }catch(QNoNativeResourcesException e) { throw e; }catch(RuntimeException e) { throw QSet.handleException(e, elementMetaType(), t); } } @QtUninvokable private static native void insert(long __this__nativeId, T t); /** *

See QSet::intersect(QSet<T>)

*/ @QtUninvokable public final void intersect(java.util.Collection other) { intersect(QtJambi_LibraryUtilities.internal.nativeId(this), other); } @QtUninvokable private static native void intersect(long __this__nativeId, java.util.Collection other); /** *

See QSet::intersects(QSet<T>)const

*/ @QtUninvokable public final boolean intersects(java.util.Collection other) { return intersects(QtJambi_LibraryUtilities.internal.nativeId(this), other); } @QtUninvokable private static native boolean intersects(long __this__nativeId, java.util.Collection other); /** *

See QSet::isEmpty()const

*/ @QtUninvokable public final boolean isEmpty() { return size()==0; } /** *

See QSet::remove(T)

*/ @QtUninvokable public final boolean remove(Object t) { try { return remove(QtJambi_LibraryUtilities.internal.nativeId(this), t); }catch(QNoNativeResourcesException e) { throw e; }catch(IllegalArgumentException e) { return false; }catch(RuntimeException e) { RuntimeException e1 = QSet.handleException(e, elementMetaType(), t); if(e1==e) throw e; return false; } } @QtUninvokable private static native boolean remove(long __this__nativeId, T t); /** *

See QSet::removeIf(Predicate)

*/ @QtUninvokable public final boolean removeIf(Predicate predicate) { Objects.requireNonNull(predicate); boolean removed = false; QSet clone = clone(); final Iterator each = clone.iterator(); while (each.hasNext()) { T value = each.next(); if (predicate.test(value)) { remove(value); removed = true; } } return removed; } /** *

See QSet::reserve(int)

*/ @QtUninvokable public final void reserve(int size) { reserve(QtJambi_LibraryUtilities.internal.nativeId(this), size); } @QtUninvokable private static native void reserve(long __this__nativeId, int size); /** *

See QSet::size()const

*/ @QtUninvokable public final int size() { return size(QtJambi_LibraryUtilities.internal.nativeId(this)); } @QtUninvokable private static native int size(long __this__nativeId); /** *

See QSet::subtract(QSet<T>)

*/ @QtUninvokable public final void subtract(java.util.Collection other) { subtract(QtJambi_LibraryUtilities.internal.nativeId(this), other); } @QtUninvokable private static native void subtract(long __this__nativeId, java.util.Collection other); /** *

See QSet::unite(QSet<T>)

*/ @QtUninvokable public final void unite(java.util.Collection other) { unite(QtJambi_LibraryUtilities.internal.nativeId(this), other); } @QtUninvokable private static native void unite(long __this__nativeId, java.util.Collection other); /** *

See QSet::values()const

*/ @QtUninvokable public final QList values() { return values(QtJambi_LibraryUtilities.internal.nativeId(this)); } @QtUninvokable private static native QList values(long __this__nativeId); /** *

See QSet::operator==(QSet<T>)const

*/ @Override @QtUninvokable public boolean equals(Object other) { if (other instanceof java.util.Collection && QList.checkContainerType(this.elementMetaType(), (java.util.Collection) other)) { return operator_equal(QtJambi_LibraryUtilities.internal.nativeId(this), (java.util.Collection) other); } return false; } @QtUninvokable private static native boolean operator_equal(long __this__nativeId, java.util.Collection l); /** * Returns the objects's hash code computed by qHash(QSet<T>). */ @Override @QtUninvokable public int hashCode() { try { return hashCode(QtJambi_LibraryUtilities.internal.nativeId(this)); } catch (QNoNativeResourcesException e) { return 0; } } @QtUninvokable private static native int hashCode(long __this__nativeId); /** * Returns the string representation of the object given by QVariant(this).toString(). */ @Override @QtUninvokable public String toString() { try { return toString(QtJambi_LibraryUtilities.internal.nativeId(this)); } catch (QNoImplementationException e) { return super.toString(); } catch (QNoNativeResourcesException e) { return "null"; } } @QtUninvokable private static native String toString(long __this__nativeId); /** * Adds the specified element to this set if it is not already present * (optional operation). More formally, adds the specified element * {@code e} to this set if the set contains no element {@code e2} * such that * {@code Objects.equals(e, e2)}. * If this set already contains the element, the call leaves the set * unchanged and returns {@code false}. In combination with the * restriction on constructors, this ensures that sets never contain * duplicate elements. */ @Override @QtUninvokable public final boolean add(T e){ insert(e); return true; } /** *

See operator<<(QDataStream&,QSet<T>)

*/ @io.qt.QtUninvokable public void writeTo(io.qt.core.QDataStream stream){ writeTo(QtJambi_LibraryUtilities.internal.nativeId(this), QtJambi_LibraryUtilities.internal.nativeId(stream)); } @io.qt.QtUninvokable private native void writeTo(long __this__nativeId, long stream); /** *

See operator>>(QDataStream&,QSet<T>&)

*/ @io.qt.QtUninvokable public void readFrom(io.qt.core.QDataStream stream){ readFrom(QtJambi_LibraryUtilities.internal.nativeId(this), QtJambi_LibraryUtilities.internal.nativeId(stream)); } @io.qt.QtUninvokable private native void readFrom(long __this__nativeId, long stream); @io.qt.QtUninvokable final QMetaType elementMetaType() { return elementMetaType(QtJambi_LibraryUtilities.internal.nativeId(this)); } @io.qt.QtUninvokable private static native QMetaType elementMetaType(long __this_nativeId); /** * Returns a QSet containing given elements. * * @param the {@code QSet}'s element type * @param element0 the first element * @param elements subsequent elements * @return a {@code QSet} containing the specified element * @throws NullPointerException if elements are {@code null} */ @SafeVarargs public static QSet of(T element0, T...elements) { QMetaType metaType = QList.findElementMetaType(element0, elements); QSet result = new QSet<>(metaType); result.add(element0); for (T t : elements) { result.add(t); } return result; } static RuntimeException handleException(RuntimeException e, QMetaType elementMetaType, Object value) { if(( (e.getClass()==RuntimeException.class && e.getMessage()!=null && e.getMessage().startsWith("Cannot cast to type")) || (e.getClass()==IllegalArgumentException.class && e.getMessage()!=null && e.getMessage().startsWith("Cannot cast object of type ")) || e instanceof ClassCastException ) && value!=null) { Class elementType = elementMetaType.javaType(); if(Collection.class.isAssignableFrom(elementType)) { elementType = Collection.class; }else if(Map.class.isAssignableFrom(elementType)) { elementType = Map.class; } if(!elementType.isInstance(value)) { return new IllegalArgumentException(String.format("Wrong argument given: %1$s, expected: %2$s", value.getClass().getTypeName(), elementType.getTypeName()), e); }else { return new IllegalArgumentException(e.getMessage(), e); } } return e; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy