Java Code Examples for gnu.trove.list.array.TIntArrayList#size()

The following examples show how to use gnu.trove.list.array.TIntArrayList#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Convert.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param vertices vertices
 * @param triangleVertexLUT triangleVertexLUT
 *
 * @return vertices
 */
public static float[] convertFromLUT(
		final TFloatArrayList vertices,
		final ArrayList<TIntArrayList> triangleVertexLUT)
{

	final float[] export = new float[triangleVertexLUT.size() * 9];
	int           t      = -1;
	for (final TIntArrayList triangleVertices : triangleVertexLUT)
	{
		final TIntArrayList vertexIndices = triangleVertices;
		for (int i = 0; i < vertexIndices.size(); ++i)
		{
			int vertexIndex = vertexIndices.get(i) * 3;
			export[++t] = vertices.get(vertexIndex);
			export[++t] = vertices.get(++vertexIndex);
			export[++t] = vertices.get(++vertexIndex);
		}
	}
	return export;
}
 
Example 2
Source File: QuestEngine.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
public HandlerResult onItemUseEvent(QuestEnv env, Item item) {
	try {
		TIntArrayList lists = getItemRelatedQuests(item.getItemTemplate().getTemplateId());
		for (int index = 0; index < lists.size(); index++) {
			QuestHandler questHandler = getQuestHandlerByQuestId(lists.get(index));
			if (questHandler != null) {
				env.setQuestId(lists.get(index));
				HandlerResult result = questHandler.onItemUseEvent(env, item);
				// allow other quests to process, the same item can be used not in one quest
				if (result != HandlerResult.UNKNOWN) {
					return result;
				}
			}
		}
		return HandlerResult.UNKNOWN;
	}
	catch (Exception ex) {
		log.error("[QuestEngine] exception in onItemUseEvent - QuestId: " + env.getQuestId() + " Error: ", ex);
		return HandlerResult.FAILED;
	}
}
 
Example 3
Source File: QuestEngine.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
public boolean onKillInWorld(QuestEnv env, int worldId) {
	try {
		if (questOnKillInWorld.containsKey(worldId)) {
			TIntArrayList killInWorldQuests = questOnKillInWorld.get(worldId);
			for (int i = 0; i < killInWorldQuests.size(); i++) {
				QuestHandler questHandler = getQuestHandlerByQuestId(killInWorldQuests.get(i));
				if (questHandler != null) {
					env.setQuestId(killInWorldQuests.get(i));
					questHandler.onKillInWorldEvent(env);
				}
			}
		}
	}
	catch (Exception ex) {
		log.error("[QuestEngine] exception in onKillInWorld - QuestId: " + env.getQuestId() + " Error: ", ex);
		return false;
	}
	return true;
}
 
Example 4
Source File: QuestEngine.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
public boolean onEnterZone(QuestEnv env, ZoneName zoneName) {
	try {
		TIntArrayList lists = getOnEnterZoneQuests(zoneName);
		for (int index = 0; index < lists.size(); index++) {
			QuestHandler questHandler = getQuestHandlerByQuestId(lists.get(index));
			if (questHandler != null) {
				env.setQuestId(lists.get(index));
				questHandler.onEnterZoneEvent(env, zoneName);
			}
		}
	}
	catch (Exception ex) {
		log.error("[QuestEngine] exception in onEnterZone - QuestId: " + env.getQuestId() + " Error: ", ex);
		return false;
	}
	return true;
}
 
Example 5
Source File: QuestEngine.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
public boolean onLeaveZone(QuestEnv env, ZoneName zoneName) {
	try {
		if (questOnLeaveZone.containsKey(zoneName)) {
			TIntArrayList leaveZoneList = questOnLeaveZone.get(zoneName);
			for (int i = 0; i < leaveZoneList.size(); i++) {
				QuestHandler questHandler = getQuestHandlerByQuestId(leaveZoneList.get(i));
				if (questHandler != null) {
					env.setQuestId(leaveZoneList.get(i));
					questHandler.onLeaveZoneEvent(env, zoneName);
				}
			}
		}
	}
	catch (Exception ex) {
		log.error("[QuestEngine] exception in onLeaveZone - QuestId: " + env.getQuestId() + " Error: ", ex);
		return false;
	}
	return true;
}
 
