Please wait. This can take some minutes ...
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.
io.qt.core.QStack Maven / Gradle / Ivy
Go to download
QtJambi base module containing QtCore, QtGui and QtWidgets.
/****************************************************************************
**
** 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.nio.*;
import java.util.*;
import io.qt.*;
import io.qt.*;
/**
* Java wrapper for Qt class QStack
* QStack will no longer implement Deque interface if compiled with Java 21.
* Instead call {@link asDeque()} to get a Deque wrapper for the stack.
*/
public class QStack extends QList implements Queue, Deque
{
/**
* Creating a container with given element type and size.
* See QStack::QStack()
* @param metaType the type T
*/
public QStack(@StrictNonNull QMetaType metaType) {
super(metaType);
}
/**
* Creating a container with given element type and size.
* See QStack::QStack()
* @param metaType the type T
*/
public QStack(QMetaType.@StrictNonNull Type metaType) {
this(new QMetaType(metaType));
}
/**
* Creating a container with given element type.
* See QStack::QStack()
* @param elementType the type T
*/
public QStack(@Nullable Class elementType) {
super(elementType);
}
/**
* Creating a container with given content.
* See QStack::QStack(const QStack<T> &)
* @param other container
*/
public QStack(@StrictNonNull Collection other) {
super(other);
}
@NativeAccess
private QStack(QMetaType elementMetaType, Collection other) {
super(elementMetaType, other);
}
/**
* Creating a container of type QVariant.
*/
public static @NonNull QStack createVariantStack(){
return new QStack<>(new QMetaType(QMetaType.Type.QVariant));
}
/**
* Creates and returns a copy of this object.
* See QStack::QStack(const QStack<T> &)
*/
@Override
public @NonNull QStack clone(){
return new QStack<>(this);
}
/**
* Constructor for internal use only.
* @param p expected to be null
.
* @hidden
*/
@NativeAccess
protected QStack(QPrivateConstructor p){
super(p);
}
/**
* @see Deque#remove()
*/
@Override
@QtUninvokable
public final T remove() {
return takeFirst();
}
/**
* @see Deque#addFirst(Object)
*/
@Override
@QtUninvokable
public final void addFirst(T e) {
push(e);
}
/**
* @see Deque#addLast(Object)
*/
@Override
@QtUninvokable
public final void addLast(T e) {
add(e);
}
/**
* @see Deque#offerFirst(Object)
*/
@Override
@QtUninvokable
public final boolean offerFirst(T e) {
push(e);
return true;
}
/**
* @see Deque#offerLast(Object)
*/
@Override
@QtUninvokable
public final boolean offerLast(T e) {
add(e);
return true;
}
/**
* @see Deque#pollFirst()
*/
@Override
@QtUninvokable
public final T pollFirst() {
if(size()==0)
return null;
return pop();
}
/**
* @see Deque#pollLast()
*/
@Override
@QtUninvokable
public final T pollLast() {
if(size()==0)
return null;
T e = takeLast();
return e;
}
/**
* @see Deque#getFirst()
*/
@Override
@QtUninvokable
public final T getFirst() {
if(size()==0)
throw new NoSuchElementException();
return peekFirst();
}
/**
* @see Deque#getLast()
*/
@Override
@QtUninvokable
public final T getLast() {
if(size()==0)
throw new NoSuchElementException();
return peekLast();
}
/**
* @see Deque#poll()
*/
@Override
@QtUninvokable
public final T poll() {
return pollFirst();
}
/**
* @see Deque#element()
*/
@Override
@QtUninvokable
public final T element() {
return getFirst();
}
/**
* @see Deque#peek()
*/
@Override
@QtUninvokable
public final T peek() {
return peekFirst();
}
/**
* @see Deque#offer(Object)
*/
@Override
@QtUninvokable
public final boolean offer(T e) {
return offerLast(e);
}
/**
* @see Deque#removeFirstOccurrence(Object)
*/
@Override
@QtUninvokable
public final boolean removeFirstOccurrence(Object o) {
int idx = indexOf(o);
return idx>=0 && idx=0 && idx descendingIterator() {
return constEnd().toJavaDescendingIterator();
}
/**
* @see Deque#peekFirst()
*/
@Override
@QtUninvokable
public final T peekFirst() {
return first();
}
/**
* Creates and returns a copy of this object.
* See QStack::top()const
*/
@QtUninvokable
public final T top() {
return last();
}
/**
* @see Deque#peekLast()
*/
@Override
@QtUninvokable
public final T peekLast() {
return last();
}
/**
* See QStack::push(T)
* @see Deque#push(Object)
*/
@Override
@QtUninvokable
public final void push(T e) {
add(e);
}
/**
* See QStack::pop()
* @see Deque#pop()
*/
@Override
@QtUninvokable
public final T pop() {
return takeLast();
}
/**
* Due to changes in Java 21 QStack does no longer implement Deque interface.
* Instead call {@link asDeque()} to get a Deque wrapper for the stack.
* @return Deque wrapper
* @since 6.6.1
*/
@QtUninvokable
public final @NonNull Deque asDeque(){
return new StackDeque<>(this);
}
/**
* Returns a QStack containing given elements.
*
* @param the {@code QStack}'s element type
* @param element0 the first element
* @param elements subsequent elements
* @return a {@code QStack} containing the specified element
* @throws NullPointerException if elements are {@code null}
*
*/
@SafeVarargs
public static @NonNull QStack of(T element0, T @StrictNonNull...elements) {
QMetaType metaType = findElementMetaType(element0, elements);
@SuppressWarnings("unchecked")
T[] allElements = (T[])new Object[elements.length+1];
System.arraycopy(elements, 0, allElements, 1, elements.length);
allElements[0] = element0;
return ofTyped(metaType, allElements);
}
/**
* Returns a QStack containing given elements.
*
* @param elements
* @return a {@code QStack} containing the specified element
*/
public static @NonNull QStack<@QtPrimitiveType@NonNull Byte> ofByte(byte @StrictNonNull...elements) {
QStack result = new QStack<>(byte.class);
result.resize(elements.length);
ByteBuffer data = QtJambi_LibraryUtilities.internal.mutableDataB(result);
data.put(elements, 0, elements.length);
QtJambi_LibraryUtilities.internal.truncateBuffer(result, data);
return result;
}
/**
* Returns a QStack containing given elements.
*
* @param elements
* @return a {@code QStack} containing the specified element
*/
public static @NonNull QStack<@QtPrimitiveType@NonNull Short> ofShort(short @StrictNonNull...elements) {
QStack result = new QStack<>(short.class);
result.resize(elements.length);
ShortBuffer data = QtJambi_LibraryUtilities.internal.mutableDataS(result);
data.put(elements, 0, elements.length);
QtJambi_LibraryUtilities.internal.truncateBuffer(result, data);
return result;
}
/**
* Returns a QStack containing given elements.
*
* @param elements
* @return a {@code QStack} containing the specified element
*/
public static @NonNull QStack<@QtPrimitiveType@NonNull Integer> ofInt(int @StrictNonNull...elements) {
QStack result = new QStack<>(int.class);
result.resize(elements.length);
IntBuffer data = QtJambi_LibraryUtilities.internal.mutableDataI(result);
data.put(elements, 0, elements.length);
QtJambi_LibraryUtilities.internal.truncateBuffer(result, data);
return result;
}
/**
* Returns a QStack containing given elements.
*
* @param elements
* @return a {@code QStack} containing the specified element
*/
public static @NonNull QStack<@QtPrimitiveType@NonNull Long> ofLong(long @StrictNonNull...elements) {
QStack result = new QStack<>(long.class);
result.resize(elements.length);
LongBuffer data = QtJambi_LibraryUtilities.internal.mutableDataJ(result);
data.put(elements, 0, elements.length);
QtJambi_LibraryUtilities.internal.truncateBuffer(result, data);
return result;
}
/**
* Returns a QStack containing given elements.
*
* @param elements
* @return a {@code QStack} containing the specified element
*/
public static @NonNull QStack<@QtPrimitiveType@NonNull Character> ofChar(char @StrictNonNull...elements) {
QStack result = new QStack<>(char.class);
result.resize(elements.length);
CharBuffer data = QtJambi_LibraryUtilities.internal.mutableDataC(result);
data.put(elements, 0, elements.length);
QtJambi_LibraryUtilities.internal.truncateBuffer(result, data);
return result;
}
/**
* Returns a QStack containing given elements.
*
* @param elements
* @return a {@code QStack} containing the specified element
*/
public static @NonNull QStack<@QtPrimitiveType@NonNull Float> ofFloat(float @StrictNonNull...elements) {
QStack result = new QStack<>(float.class);
result.resize(elements.length);
FloatBuffer data = QtJambi_LibraryUtilities.internal.mutableDataF(result);
data.put(elements, 0, elements.length);
QtJambi_LibraryUtilities.internal.truncateBuffer(result, data);
return result;
}
/**
* Returns a QStack containing given elements.
*
* @param elements
* @return a {@code QStack} containing the specified element
*/
public static @NonNull QStack<@QtPrimitiveType@NonNull Double> ofDouble(double @StrictNonNull...elements) {
QStack result = new QStack<>(double.class);
result.resize(elements.length);
DoubleBuffer data = QtJambi_LibraryUtilities.internal.mutableDataD(result);
data.put(elements, 0, elements.length);
QtJambi_LibraryUtilities.internal.truncateBuffer(result, data);
return result;
}
/**
* Returns a QStack containing given elements.
*
* @param elements
* @return a {@code QStack} containing the specified element
*/
public static @NonNull QStack<@QtPrimitiveType@NonNull Boolean> ofBoolean(boolean @StrictNonNull...elements) {
QStack result = new QStack<>(boolean.class);
result.reserve(elements.length);
for (boolean t : elements) {
result.append(t);
}
return result;
}
/**
* Returns a QStack containing given elements.
*
* @param elements
* @return a {@code QStack} containing the specified element
*/
public static @NonNull QStack<@QtPrimitiveType@NonNull Byte> ofBuffer(@StrictNonNull ByteBuffer elements) {
QStack result = new QStack<>(byte.class);
result.resize(elements.remaining());
ByteBuffer data = QtJambi_LibraryUtilities.internal.mutableDataB(result);
data.put(elements);
QtJambi_LibraryUtilities.internal.truncateBuffer(result, data);
return result;
}
/**
* Returns a QStack containing given elements.
*
* @param elements
* @return a {@code QStack} containing the specified element
*/
public static @NonNull QStack<@QtPrimitiveType@NonNull Short> ofBuffer(@StrictNonNull ShortBuffer elements) {
QStack result = new QStack<>(short.class);
result.resize(elements.remaining());
ShortBuffer data = QtJambi_LibraryUtilities.internal.mutableDataS(result);
data.put(elements);
QtJambi_LibraryUtilities.internal.truncateBuffer(result, data);
return result;
}
/**
* Returns a QStack containing given elements.
*
* @param elements
* @return a {@code QStack} containing the specified element
*/
public static @NonNull QStack<@QtPrimitiveType@NonNull Integer> ofBuffer(@StrictNonNull IntBuffer elements) {
QStack result = new QStack<>(int.class);
result.resize(elements.remaining());
IntBuffer data = QtJambi_LibraryUtilities.internal.mutableDataI(result);
data.put(elements);
QtJambi_LibraryUtilities.internal.truncateBuffer(result, data);
return result;
}
/**
* Returns a QStack containing given elements.
*
* @param elements
* @return a {@code QStack} containing the specified element
*/
public static @NonNull QStack<@QtPrimitiveType@NonNull Long> ofBuffer(@StrictNonNull LongBuffer elements) {
QStack result = new QStack<>(long.class);
result.resize(elements.remaining());
LongBuffer data = QtJambi_LibraryUtilities.internal.mutableDataJ(result);
data.put(elements);
QtJambi_LibraryUtilities.internal.truncateBuffer(result, data);
return result;
}
/**
* Returns a QStack containing given elements.
*
* @param elements
* @return a {@code QStack} containing the specified element
*/
public static @NonNull QStack<@QtPrimitiveType@NonNull Character> ofBuffer(@StrictNonNull CharBuffer elements) {
QStack result = new QStack<>(char.class);
result.resize(elements.remaining());
CharBuffer data = QtJambi_LibraryUtilities.internal.mutableDataC(result);
data.put(elements);
QtJambi_LibraryUtilities.internal.truncateBuffer(result, data);
return result;
}
/**
* Returns a QStack containing given elements.
*
* @param elements
* @return a {@code QStack} containing the specified element
*/
public static @NonNull QStack<@QtPrimitiveType@NonNull Float> ofBuffer(@StrictNonNull FloatBuffer elements) {
QStack result = new QStack<>(float.class);
result.resize(elements.remaining());
FloatBuffer data = QtJambi_LibraryUtilities.internal.mutableDataF(result);
data.put(elements);
QtJambi_LibraryUtilities.internal.truncateBuffer(result, data);
return result;
}
/**
* Returns a QStack containing given elements.
*
* @param elements
* @return a {@code QStack} containing the specified element
*/
public static @NonNull QStack<@QtPrimitiveType@NonNull Double> ofBuffer(@StrictNonNull DoubleBuffer elements) {
QStack result = new QStack<>(double.class);
result.resize(elements.remaining());
DoubleBuffer data = QtJambi_LibraryUtilities.internal.mutableDataD(result);
data.put(elements);
QtJambi_LibraryUtilities.internal.truncateBuffer(result, data);
return result;
}
/**
* Returns a QStack containing given elements.
*
* @param the {@code QStack}'s element type
* @param type the {@code QStack}'s element type
* @param elements all list elements to be added
* @return a {@code QStack} containing the specified element
*
*/
@SafeVarargs
public static @NonNull QStack ofTyped(@Nullable Class super T> type, T @StrictNonNull...elements) {
QMetaType metaType = QList.findElementMetaType(type, elements);
return ofTyped(metaType, elements);
}
/**
* Returns a QStack containing given elements.
*
* @param the {@code QStack}'s element type
* @param metaType the {@code QStack}'s element type
* @param elements all list elements to be added
* @return a {@code QStack} containing the specified element
*
*/
@SafeVarargs
public static @NonNull QStack ofTyped(@StrictNonNull QMetaType metaType, T @StrictNonNull...elements) {
if(metaType.id()==0)
throw new IllegalArgumentException("QMetaType::UnknownType cannot be type of QStack.");
if(metaType.id()==QMetaType.Type.Void.value())
throw new IllegalArgumentException("void cannot be type of QStack.");
return new QStack<>(metaType, Arrays.asList(elements));
}
}