Search in sources :

Example 21 with TLongHashSet

use of gnu.trove.set.hash.TLongHashSet in project OpenTripPlanner by opentripplanner.

the class HashGridSpatialIndex method insert.

public final void insert(LineString geom, final Object item) {
    Coordinate[] coord = geom.getCoordinates();
    final TLongSet keys = new TLongHashSet(coord.length * 8);
    for (int i = 0; i < coord.length - 1; i++) {
        // TODO Cut the segment if longer than bin size
        // to reduce the number of wrong bins
        Envelope env = new Envelope(coord[i], coord[i + 1]);
        visit(env, true, new BinVisitor<T>() {

            @Override
            public boolean visit(List<T> bin, long mapKey) {
                keys.add(mapKey);
                return false;
            }
        });
    }
    keys.forEach(new TLongProcedure() {

        @SuppressWarnings("unchecked")
        @Override
        public boolean execute(long key) {
            // Note: bins have been initialized in the previous visit
            bins.get(key).add((T) item);
            nEntries++;
            return true;
        }
    });
    nObjects++;
}
Also used : Envelope(com.vividsolutions.jts.geom.Envelope) TLongProcedure(gnu.trove.procedure.TLongProcedure) Coordinate(com.vividsolutions.jts.geom.Coordinate) TLongSet(gnu.trove.set.TLongSet) TLongHashSet(gnu.trove.set.hash.TLongHashSet)

Example 22 with TLongHashSet

use of gnu.trove.set.hash.TLongHashSet in project PorkBot by DaMatrix.

the class AudioUtils method init.

public static void init() {
    youTube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer() {

        @Override
        public void initialize(HttpRequest request) {
        }
    }).setApplicationName("youtube-cmdline-search-sample").build();
    devKey = KeyGetter.getDevKey();
    musicManagers = new TSynchronizedLongObjectMap<>(new TLongObjectHashMap<>());
    playerManager = new DefaultAudioPlayerManager();
    AudioSourceManagers.registerRemoteSources(playerManager);
    AudioSourceManagers.registerLocalSource(playerManager);
    PorkBot.timer.schedule(new TimerTask() {

        @Override
        public void run() {
            TLongSet toRemove = new TLongHashSet();
            long now = System.currentTimeMillis();
            musicManagers.forEachEntry((key, value) -> {
                A: {
                    if (value.channel == null) {
                        // System.out.println("Removing guild because: missing channel");
                        toRemove.add(key);
                        break A;
                    }
                    if (value.created + 10000 < now && (value.channel.getMembers().size() < 2 || (value.manager.scheduler.queue.size() == 0 && value.manager.player.getPlayingTrack() == null))) {
                        // nobody's in the channel
                        // System.out.println("Removing guild because: empty");
                        value.manager.player.destroy();
                        value.channel.getGuild().getAudioManager().closeAudioConnection();
                        toRemove.add(key);
                        break A;
                    }
                }
                return true;
            });
            toRemove.forEach(l -> {
                musicManagers.remove(l);
                return true;
            });
            // not sure why or how this is happening, but it does apparently
            List<AudioManager> list = ShardUtils.getConnectedVoice();
            for (AudioManager manager : list) {
                if (manager.getConnectedChannel().getMembers().size() < 2) {
                    manager.closeAudioConnection();
                }
            }
        }
    }, 10000, 5000);
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) LoadingCache(com.google.common.cache.LoadingCache) Member(net.dv8tion.jda.core.entities.Member) TextChannel(net.dv8tion.jda.core.entities.TextChannel) MessageUtils(net.daporkchop.porkbot.util.MessageUtils) ShardUtils(net.daporkchop.porkbot.util.ShardUtils) PorkBot(net.daporkchop.porkbot.PorkBot) HttpRequest(com.google.api.client.http.HttpRequest) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer) TSynchronizedLongObjectMap(gnu.trove.impl.sync.TSynchronizedLongObjectMap) TLongHashSet(gnu.trove.set.hash.TLongHashSet) KeyGetter(net.daporkchop.porkbot.util.KeyGetter) TimerTask(java.util.TimerTask) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) DefaultAudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager) TLongSet(gnu.trove.set.TLongSet) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) AudioManager(net.dv8tion.jda.core.managers.AudioManager) YouTube(com.google.api.services.youtube.YouTube) IOException(java.io.IOException) AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) CacheLoader(com.google.common.cache.CacheLoader) AudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager) TimeUnit(java.util.concurrent.TimeUnit) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) Guild(net.dv8tion.jda.core.entities.Guild) List(java.util.List) SearchListResponse(com.google.api.services.youtube.model.SearchListResponse) AudioSourceManagers(com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers) TLongObjectMap(gnu.trove.map.TLongObjectMap) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) CacheBuilder(com.google.common.cache.CacheBuilder) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) DefaultAudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) YouTube(com.google.api.services.youtube.YouTube) AudioManager(net.dv8tion.jda.core.managers.AudioManager) TimerTask(java.util.TimerTask) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) TLongSet(gnu.trove.set.TLongSet) TLongHashSet(gnu.trove.set.hash.TLongHashSet) List(java.util.List) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer)

Aggregations

TLongHashSet (gnu.trove.set.hash.TLongHashSet)22 ArrayList (java.util.ArrayList)11 RouteDataObject (net.osmand.binary.RouteDataObject)6 TLongSet (gnu.trove.set.TLongSet)5 List (java.util.List)5 TLongArrayList (gnu.trove.list.array.TLongArrayList)4 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)4 TIntArrayList (gnu.trove.list.array.TIntArrayList)3 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)3 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 PriorityQueue (java.util.PriorityQueue)2 TimeUnit (java.util.concurrent.TimeUnit)2 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)2 Node (net.osmand.osm.edit.Node)2 BinaryRoutePlanner (net.osmand.router.BinaryRoutePlanner)2 RouteSegment (net.osmand.router.BinaryRoutePlanner.RouteSegment)2 Async (br.com.brjdevs.java.utils.async.Async)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DiscordBotsAPI (com.github.natanbc.discordbotsapi.DiscordBotsAPI)1