Example 6
Source File: QuestEngine.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
public boolean onMovieEnd(QuestEnv env, int movieId) {
	try {
		TIntArrayList onMovieEndQuests = getOnMovieEndQuests(movieId);
		for (int index = 0; index < onMovieEndQuests.size(); index++) {
			env.setQuestId(onMovieEndQuests.get(index));
			QuestHandler questHandler = getQuestHandlerByQuestId(env.getQuestId());
			if (questHandler != null) {
				if (questHandler.onMovieEndEvent(env, movieId)) {
					return true;
				}
			}
		}
	}
	catch (Exception ex) {
		log.error("[QuestEngine] exception in onMovieEnd - QuestId: " + env.getQuestId() + " Error: ", ex);
	}
	return false;
}
 
Example 7
Source File: QuestEngine.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
public boolean onUseSkill(QuestEnv env, int skillId) {
	try {
		if (questOnUseSkill.containsKey(skillId)) {
			TIntArrayList quests = questOnUseSkill.get(skillId);
			for (int i = 0; i < quests.size(); i++) {
				QuestHandler questHandler = getQuestHandlerByQuestId(quests.get(i));
				if (questHandler != null) {
					env.setQuestId(quests.get(i));
					questHandler.onUseSkillEvent(env, skillId);
				}
			}
		}
	}
	catch (Exception ex) {
		log.error("[QuestEngine] exception in onUseSkill - QuestId: " + env.getQuestId() + " Error: ", ex);
		return false;
	}
	return true;
}
 
Example 8
Source File: QuestEngine.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
public HandlerResult onBonusApplyEvent(QuestEnv env, BonusType bonusType, List<QuestItems> rewardItems) {
	try {
		TIntArrayList lists = this.getOnBonusApplyQuests(bonusType);
		for (int index = 0; index < lists.size(); index++) {
			QuestHandler questHandler = getQuestHandlerByQuestId(lists.get(index));
			if (questHandler != null) {
				env.setQuestId(lists.get(index));
				return questHandler.onBonusApplyEvent(env, bonusType, rewardItems);
			}
		}
		return HandlerResult.UNKNOWN;
	}
	catch (Exception ex) {
		log.error("[QuestEngine] exception in onBonusApply - QuestId: " + env.getQuestId() + " Error: ", ex);
		return HandlerResult.FAILED;
	}
}
 
Example 9
Source File: AudioFingerprint.java    From cineast with MIT License 6 votes vote down vote up
/**
 * This method represents the first step that's executed when processing query. The associated SegmentContainer is
 * examined and feature-vectors are being generated. The generated vectors are returned by this method together with an
 * optional weight-vector.
 *
 * <strong>Important: </strong> The weight-vector must have the same size as the feature-vectors returned by the method.
 *
 * @param sc SegmentContainer that was submitted to the feature module
 * @param qc A QueryConfig object that contains query-related configuration parameters. Can still be edited.
 * @return A pair containing a List of features and an optional weight vector.
 */
@Override
protected List<float[]> preprocessQuery(SegmentContainer sc, ReadableQueryConfig qc) {
    /* Prepare empty list of features. */
    List<float[]> features = new ArrayList<>();

    /* Extract filtered spectrum and create query-vectors. */
    final TIntArrayList filteredSpectrum = this.filterSpectrum(sc);
    final int shift = RANGES.length-1;
    final int lookups = Math.max(1,Math.min(30, filteredSpectrum.size() - FINGERPRINT));

    for (int i=1;i<=lookups;i++) {
        float[] feature = new float[FINGERPRINT];
        for (int j=0; j< FINGERPRINT; j++) {
            if (i * shift + j < filteredSpectrum.size()) {
                feature[j] = filteredSpectrum.get(i * shift + j);
            }
        }
        features.add(feature);
    }
    return features;
}
 
Example 10
Source File: QuestEngine.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public void onPassFlyingRing(QuestEnv env, String FlyRing) {
	try {
		TIntArrayList lists = getOnPassFlyingRingsQuests(FlyRing);
		for (int index = 0; index < lists.size(); index++) {
			QuestHandler questHandler = getQuestHandlerByQuestId(lists.get(index));
			if (questHandler != null) {
				env.setQuestId(lists.get(index));
				questHandler.onPassFlyingRingEvent(env, FlyRing);
			}
		}
	}
	catch (Exception ex) {
		log.error("[QuestEngine] exception in onPassFlyingRing - QuestId: " + env.getQuestId() + " Error: ", ex);
	}
}
 
