org.gnome.gtk.StringSorter Maven / Gradle / Ivy
// This file was automatically generated by Java-GI. Do not edit this file
// directly! Visit for more information.
//
// The API documentation in this file was derived from GObject-Introspection
// metadata and may include text or comments from the original C sources.
//
// Copyright (c), upstream authors as identified in the GObject-Introspection
// metadata.
//
// This generated file is distributed under the same license as the original
// GObject-Introspection data, unless otherwise specified. Users of this file
// are responsible for complying with any licenses or terms required by the
// original authors.
//
// THIS FILE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
//
package org.gnome.gtk;
import io.github.jwharm.javagi.gobject.InstanceCache;
import io.github.jwharm.javagi.gobject.types.Types;
import io.github.jwharm.javagi.interop.Interop;
import io.github.jwharm.javagi.interop.MemoryCleaner;
import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.MethodHandle;
import javax.annotation.processing.Generated;
import org.gnome.glib.Type;
import org.gnome.gobject.GObject;
import org.gnome.gobject.Value;
import org.jetbrains.annotations.Nullable;
/**
* {@code GtkStringSorter} is a {@code GtkSorter} that compares strings.
*
* It does the comparison in a linguistically correct way using the
* current locale by normalizing Unicode strings and possibly case-folding
* them before performing the comparison.
*
* To obtain the strings to compare, this sorter evaluates a
* {@link Expression}.
*/
@Generated("io.github.jwharm.JavaGI")
public class StringSorter extends Sorter {
static {
Gtk.javagi$ensureInitialized();
}
/**
* Create a StringSorter proxy instance for the provided memory address.
*
* @param address the memory address of the native object
*/
public StringSorter(MemorySegment address) {
super(Interop.reinterpret(address, getMemoryLayout().byteSize()));
}
/**
* Creates a new string sorter that compares items using the given
* {@code expression}.
*
* Unless an expression is set on it, this sorter will always
* compare items as invalid.
*
* @param expression The expression to evaluate
*/
public StringSorter(@Nullable Expression expression) {
this(constructNew(expression));
InstanceCache.put(handle(), this);
}
/**
* Calls {@link StringSorter#StringSorter(org.gnome.gtk.Expression)} with expression = {@code null}
*/
public StringSorter() {
this((Expression) null);
}
/**
* Get the GType of the StringSorter class
*
* @return the GType
*/
public static Type getType() {
return Interop.getType("gtk_string_sorter_get_type");
}
/**
* Returns this instance as if it were its parent type. This is mostly
* synonymous to the Java {@code super} keyword, but will set the native
* typeclass function pointers to the parent type. When overriding a native
* virtual method in Java, "chaining up" with {@code super.methodName()}
* doesn't work, because it invokes the overridden function pointer again.
* To chain up, call {@code asParent().methodName()}. This will call the
* native function pointer of this virtual method in the typeclass of the
* parent type.
*/
protected StringSorter asParent() {
StringSorter _parent = new StringSorter(handle());
_parent.callParent(true);
return _parent;
}
private static MemorySegment constructNew(@Nullable Expression expression) {
if (expression != null) MemoryCleaner.yieldOwnership(expression);
MemorySegment _result;
try {
_result = (MemorySegment) MethodHandles.gtk_string_sorter_new.invokeExact(
(MemorySegment) (expression == null ? MemorySegment.NULL : expression.handle()));
} catch (Throwable _err) {
throw new AssertionError(_err);
}
return _result;
}
/**
* Gets which collation method the sorter uses.
*
* @return The collation method
*/
public Collation getCollation() {
int _result;
try {
_result = (int) MethodHandles.gtk_string_sorter_get_collation.invokeExact(handle());
} catch (Throwable _err) {
throw new AssertionError(_err);
}
return Collation.of(_result);
}
/**
* Gets the expression that is evaluated to obtain strings from items.
*
* @return a {@code GtkExpression}
*/
public Expression getExpression() {
MemorySegment _result;
try {
_result = (MemorySegment) MethodHandles.gtk_string_sorter_get_expression.invokeExact(
handle());
} catch (Throwable _err) {
throw new AssertionError(_err);
}
return (Expression) InstanceCache.getForType(_result, Expression.ExpressionImpl::new, true);
}
/**
* Gets whether the sorter ignores case differences.
*
* @return {@code true} if this StringSorter is ignoring case differences
*/
public boolean getIgnoreCase() {
int _result;
try {
_result = (int) MethodHandles.gtk_string_sorter_get_ignore_case.invokeExact(handle());
} catch (Throwable _err) {
throw new AssertionError(_err);
}
return _result != 0;
}
/**
* Sets the collation method to use for sorting.
*
* @param collation the collation method
*/
public void setCollation(Collation collation) {
try {
MethodHandles.gtk_string_sorter_set_collation.invokeExact(handle(),
collation.getValue());
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
/**
* Sets the expression that is evaluated to obtain strings from items.
*
* The expression must have the type {@code G_TYPE_STRING}.
*
* @param expression a {@code GtkExpression}
*/
public void setExpression(@Nullable Expression expression) {
try {
MethodHandles.gtk_string_sorter_set_expression.invokeExact(handle(),
(MemorySegment) (expression == null ? MemorySegment.NULL : expression.handle()));
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
/**
* Sets whether the sorter will ignore case differences.
*
* @param ignoreCase {@code true} to ignore case differences
*/
public void setIgnoreCase(boolean ignoreCase) {
try {
MethodHandles.gtk_string_sorter_set_ignore_case.invokeExact(handle(),
ignoreCase ? 1 : 0);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
/**
* A {@link Builder} object constructs a {@code StringSorter}
* with the specified properties.
* Use the various {@code set...()} methods to set properties,
* and finish construction with {@link Builder#build()}.
*/
public static Builder extends Builder> builder() {
return new Builder<>();
}
public static class StringSorterClass extends Sorter.SorterClass {
/**
* Create a StringSorterClass proxy instance for the provided memory address.
*
* @param address the memory address of the native object
*/
public StringSorterClass(MemorySegment address) {
super(Interop.reinterpret(address, getMemoryLayout().byteSize()));
}
/**
* Allocate a new StringSorterClass.
*
* @param arena to control the memory allocation scope
*/
public StringSorterClass(Arena arena) {
super(arena.allocate(getMemoryLayout()));
}
/**
* Allocate a new StringSorterClass.
* The memory is allocated with {@link Arena#ofAuto}.
*/
public StringSorterClass() {
super(Arena.ofAuto().allocate(getMemoryLayout()));
}
/**
* The memory layout of the native struct.
* @return the memory layout
*/
public static MemoryLayout getMemoryLayout() {
return MemoryLayout.structLayout(
Sorter.SorterClass.getMemoryLayout().withName("parent_class")
).withName("GtkStringSorterClass");
}
}
/**
* Inner class implementing a builder pattern to construct a GObject with
* properties.
*
* @param the type of the Builder that is returned
*/
public static class Builder> extends Sorter.Builder {
/**
* Default constructor for a {@code Builder} object.
*/
protected Builder() {
}
/**
* Finish building the {@code StringSorter} object. This will call
* {@link GObject#withProperties} to create a new GObject instance,
* which is then cast to {@code StringSorter}.
*
* @return a new instance of {@code StringSorter} with the properties
* that were set in the Builder object.
*/
public StringSorter build() {
try {
var _instance = (StringSorter) GObject.withProperties(StringSorter.getType(), getNames(), getValues());
connectSignals(_instance.handle());
return _instance;
} finally {
for (Value _value : getValues()) _value.unset();
getArena().close();
}
}
/**
* The collation method to use for sorting.
*
* The {@code GTK_COLLATION_NONE} value is useful when the expression already
* returns collation keys, or strings that need to be compared byte-by-byte.
*
* The default value, {@code GTK_COLLATION_UNICODE}, compares strings according
* to the Unicode collation algorithm.
*
* @param collation the value for the {@code collation} property
* @return the {@code Builder} instance is returned, to allow method chaining
*/
public B setCollation(Collation collation) {
Arena _arena = getArena();
Value _value = new Value(_arena);
_value.init(Collation.getType());
_value.setEnum(collation.getValue());
addBuilderProperty("collation", _value);
return (B) this;
}
/**
* The expression to evaluate on item to get a string to compare with.
*
* @param expression the value for the {@code expression} property
* @return the {@code Builder} instance is returned, to allow method chaining
*/
public B setExpression(Expression expression) {
Arena _arena = getArena();
Value _value = new Value(_arena);
_value.init(Expression.getType());
Gtk.valueSetExpression(_value, expression);
addBuilderProperty("expression", _value);
return (B) this;
}
/**
* If sorting is case sensitive.
*
* @param ignoreCase the value for the {@code ignore-case} property
* @return the {@code Builder} instance is returned, to allow method chaining
*/
public B setIgnoreCase(boolean ignoreCase) {
Arena _arena = getArena();
Value _value = new Value(_arena);
_value.init(Types.BOOLEAN);
_value.setBoolean(ignoreCase);
addBuilderProperty("ignore-case", _value);
return (B) this;
}
}
private static final class MethodHandles {
static final MethodHandle gtk_string_sorter_new = Interop.downcallHandle(
"gtk_string_sorter_new", FunctionDescriptor.of(ValueLayout.ADDRESS,
ValueLayout.ADDRESS), false);
static final MethodHandle gtk_string_sorter_get_collation = Interop.downcallHandle(
"gtk_string_sorter_get_collation", FunctionDescriptor.of(ValueLayout.JAVA_INT,
ValueLayout.ADDRESS), false);
static final MethodHandle gtk_string_sorter_get_expression = Interop.downcallHandle(
"gtk_string_sorter_get_expression", FunctionDescriptor.of(ValueLayout.ADDRESS,
ValueLayout.ADDRESS), false);
static final MethodHandle gtk_string_sorter_get_ignore_case = Interop.downcallHandle(
"gtk_string_sorter_get_ignore_case", FunctionDescriptor.of(ValueLayout.JAVA_INT,
ValueLayout.ADDRESS), false);
static final MethodHandle gtk_string_sorter_set_collation = Interop.downcallHandle(
"gtk_string_sorter_set_collation", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS,
ValueLayout.JAVA_INT), false);
static final MethodHandle gtk_string_sorter_set_expression = Interop.downcallHandle(
"gtk_string_sorter_set_expression", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS,
ValueLayout.ADDRESS), false);
static final MethodHandle gtk_string_sorter_set_ignore_case = Interop.downcallHandle(
"gtk_string_sorter_set_ignore_case", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS,
ValueLayout.JAVA_INT), false);
}
}