org.freedesktop.gstreamer.glib.NativeFlags Maven / Gradle / Ivy
/*
* Copyright (c) 2020 Neil C Smith
*
* This file is part of gstreamer-java.
*
* This code is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with this work. If not, see .
*/
package org.freedesktop.gstreamer.glib;
import java.util.EnumSet;
import java.util.Set;
/**
* Interface for enums that represent native bit flags.
* @param type of flag enum
*/
public interface NativeFlags> extends NativeEnum {
public static & NativeFlags> int toInt(Set flags) {
int ret = 0;
for (FLAG flag : flags) {
ret |= flag.intValue();
}
return ret;
}
public static & NativeFlags> int toInt(EnumSet flags) {
int ret = 0;
for (FLAG flag : flags) {
ret |= flag.intValue();
}
return ret;
}
public static & NativeFlags> EnumSet
fromInt(Class type, int val) {
EnumSet set = EnumSet.allOf(type);
set.removeIf(f -> ((val & f.intValue()) == 0));
return set;
}
}