Java Code Examples for org.apache.commons.lang3.ArrayUtils.add()

The following are Jave code examples for showing how to use add() of the org.apache.commons.lang3.ArrayUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: BaseClient   File: GameSettings.java   View Source Code Vote up 6 votes
public GameSettings(Minecraft mcIn, File p_i46326_2_)
{
    this.keyBindings = (KeyBinding[])((KeyBinding[])ArrayUtils.addAll(new KeyBinding[] {this.keyBindAttack, this.keyBindUseItem, this.keyBindForward, this.keyBindLeft, this.keyBindBack, this.keyBindRight, this.keyBindJump, this.keyBindSneak, this.keyBindSprint, this.keyBindDrop, this.keyBindInventory, this.keyBindChat, this.keyBindPlayerList, this.keyBindPickBlock, this.keyBindCommand, this.keyBindScreenshot, this.keyBindTogglePerspective, this.keyBindSmoothCamera, this.keyBindStreamStartStop, this.keyBindStreamPauseUnpause, this.keyBindStreamCommercials, this.keyBindStreamToggleMic, this.keyBindFullscreen, this.keyBindSpectatorOutlines}, this.keyBindsHotbar));
    this.difficulty = EnumDifficulty.NORMAL;
    this.lastServer = "";
    this.fovSetting = 70.0F;
    this.language = "en_US";
    this.forceUnicodeFont = false;
    this.mc = mcIn;
    this.optionsFile = new File(p_i46326_2_, "options.txt");
    this.optionsFileOF = new File(p_i46326_2_, "optionsof.txt");
    this.limitFramerate = (int)GameSettings.Options.FRAMERATE_LIMIT.getValueMax();
    this.ofKeyBindZoom = new KeyBinding("of.key.zoom", 46, "key.categories.misc");
    this.keyBindings = (KeyBinding[])((KeyBinding[])ArrayUtils.add(this.keyBindings, this.ofKeyBindZoom));
    GameSettings.Options.RENDER_DISTANCE.setValueMax(32.0F);
    this.renderDistanceChunks = 8;
    this.loadOptions();
    Config.initGameSettings(this);
}
 
Example 2
Project: BaseClient   File: GameSettings.java   View Source Code Vote up 6 votes
public GameSettings(Minecraft mcIn, File p_i46326_2_)
{
    this.keyBindings = (KeyBinding[])((KeyBinding[])ArrayUtils.addAll(new KeyBinding[] {this.keyBindAttack, this.keyBindUseItem, this.keyBindForward, this.keyBindLeft, this.keyBindBack, this.keyBindRight, this.keyBindJump, this.keyBindSneak, this.keyBindSprint, this.keyBindDrop, this.keyBindInventory, this.keyBindChat, this.keyBindPlayerList, this.keyBindPickBlock, this.keyBindCommand, this.keyBindScreenshot, this.keyBindTogglePerspective, this.keyBindSmoothCamera, this.keyBindStreamStartStop, this.keyBindStreamPauseUnpause, this.keyBindStreamCommercials, this.keyBindStreamToggleMic, this.keyBindFullscreen, this.keyBindSpectatorOutlines}, this.keyBindsHotbar));
    this.difficulty = EnumDifficulty.NORMAL;
    this.lastServer = "";
    this.fovSetting = 70.0F;
    this.language = "en_US";
    this.forceUnicodeFont = false;
    this.mc = mcIn;
    this.optionsFile = new File(p_i46326_2_, "options.txt");
    this.optionsFileOF = new File(p_i46326_2_, "optionsof.txt");
    this.limitFramerate = (int)GameSettings.Options.FRAMERATE_LIMIT.getValueMax();
    this.ofKeyBindZoom = new KeyBinding("Zoom", 46, "key.categories.misc");
    this.keyBindings = (KeyBinding[])((KeyBinding[])ArrayUtils.add(this.keyBindings, this.ofKeyBindZoom));
    GameSettings.Options.RENDER_DISTANCE.setValueMax(32.0F);
    this.renderDistanceChunks = 8;
    this.loadOptions();
    Config.initGameSettings(this);
}
 
