<commit_before>/*
 * Copyright 2014 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.terasology.logic.delay;

import gnu.trove.TCollections;
import gnu.trove.map.TObjectLongMap;
import gnu.trove.map.hash.TObjectLongHashMap;
import gnu.trove.procedure.TObjectLongProcedure;
import org.terasology.entitySystem.Component;
import org.terasology.world.block.ForceBlockActive;

import java.util.HashSet;
import java.util.Set;

/**
 * @author <NAME> <<EMAIL>>
 */
@ForceBlockActive
public final class DelayedActionComponent implements Component {
    private TObjectLongMap<String> actionIdsWakeUp = new TObjectLongHashMap<>();
    private long lowestWakeUp = Long.MAX_VALUE;

    public DelayedActionComponent() {
    }

    public void addActionId(String actionId, long wakeUp) {
        lowestWakeUp = Math.min(lowestWakeUp, wakeUp);
    }

    public void removeActionId(String actionId) {
        final long removedWakeUp = actionIdsWakeUp.remove(actionId);
        if (removedWakeUp == lowestWakeUp) {
            lowestWakeUp = findSmallestWakeUp();
        }
    }

    public Set<String> removeActionsUpTo(final long worldTime) {
        final Set<String> result = new HashSet<>();
        actionIdsWakeUp.forEachEntry(
                new TObjectLongProcedure<String>() {
                    @Override
                    public boolean execute(String actionId, long time) {
                        if (time <= worldTime) {
                            result.add(actionId);
                        }
                        return true;
                    }
                });
        for (String actionId : result) {
            actionIdsWakeUp.remove(actionId);
        }
        lowestWakeUp = findSmallestWakeUp();

        return result;
    }

    public long getLowestWakeUp() {
        return lowestWakeUp;
    }

    private long findSmallestWakeUp() {
        long result = Long.MAX_VALUE;
        for (long value : actionIdsWakeUp.values()) {
            result = Math.min(result, value);
        }
        return result;
    }

    public boolean isEmpty() {
        return actionIdsWakeUp.isEmpty();
    }

    public TObjectLongMap<String> getActionIdsWakeUp() {
        return TCollections.unmodifiableMap(actionIdsWakeUp);
    }
}<commit_msg>Switching Trove map to Map<String, Long>.<commit_after>/*
 * Copyright 2014 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.terasology.logic.delay;

import org.terasology.entitySystem.Component;
import org.terasology.world.block.ForceBlockActive;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author <NAME> <<EMAIL>>
 */
@ForceBlockActive
public final class DelayedActionComponent implements Component {
    private Map<String, Long> actionIdsWakeUp = new HashMap<>();
    private long lowestWakeUp = Long.MAX_VALUE;

    public DelayedActionComponent() {
    }

    public void addActionId(String actionId, long wakeUp) {
        lowestWakeUp = Math.min(lowestWakeUp, wakeUp);
    }

    public void removeActionId(String actionId) {
        final long removedWakeUp = actionIdsWakeUp.remove(actionId);
        if (removedWakeUp == lowestWakeUp) {
            lowestWakeUp = findSmallestWakeUp();
        }
    }

    public Set<String> removeActionsUpTo(final long worldTime) {
        final Set<String> result = new HashSet<>();
        final Iterator<Map.Entry<String, Long>> entryIterator = actionIdsWakeUp.entrySet().iterator();
        while (entryIterator.hasNext()) {
            final Map.Entry<String, Long> entry = entryIterator.next();
            if (entry.getValue() <= worldTime) {
                result.add(entry.getKey());
                entryIterator.remove();
            }
        }
        lowestWakeUp = findSmallestWakeUp();

        return result;
    }

    public long getLowestWakeUp() {
        return lowestWakeUp;
    }

    private long findSmallestWakeUp() {
        long result = Long.MAX_VALUE;
        for (long value : actionIdsWakeUp.values()) {
            result = Math.min(result, value);
        }
        return result;
    }

    public boolean isEmpty() {
        return actionIdsWakeUp.isEmpty();
    }

    public Map<String, Long> getActionIdsWakeUp() {
        return Collections.unmodifiableMap(actionIdsWakeUp);
    }
}
{'fraction_non_alphanumeric': 0.09146229024525171, 'fraction_numerical': 0.0029503964595242486, 'mean_word_length': 2.7692842251563587, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4443890', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1496, 'n_words': 419}