Example 11
Source File: SFMDemo.java    From COMP3204 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
FeatureTable filterNonTracked(FeatureTable ft) {
	final int nFrames = ft.features.size();
	final TIntArrayList tracksToRemove = new TIntArrayList();

	for (int i = 0; i < ft.nFeatures; i++) {
		int sum = 0;

		for (int f = 1; f < nFrames; f++) {
			sum += ft.features.get(f).get(i).val;
		}

		if (sum != 0) {
			tracksToRemove.add(i);
		}
	}

	final FeatureTable filtered = new FeatureTable(ft.nFeatures - tracksToRemove.size());
	for (int f = 0; f < nFrames; f++) {
		final FeatureList fl = new FeatureList(filtered.nFeatures);

		for (int i = 0, j = 0; i < ft.nFeatures; i++) {
			if (!tracksToRemove.contains(i))
				fl.features[j++] = ft.features.get(f).get(i);
		}
		filtered.storeFeatureList(fl, f);
	}

	return filtered;
}
 
Example 12
Source File: StrictHackathonAlgorithm.java    From htm.java-examples with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns a random, sorted, and  unique array of the specified sample size of
 * selections from the specified list of choices.
 *
 * @param sampleSize the number of selections in the returned sample
 * @param choices    the list of choices to select from
 * @param random     a random number generator
 * @return a sample of numbers of the specified size
 */
int[] sample(int sampleSize, TIntArrayList choices, Random random) {
    TIntHashSet temp = new TIntHashSet();
    int upperBound = choices.size();
    for (int i = 0; i < sampleSize; i++) {
        int randomIdx = random.nextInt(upperBound);
        while (temp.contains(choices.get(randomIdx))) {
            randomIdx = random.nextInt(upperBound);
        }
        temp.add(choices.get(randomIdx));
    }
    TIntArrayList al = new TIntArrayList(temp);
    al.sort();
    return al.toArray();
}
 
Example 13
Source File: FoxEatsDemo.java    From htm.java-examples with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns a random, sorted, and  unique array of the specified sample size of
 * selections from the specified list of choices.
 *
 * @param sampleSize the number of selections in the returned sample
 * @param choices    the list of choices to select from
 * @param random     a random number generator
 * @return a sample of numbers of the specified size
 */
int[] sample(int sampleSize, TIntArrayList choices, Random random) {
    TIntHashSet temp = new TIntHashSet();
    int upperBound = choices.size();
    for (int i = 0; i < sampleSize; i++) {
        int randomIdx = random.nextInt(upperBound);
        while (temp.contains(choices.get(randomIdx))) {
            randomIdx = random.nextInt(upperBound);
        }
        temp.add(choices.get(randomIdx));
    }
    TIntArrayList al = new TIntArrayList(temp);
    al.sort();
    return al.toArray();
}
 
Example 14
Source File: ArrayUtils.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns a random, sorted, and  unique array of the specified sample size of
 * selections from the specified list of choices.
 *
 * @param sampleSize the number of selections in the returned sample
 * @param choices    the list of choices to select from
 * @param random     a random number generator
 * @return a sample of numbers of the specified size
 */
public static int[] sample(TIntArrayList choices, int[] selectedIndices, Random random) {
    TIntArrayList choiceSupply = new TIntArrayList(choices);
    int upperBound = choices.size();
    for (int i = 0; i < selectedIndices.length; i++) {
        int randomIdx = random.nextInt(upperBound);
        selectedIndices[i] = (choiceSupply.removeAt(randomIdx));
        upperBound--;
    }
    Arrays.sort(selectedIndices);
    //System.out.println("sample: " + Arrays.toString(selectedIndices));
    return selectedIndices;
}
 