Example 3
Project: otf2ttf   File: CubicToQuad.java   View Source Code Vote up 6 votes
public double[] _cubicToQuad(double p1x, double p1y, double c1x, double c1y, double c2x, double c2y, double p2x,
		double p2y, double errorBound) {
	Point p1 = new Point(p1x, p1y);
	Point c1 = new Point(c1x, c1y);
	Point c2 = new Point(c2x, c2y);
	Point p2 = new Point(p2x, p2y);
	Point[] pc = calcPowerCoefficients(p1, c1, c2, p2);
	Point a = pc[0], b = pc[1], c = pc[2], d = pc[3];

	Point[][] approximation = new Point[][] {};
	for (int segmentsCount = 1; segmentsCount <= 8; segmentsCount++) {
		approximation = new Point[][] {};
		for (double t = 0.0; t < 1; t += 1.0 / segmentsCount) {
			approximation = ArrayUtils.add(approximation, processSegment(a, b, c, d, t, t + 1 / segmentsCount));
		}
		if (segmentsCount == 1 && (approximation[0][1].sub(p1).dot(c1.sub(p1)) < 0
				|| approximation[0][1].sub(p2).dot(c2.sub(p2)) < 0)) {
			// approximation concave, while the curve is convex (or vice versa)
			continue;
		}
		if (_isApproximationClose(a, b, c, d, approximation, errorBound)) {
			break;
		}
	}
	return toFlatArray(approximation);
}
 
Example 4
Project: teiniker-lectures-configurationmanagement   File: ArrayExample.java   View Source Code Vote up 6 votes
public static void main(String[] args)
{
	String[] array = ArrayUtils.toArray("one", "two", "three");	
	System.out.println(ArrayUtils.toString(array));
	
	array = ArrayUtils.add(array, "four");
	System.out.println(ArrayUtils.toString(array));
	
	if(ArrayUtils.contains(array,"two"))
	{
		System.out.println("found \"two\" in the array.");
	}
	
	ArrayUtils.reverse(array);
	System.out.println(ArrayUtils.toString(array));
}
 
Example 5
Project: teiniker-lectures-configurationmanagement   File: ArrayExample.java   View Source Code Vote up 6 votes
public static void main(String[] args)
{
	String[] array = ArrayUtils.toArray("one", "two", "three");	
	System.out.println(ArrayUtils.toString(array));
	
	array = ArrayUtils.add(array, "four");
	System.out.println(ArrayUtils.toString(array));
	
	if(ArrayUtils.contains(array,"two"))
	{
		System.out.println("found \"two\" in the array.");
	}
	
	ArrayUtils.reverse(array);
	System.out.println(ArrayUtils.toString(array));
}
 
Example 6
Project: sumo   File: MathUtil.java   View Source Code Vote up 5 votes
/**
 * Convolution U(m)=Sum( H(m)X(n-m) )    0<=m=<(size(H)-1) n=size(H)
 * 
 * This function reproduce the matlab conv function with shape='valid'
 * 
 * @param a
 * @param b
 * @return
 */
public static double[] linearConvolutionMatlabValid(double a[],double b[]){
	//size of the array result without zero padd values
	int sizeResult=a.length+b.length-1;
	int matlabSizeResult=a.length-b.length+1;
	
	b=ArrayUtils.add(b,0);
	
	double[] u=new double[sizeResult];
	int idU=0;
	for(int n=0;n<sizeResult;n++){
		double val=0;

		for(int m=0;m<=n;m++){
			int idx1=m;
			int idx2=n-m;
			
			if(idx2>=0&&idx1>=0&&idx2<b.length-1&&idx1<a.length){
				val=val+a[idx1]*b[idx2];
			}	
		}
		u[idU]=val;
		idU++;
	}
	int diff=(sizeResult-matlabSizeResult);
	int idxStart=diff/2+diff%2;
	int idxEnd=u.length-diff/2;
	u=ArrayUtils.subarray(u, idxStart, idxEnd);
	
	
	return u; 
}
 
Example 7
Project: sumo   File: TestJavaConvolution.java   View Source Code Vote up 5 votes
/**
 * Convolution U(m)=Sum( H(m)X(n-m) )    0<=m=<(size(H)-1) n=size(H)
 * 
 * This function reproduce the matlab conv function with shape='valid'
 * 
 * @param a
 * @param b
 * @return
 */
public static double[] linearConvolutionMatlabValid(double a[],double b[]){
	//size of the array result without zero padd values
	int sizeResult=a.length+b.length-1;
	int matlabSizeResult=a.length-b.length+1;
	
	b=ArrayUtils.add(b,0);
	List<Integer> idxPadded=new ArrayList<Integer>();
	
	double[] u=new double[sizeResult];
	int idU=0;
	for(int n=0;n<sizeResult;n++){
		double val=0;
		
		
		for(int m=0;m<=n;m++){
			
			int idx1=m;
			int idx2=n-m;
			
			if(idx2>=0&&idx1>=0&&idx2<b.length-1&&idx1<a.length){
				val=val+a[idx1]*b[idx2];
			}	
		}

		u[idU]=val;
		idU++;
	}
	int diff=(sizeResult-matlabSizeResult);
	int idxStart=diff/2+diff%2;
	int idxEnd=u.length-diff/2;
	u=ArrayUtils.subarray(u, idxStart, idxEnd);
	
	
	return u; 
}
 
