List of usage examples for java.util Arrays copyOf
public static boolean[] copyOf(boolean[] original, int newLength)
From source file:net.sf.dsp4j.octave.packages.signal_1_2_0.Cheb2Ord.java
private void calcCheb2Ord(double[] Wp, double[] Ws, double Rp, double Rs) { double T = 2; // returned frequency is the same as the input frequency Wc = Arrays.copyOf(Ws, Ws.length); // warp the target frequencies according to the bilinear transform for (int i = 0; i < Wp.length; i++) { Ws[i] = 2.0 / T * Math.tan(Math.PI * Ws[i] / T); Wp[i] = 2.0 / T * Math.tan(Math.PI * Wp[i] / T); }//from ww w. ja va 2 s . c o m double Wa; if (Wp[0] < Ws[0]) { // low pass if (Wp.length == 1) { Wa = Wp[0] / Ws[0]; } else { // band reject throw new RuntimeException("band reject is not implement yet."); } } else { // if high pass, reverse the sense of the test if (Wp.length == 1) { Wa = Ws[0] / Wp[0]; } else { // band pass Wa = Double.MAX_VALUE; for (int i = 0; i < Wp.length; i++) { Wa = Math.min(Wa, Math.abs((Math.pow(Wp[i], 2) - Ws[0] * Ws[1]) / (Wp[i] * (Ws[0] - Ws[1])))); } } } // compute minimum n which satisfies all band edge conditions final double stop_atten = Math.pow(10, Math.abs(Rs) / 10.0); final double pass_atten = Math.pow(10, Math.abs(Rp) / 10.0); n = (int) Math.ceil( FastMath.acosh(Math.sqrt((stop_atten - 1.0) / (pass_atten - 1.0))) / FastMath.acosh(1.0 / Wa)); }
From source file:com.opengamma.analytics.math.cube.DoublesCube.java
/** * @param xData An array of <i>x</i> data, not null * @param yData An array of <i>y</i> data, not null, must be the same length as the <i>x</i> data array * @param zData An array of <i>z</i> data, not null, must be the same length as the <i>x</i> data array * @param values An array of <i>values</i> , not null, must be the same length as the <i>x</i> data array *//*w w w. j a v a 2 s .c o m*/ public DoublesCube(final double[] xData, final double[] yData, final double[] zData, final double[] values) { super(); Validate.notNull(xData, "x data"); Validate.notNull(yData, "y data"); Validate.notNull(zData, "z data"); Validate.notNull(values, "values"); _n = xData.length; Validate.isTrue(_n == yData.length); Validate.isTrue(_n == zData.length); Validate.isTrue(_n == values.length); _xData = Arrays.copyOf(xData, _n); _yData = Arrays.copyOf(yData, _n); _zData = Arrays.copyOf(zData, _n); _values = Arrays.copyOf(values, _n); }
From source file:com.smartitengineering.event.hub.spi.db.PersistentEvent.java
public byte[] getContent() { if (content == null) { return null; } return Arrays.copyOf(content, content.length); }
From source file:com.linkedin.databus2.schemas.FileSystemVersionedSchemaSetProvider.java
public FileSystemVersionedSchemaSetProvider(String schemaSuffix, File... dirs) { this.dirs = Arrays.copyOf(dirs, dirs.length); this.schemaSuffix = schemaSuffix; }
From source file:edu.gsgp.utils.Utils.java
public static double getMedian(double[] array) { double[] auxArray = Arrays.copyOf(array, array.length); Arrays.sort(auxArray);/*from ww w. j ava2s . c om*/ // Even number if (auxArray.length % 2 == 0) { int secondElement = auxArray.length / 2; return (auxArray[secondElement - 1] + auxArray[secondElement]) / 2; } else { int element = (auxArray.length - 1) / 2; return auxArray[element]; } }
From source file:me.footlights.core.crypto.SecretKeyTest.java
/** * Test encryption and decryption using test vectors from * @url http://csrc.nist.gov/groups/STM/cavp/documents/aes/KAT_AES.zip. *//*from w w w.j a v a 2s . c o m*/ @Test public void testEncryptDecrypt() throws Throwable { for (String[] v : TEST_VECTORS) { int i = 0; String algorithm = v[i++]; String mode = v[i++]; byte[] secret = Hex.decodeHex(v[i++].toCharArray()); i++; // We don't actually use the IV. byte[] plaintext = Hex.decodeHex(v[i++].toCharArray()); ByteBuffer plainbuf = ByteBuffer.wrap(Arrays.copyOf(plaintext, plaintext.length)); byte[] ciphertext = Hex.decodeHex(v[i++].toCharArray()); ByteBuffer cipherbuf = ByteBuffer.wrap(Arrays.copyOf(ciphertext, ciphertext.length)); SecretKey key = SecretKey.newGenerator().setAlgorithm(algorithm).setBytes(secret).generate(); CipherBuilder builder = key.newCipherBuilder().setMode(mode); try { Cipher e = builder.setOperation(Operation.ENCRYPT).build(); Cipher d = builder.setOperation(Operation.DECRYPT).build(); assertArrayEquals(ciphertext, e.doFinal(plaintext)); assertArrayEquals(plaintext, d.doFinal(ciphertext)); // Do it again, but this time with ByteBuffers. e.doFinal(plainbuf, cipherbuf); assertArrayEquals(ciphertext, cipherbuf.array()); d.doFinal(cipherbuf, plainbuf); assertArrayEquals(plaintext, plainbuf.array()); } catch (InvalidKeyException e) { fail("Unable to construct an AES cipher with a " + (8 * secret.length) + "-bit key; is the JCE unlimited strength policy installed?"); } } }
From source file:net.sf.dsp4j.octave.packages.signal_1_2_0.Cheb1Ord.java
private void calcCheb1Ord(double[] Wp, double[] Ws, double Rp, double Rs) { double T = 2; // returned frequency is the same as the input frequency Wc = Arrays.copyOf(Wp, Wp.length); // warp the target frequencies according to the bilinear transform for (int i = 0; i < Wp.length; i++) { Ws[i] = 2.0 / T * Math.tan(Math.PI * Ws[i] / T); Wp[i] = 2.0 / T * Math.tan(Math.PI * Wp[i] / T); }/*from ww w . j a va 2s . c o m*/ double Wa; if (Wp[0] < Ws[0]) // low pass { if (Wp.length == 1) { Wa = Ws[0] / Wp[0]; } else { // band reject throw new RuntimeException("band reject is not implement yet."); } } else { // if high pass, reverse the sense of the test if (Wp.length == 1) { Wa = Wp[0] / Ws[0]; } else { // band pass Wa = Double.MAX_VALUE; for (int i = 0; i < Wp.length; i++) { Wa = Math.min(Wa, Math.abs((Math.pow(Ws[i], 2) - Wp[0] * Wp[1]) / (Ws[i] * (Wp[0] - Wp[1])))); } } } // compute minimum n which satisfies all band edge conditions final double stop_atten = Math.pow(10, Math.abs(Rs) / 10.0); final double pass_atten = Math.pow(10, Math.abs(Rp) / 10.0); n = (int) Math .ceil(FastMath.acosh(Math.sqrt((stop_atten - 1.0) / (pass_atten - 1.0))) / FastMath.acosh(Wa)); }
From source file:net.sf.dsp4j.octave.packages.signal_1_2_0.Zp2Sos.java
public Zp2Sos(Complex[] zeros, Complex[] poles, double gain) { this.gain = gain; CplxReal cplxReal = new CplxReal(); cplxReal.cplxReal(0.0000000001, zeros); Complex[] zc = cplxReal.getConjComplxPair(); Complex[] zr = cplxReal.getRealValues(); cplxReal.cplxReal(0.0000000001, poles); Complex[] pc = cplxReal.getConjComplxPair(); Complex[] pr = cplxReal.getRealValues(); int nzc = zc.length; int npc = pc.length; int nzr = zr.length; int npr = pr.length; // Pair up real zeros: int nzrsec = 0; Complex[] zrms = new Complex[0]; Complex[] zrp = new Complex[0]; if (nzr > 0) { if (nzr % 2 == 1) { zr = Arrays.copyOf(zr, zr.length + 1); zr[zr.length - 1] = Complex.ZERO; nzr++;//from ww w . j ava2 s. co m } nzrsec = nzr / 2; zrms = new Complex[nzrsec]; zrp = new Complex[nzrsec]; for (int i = 0; i < zrms.length; i++) { zrms[i] = zr[i * 2].negate().subtract(zr[i * 2 + 1]); zrp[i] = zr[i * 2].multiply(zr[i * 2 + 1]); } } // Pair up real poles: int nprsec = 0; Complex[] prms = new Complex[0]; Complex[] prp = new Complex[0]; if (npr > 0) { if (npr % 2 == 1) { pr = Arrays.copyOf(pr, pr.length + 1); pr[pr.length - 1] = Complex.ZERO; npr++; } nprsec = npr / 2; prms = new Complex[nprsec]; prp = new Complex[nprsec]; for (int i = 0; i < prms.length; i++) { prms[i] = pr[i * 2].negate().subtract(pr[i * 2 + 1]); prp[i] = pr[i * 2].multiply(pr[i * 2 + 1]); } } int nsecs = Math.max(nzc + nzrsec, npc + nprsec); // Convert complex zeros and poles to real 2nd-order section form: double[] zcm2r = OctaveBuildIn.real(zc); for (int i = 0; i < zcm2r.length; i++) { zcm2r[i] *= -2; } double[] zca2 = OctaveBuildIn.abs(zc); for (int i = 0; i < zca2.length; i++) { zca2[i] = Math.pow(zca2[i], 2); } double[] pcm2r = OctaveBuildIn.real(pc); for (int i = 0; i < pcm2r.length; i++) { pcm2r[i] *= -2; } double[] pca2 = OctaveBuildIn.abs(pc); for (int i = 0; i < pca2.length; i++) { pca2[i] = Math.pow(pca2[i], 2); } //all 2nd-order polynomials are monic sos = new double[nsecs][6]; for (int i = 0; i < nsecs; i++) { sos[i][0] = 1; sos[i][3] = 1; } int nzrl = nzc + nzrsec; // index of last real zero section int nprl = npc + nprsec; // index of last real pole section for (int i = 0; i < nsecs; i++) { if (i < nzc) { // lay down a complex zero pair: sos[i][1] = zcm2r[i]; sos[i][2] = zca2[i]; } else if (i < nzrl) { // lay down a pair of real zeros: sos[i][1] = zrms[i - nzc].getReal(); sos[i][2] = zrp[i - nzc].getReal(); } if (i < npc) { // lay down a complex pole pair: sos[i][4] = pcm2r[i]; sos[i][5] = pca2[i]; } else if (i < nprl) { //lay down a pair of real poles: sos[i][4] = prms[i - npc].getReal(); sos[i][5] = prp[i - npc].getReal(); } } }
From source file:com.enviosya.client.tool.Tool.java
public String Desencriptar(String textoEncriptado) throws Exception { //String secretKey = "qualityinfosolutions"; //llave para desenciptar datos String base64EncryptedString = ""; try {/*from w w w . j a va2 s .c om*/ byte[] message = Base64.decodeBase64(textoEncriptado.getBytes("utf-8")); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); SecretKey key = new SecretKeySpec(keyBytes, "DESede"); Cipher decipher = Cipher.getInstance("DESede"); decipher.init(Cipher.DECRYPT_MODE, key); byte[] plainText = decipher.doFinal(message); base64EncryptedString = new String(plainText, "UTF-8"); } catch (Exception e) { //Ac tengo que agregar el retorno de la exception } return base64EncryptedString; }
From source file:com.adobe.acs.commons.notifications.impl.InboxNotificationImpl.java
public String[] getNotificationActions() { if (notificationActions == null) { return ArrayUtils.EMPTY_STRING_ARRAY; } else {//from w w w . j a v a 2 s.c o m return Arrays.copyOf(notificationActions, notificationActions.length); } }