Example 15
Source File: NodeBreakerVoltageLevel.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public boolean isValid(UndirectedGraph<? extends TerminalExt, SwitchImpl> graph, TIntArrayList nodes, List<NodeTerminal> terminals) {
    int feederCount = 0;
    int branchCount = 0;
    int busbarSectionCount = 0;
    for (int i = 0; i < nodes.size(); i++) {
        int node = nodes.get(i);
        TerminalExt terminal = graph.getVertexObject(node);
        if (terminal != null) {
            AbstractConnectable connectable = terminal.getConnectable();
            switch (connectable.getType()) {
                case LINE:
                case TWO_WINDINGS_TRANSFORMER:
                case THREE_WINDINGS_TRANSFORMER:
                case HVDC_CONVERTER_STATION:
                case DANGLING_LINE:
                    branchCount++;
                    feederCount++;
                    break;

                case LOAD:
                case GENERATOR:
                case BATTERY:
                case SHUNT_COMPENSATOR:
                case STATIC_VAR_COMPENSATOR:
                    feederCount++;
                    break;

                case BUSBAR_SECTION:
                    busbarSectionCount++;
                    break;

                default:
                    throw new AssertionError();
            }
        }
    }
    return (busbarSectionCount >= 1 && feederCount >= 1)
            || (branchCount >= 1 && feederCount >= 2);
}
 
Example 16
Source File: UniversalRandom.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns a random, sorted, and  unique list of the specified sample size of
 * selections from the specified list of choices.
 * 
 * @param choices
 * @param selectedIndices
 * @return an array containing a sampling of the specified choices
 */
public int[] sample(TIntArrayList choices, int[] selectedIndices) {
    TIntArrayList choiceSupply = new TIntArrayList(choices);
    int upperBound = choices.size();
    for (int i = 0; i < selectedIndices.length; i++) {
        int randomIdx = nextInt(upperBound);
        selectedIndices[i] = (choiceSupply.removeAt(randomIdx));
        upperBound--;
    }
    Arrays.sort(selectedIndices);
    //System.out.println("sample: " + Arrays.toString(selectedIndices));
    return selectedIndices;
}
 
Example 17
Source File: UndirectedGraphImpl.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void traverse(int v, Traverser traverser, boolean[] encountered) {
    checkVertex(v);
    Objects.requireNonNull(traverser);
    Objects.requireNonNull(encountered);

    if (encountered.length < vertices.size()) {
        throw new PowsyblException("Encountered array is too small");
    }

    TIntArrayList[] adjacencyList = getAdjacencyList();
    TIntArrayList adjacentEdges = adjacencyList[v];
    encountered[v] = true;
    for (int i = 0; i < adjacentEdges.size(); i++) {
        int e = adjacentEdges.getQuick(i);
        Edge<E> edge = edges.get(e);
        int v1 = edge.getV1();
        int v2 = edge.getV2();
        if (!encountered[v1]) {
            if (traverser.traverse(v2, e, v1) == TraverseResult.CONTINUE) {
                encountered[v1] = true;
                traverse(v1, traverser, encountered);
            }
        } else if (!encountered[v2] && traverser.traverse(v1, e, v2) == TraverseResult.CONTINUE) {
            encountered[v2] = true;
            traverse(v2, traverser, encountered);
        }
    }
}
 
Example 18
Source File: UniversalRandom.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
private int[] sampleWithPrintout(TIntArrayList choices, int[] selectedIndices, List<Integer> collectedRandoms) {
    TIntArrayList choiceSupply = new TIntArrayList(choices);
    int upperBound = choices.size();
    for (int i = 0; i < selectedIndices.length; i++) {
        int randomIdx = nextInt(upperBound);
        //System.out.println("randomIdx: " + randomIdx);
        collectedRandoms.add(randomIdx);
        selectedIndices[i] = (choiceSupply.removeAt(randomIdx));
        upperBound--;
    }
    Arrays.sort(selectedIndices);
    return selectedIndices;
}
 
Example 19
Source File: Document.java    From JGibbLabeledLDA with GNU General Public License v2.0 5 votes vote down vote up
public Document(TIntArrayList doc){
    this.length = doc.size();
    this.words = new int[length];
    for (int i = 0; i < length; i++){
        this.words[i] = doc.get(i);
    }
}
 
Example 20
Source File: AbstractMethodResult.java    From PE-HFT-Java with GNU General Public License v3.0 3 votes vote down vote up
public long[] getMillisec(TIntArrayList h, TIntArrayList millisec){
	
	long[] v= new long[h.size()];
	
	for(int i=0; i<h.size();i++)
		v[i] = h.getQuick(i)*3600000L + millisec.getQuick(i);
	
	return v;
	
}