Example 8
Project: convertigo-engine   File: UIControlEvent.java   View Source Code Vote up 5 votes
@Override
public String[] getTagsForProperty(String propertyName) {
	if (propertyName.equals("eventName")) {
		String[] attrEvents = EnumUtils.toNames(AttrEvent.class);
		if (parent != null && parent instanceof UIDynamicElement) {
			String[] eventNames = ((UIDynamicElement)parent).getEventNames();
    		if (eventNames.length > 0) {
    			eventNames = ArrayUtils.add(eventNames, "");
    		}
			return ArrayUtils.addAll(eventNames, attrEvents);
		}
		return attrEvents;
	}
	return new String[0];
}
 
Example 9
Project: embulk-filter-google_translate_api   File: GoogleTranslateApiPageOutput.java   View Source Code Vote up 5 votes
/**
 * @param texts
 * @return
 */
private List<Translation> translate(List<String> texts) {
    TranslateOption[] translateOptions = new TranslateOption[] {};
    if (srcLang != null) {
        translateOptions = ArrayUtils.add(translateOptions, srcLang);
    }
    if (model != null) {
        translateOptions = ArrayUtils.add(translateOptions, model);
    }
    return translate.translate(texts, translateOptions);
}
 
Example 10
Project: otf2ttf   File: CTQ.java   View Source Code Vote up 5 votes
public double[] handle(Contour z1, Contour z2, Contour z3, Contour z4, Double splitAtX, Double splitAtY,
		double err) {
	double[][] segs = getSplitAtXY(z1.x, z1.y, z2.x, z2.y, z3.x, z3.y, z4.x, z4.y, splitAtX, splitAtY);
	double[] ss = new double[] {};
	for (double[] s : segs) {
		double[] a = cubicToQuad(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], err);
		for (int j = ss.length != 0 ? 2 : 0; j < a.length; j++) {
			ss = ArrayUtils.add(ss, a[j]);
		}
	}
	return ss;
}
 
Example 11
Project: referenceapp   File: AdminUIApplication.java   View Source Code Vote up 5 votes
public static void main(String[] args) throws Exception {
	String[] localArgs = args;
	if (ArrayUtils.isEmpty(localArgs)) {
		localArgs = (String[])ArrayUtils.add(localArgs, "server");
		localArgs = (String[])ArrayUtils.add(localArgs, "admin-ui.yml");
	}
	new AdminUIApplication().run(localArgs );
	
}
 
Example 12
Project: pnc-repressurized   File: GuiAphorismTile.java   View Source Code Vote up 4 votes
@Override
protected void keyTyped(char par1, int par2) throws IOException {
    if (par2 == Keyboard.KEY_ESCAPE) {
        NetworkHandler.sendToServer(new PacketAphorismTileUpdate(tile));
    } else if (par2 == Keyboard.KEY_LEFT || par2 == Keyboard.KEY_UP) {
        cursorY--;
        if (cursorY < 0) cursorY = textLines.length - 1;
    } else if (par2 == Keyboard.KEY_DOWN || par2 == Keyboard.KEY_NUMPADENTER) {
        cursorY++;
        if (cursorY >= textLines.length) cursorY = 0;
    } else if (par2 == Keyboard.KEY_RETURN) {
        cursorY++;
        textLines = ArrayUtils.add(textLines, cursorY, "");
    } else if (par2 == Keyboard.KEY_BACK) {
        if (textLines[cursorY].length() > 0) {
            textLines[cursorY] = textLines[cursorY].substring(0, textLines[cursorY].length() - 1);
            if (textLines[cursorY].endsWith("\u00a7")) {
                textLines[cursorY] = textLines[cursorY].substring(0, textLines[cursorY].length() - 1);
            }
        } else if (textLines.length > 1) {
            textLines = ArrayUtils.remove(textLines, cursorY);
            cursorY--;
            if (cursorY < 0) cursorY = 0;
        }
    } else if (par2 == Keyboard.KEY_DELETE) {
        if (GuiScreen.isShiftKeyDown()) {
            textLines = new String[1];
            textLines[0] = "";
            cursorY = 0;
        } else {
            if (textLines.length > 1) {
                textLines = ArrayUtils.remove(textLines, cursorY);
                if (cursorY > textLines.length - 1)
                    cursorY = textLines.length - 1;
            }
        }
    } else if (ChatAllowedCharacters.isAllowedCharacter(par1)) {
        if (GuiScreen.isAltKeyDown()) {
            if (par1 >= 'a' && par1 <= 'f' || par1 >= 'l' && par1 <= 'o' || par1 == 'r' || par1 >= '0' && par1 <= '9') {
                textLines[cursorY] = textLines[cursorY] + "\u00a7" + par1;
            }
        } else {
            textLines[cursorY] = textLines[cursorY] + par1;
        }
    }
    tile.setTextLines(textLines);
    super.keyTyped(par1, par2);
}
 
