Java Code Examples for it.unimi.dsi.fastutil.objects.ObjectArrayList#remove()

The following examples show how to use it.unimi.dsi.fastutil.objects.ObjectArrayList#remove() . 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: FixSingleFunctionArgs.java    From WarpPI with Apache License 2.0 6 votes vote down vote up
@Override
public boolean eval(final IntWrapper curIndex, final Function lastFunction, final Function currentFunction,
		final ObjectArrayList<Function> functionsList) throws Error {
	if (currentFunction instanceof FunctionSingle) {
		if (((FunctionSingle) currentFunction).getParameter() == null) {
			if (lastFunction == null) {
				throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified.");
			} else {
				((FunctionSingle) currentFunction).setParameter(lastFunction);
				functionsList.remove(curIndex.i + 1);
			}
			return true;
		}
	}
	return false;
}
 
Example 2
Source File: AddImplicitMultiplications.java    From WarpPI with Apache License 2.0 6 votes vote down vote up
@Override
public boolean eval(final IntWrapper curIndex, final Function lastFunction, final Function currentFunction,
		final ObjectArrayList<Function> functionsList) {
	if (currentFunction instanceof Function) {
		if (lastFunction instanceof Function) {
			functionsList.set(curIndex.i, new Multiplication(context, currentFunction, lastFunction));
			functionsList.remove(curIndex.i + 1);
			return true;
		}
	} else if (currentFunction instanceof Function) {
		if (lastFunction instanceof Function) {
			functionsList.set(curIndex.i, new Multiplication(context, currentFunction, lastFunction));
			functionsList.remove(curIndex.i + 1);
			return true;
		}
	}
	return false;
}
 
Example 3
Source File: FixMultiplicationsAndDivisions.java    From WarpPI with Apache License 2.0 6 votes vote down vote up
@Override
public boolean eval(final IntWrapper curIndex, final Function lastFunction, final Function currentFunction,
		final ObjectArrayList<Function> functionsList) throws Error {
	if (currentFunction instanceof Multiplication || currentFunction instanceof Division) {
		if (currentFunction.getParameter(0) == null && currentFunction.getParameter(1) == null) {
			if (curIndex.i - 1 >= 0 && curIndex.i + 1 < functionsList.size()) {
				final Function next = functionsList.get(curIndex.i + 1);
				final Function prev = functionsList.get(curIndex.i - 1);
				functionsList.set(curIndex.i, currentFunction.setParameter(0, prev).setParameter(1, next));
				functionsList.remove(curIndex.i + 1);
				functionsList.remove(curIndex.i - 1);
				curIndex.i--;
				return true;
			} else if (currentFunction.getParameter(0) == null || currentFunction.getParameter(1) == null) {
				throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified.");
			}
		}
	}
	return false;
}
 
Example 4
Source File: FixSumsAndSubtractions.java    From WarpPI with Apache License 2.0 6 votes vote down vote up
@Override
public boolean eval(final IntWrapper curIndex, final Function lastFunction, final Function currentFunction,
		final ObjectArrayList<Function> functionsList) throws Error {
	if (currentFunction instanceof Sum || currentFunction instanceof Subtraction || currentFunction instanceof SumSubtraction) {
		if (currentFunction.getParameter(0) == null && currentFunction.getParameter(1) == null) {
			if (curIndex.i - 1 >= 0 && curIndex.i + 1 < functionsList.size()) {
				final Function next = functionsList.get(curIndex.i + 1);
				final Function prev = functionsList.get(curIndex.i - 1);
				functionsList.set(curIndex.i, currentFunction.setParameter(0, prev).setParameter(1, next));
				functionsList.remove(curIndex.i + 1);
				functionsList.remove(curIndex.i - 1);
				curIndex.i--;
				return true;
			} else if (currentFunction.getParameter(0) == null || currentFunction.getParameter(1) == null) {
				throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified.");
			}
		}
	}
	return false;
}
 
Example 5
Source File: Phrase.java    From minie with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Given a list of words 'words', replace all of them with one word 'w'
 * @param words: the list of words to be replaced with one word
 * @param w: the word replacing the sublist
 */
public void replaceWordsWithOneWord(ObjectArrayList<IndexedWord> words, IndexedWord w){
    // If the list of words is empty, return (nothing to replace)
    if (words.size() == 0)
        return;
    
    // Replace the first word from the list with the replacing word, then drop it from the list, then remove the rest
    int firstWordInd = this.getWordList().indexOf(words.get(0));
    if (firstWordInd == -1)
        return;
    this.setWordInWordList(firstWordInd, w);
    words.remove(0);
    if (words.size() > 0)
        this.removeWordsFromList(words);
}
 
Example 6
Source File: JoinNumberAndVariables.java    From WarpPI with Apache License 2.0 5 votes vote down vote up
@Override
public boolean eval(final IntWrapper curIndex, final Function lastFunction, final Function currentFunction,
		final ObjectArrayList<Function> functionsList) {
	if (currentFunction instanceof Number | currentFunction instanceof Variable | currentFunction instanceof Division) {
		if (lastFunction instanceof Variable | lastFunction instanceof Number | (lastFunction instanceof Multiplication && ((Multiplication) lastFunction).getParameter2() != null)) {
			final Function a = currentFunction;
			final Function b = lastFunction;
			functionsList.set(curIndex.i, new Multiplication(context, a, b));
			functionsList.remove(curIndex.i + 1);
			return true;
		}
	}
	return false;
}
 
Example 7
Source File: RemoveParentheses.java    From WarpPI with Apache License 2.0 5 votes vote down vote up
@Override
public boolean eval(final IntWrapper curIndex, final Function lastFunction, final Function currentFunction,
		final ObjectArrayList<Function> functionsList) {
	if (currentFunction instanceof Expression) {
		if (((Expression) currentFunction).getParameter() == null) {
			functionsList.remove(curIndex.i);
		} else {
			functionsList.set(curIndex.i, ((Expression) currentFunction).getParameter());
		}
		return true;
	}
	return false;
}