Example 13
Project: CreeperHostGui   File: Client.java   View Source Code Vote up 4 votes
@Override
public void registerKeys()
{
    openGuiKey = new KeyBinding("minetogether.key.friends", Keyboard.KEY_M, "minetogether.keys");
    Minecraft.getMinecraft().gameSettings.keyBindings = ArrayUtils.add(Minecraft.getMinecraft().gameSettings.keyBindings, openGuiKey);
}
 
Example 14
Project: QDrill   File: TypedFieldId.java   View Source Code Vote up 4 votes
public TypedFieldId cloneWithChild(int id) {
  int[] fieldIds = ArrayUtils.add(this.fieldIds, id);
  return new TypedFieldId(intermediateType, secondaryFinal, finalType, isHyperReader, remainder, fieldIds);
}
 
Example 15
Project: CustomWorldGen   File: ClientRegistry.java   View Source Code Vote up 4 votes
public static void registerKeyBinding(KeyBinding key)
{
    Minecraft.getMinecraft().gameSettings.keyBindings = ArrayUtils.add(Minecraft.getMinecraft().gameSettings.keyBindings, key);
}
 
Example 16
Project: QDrill   File: HyperVectorWrapper.java   View Source Code Vote up 4 votes
public void addVectors(ValueVector[] vv) {
  vectors = (T[]) ArrayUtils.add(vectors, vv);
}
 
Example 17
Project: dremio-oss   File: HyperVectorWrapper.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
public void addVector(ValueVector v) {
  Preconditions.checkArgument(v.getClass() == this.getVectorClass(), String.format("Cannot add vector type %s to hypervector type %s for field %s",
    v.getClass(), this.getVectorClass(), v.getField()));
  vectors = (T[]) ArrayUtils.add(vectors, v);// TODO optimize this so not copying every time
}
 
Example 18
Project: dremio-oss   File: TypedFieldId.java   View Source Code Vote up 4 votes
public TypedFieldId cloneWithChild(int id) {
  int[] fieldIds = ArrayUtils.add(this.fieldIds, id);
  return new TypedFieldId(intermediateType, secondaryFinal, finalType, isHyperReader, remainder, fieldIds);
}
 
Example 19
Project: krobot   File: Config.java   View Source Code Vote up 3 votes
/**
 * Append an object to an array of the config
 *
 * @param field The path (see {@link #at(String)}) of the array
 * @param classOfArray The class of the array
 * @param toAppend The object to append
 *
 * @param <T> The type of the object
 *
 * @return The new array
 */
default <T> T[] append(String field, Class<T[]> classOfArray, T toAppend)
{
    T[] array = ArrayUtils.add(at(field, classOfArray), toAppend);
    set(field, array);

    return array;
}
 
Example 20
Project: cryptotrader   File: AbstractService.java   View Source Code Vote up 2 votes
@VisibleForTesting
public BigDecimal calculateComposite(List<Composite> products, BiFunction<String, String, BigDecimal> f) {

    if (CollectionUtils.isEmpty(products)) {
        return null;
    }

    BigDecimal[] results = {null};

    for (Composite composite : products) {

        if (composite == null || composite.getSite() == null || composite.getSite().length() < 2) {
            return null;
        }

        char operation = composite.getSite().charAt(0);

        BinaryOperator<BigDecimal> operator = null;

        if (operation == '+') {
            operator = BigDecimal::add;
        }

        if (operation == '-') {
            operator = BigDecimal::subtract;
        }

        if (operation == '*') {
            operator = BigDecimal::multiply;
        }

        if (operation == '/') {
            operator = (o1, o2) -> o1.divide(o2, SCALE, HALF_UP);
        }

        if (operation != '@' && operator == null) {
            return null; // Average
        }

        String site = composite.getSite().substring(1);

        String product = composite.getInstrument();

        BigDecimal value = f.apply(site, product);

        if (value == null || value.signum() == 0) {
            return null;
        }

        if (operator == null) {

            results = ArrayUtils.add(results, value);

            continue;

        }

        BigDecimal current = trim(results[0], ONE);

        results[0] = operator.apply(current, value);

    }

    long count = Stream.of(results).filter(Objects::nonNull).count();

    BigDecimal total = Stream.of(results).filter(Objects::nonNull)
            .reduce(BigDecimal::add).orElse(ZERO);

    return total.divide(BigDecimal.valueOf(count), SCALE, HALF_UP);

}