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_0_11.Freqz.java
public Freqz(double[] b, int n) { FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD); Complex[] hb = fft.transform(Arrays.copyOf(b, 2 * n), TransformType.FORWARD); H = Arrays.copyOfRange(hb, 0, n); w = new double[n]; for (int i = 0; i < H.length; i++) { w[i] = Math.PI / n * i;// w w w . j a v a2 s. c om } }
From source file:com.opengamma.analytics.math.fft.JTransformsWrapper.java
/** * The forward discrete Fourier transform. *Note:* In this definition * $-i$ appears in the exponential rather than $i$. * <p>/* w ww.ja v a2 s. co m*/ * If $z$ is an array of $N$ complex values sampled at intervals $\Delta$ * from a function $h(t)$, then the transform * $$ * $H(f) = \int^{\infty}_{-\infty} e^{-2i\pi f t} h(t) dt$ * $$ * is sampled at $N$ points at intervals of $\frac{1}{N\Delta}$. * <p> * The first $\frac{N}{2} + 1$ values ($i = 0$ to $\frac{N}{2}$) are $f = * \frac{i}{N\Delta}$, while the values $i = \frac{N}{2}$ to $N - 1$ are $f = * \frac{i-N}{N\Delta}$ (i.e. negative frequencies with $H(\frac{1}{2\Delta}) * = H(\frac{-1}{2\Delta})$). * <p> * As $h(t)$ is real, $H(f) = H(-f)^*$, so the second half of the array * (negative values of f) are superfluous. * @param h Array of N real values * @return The Fourier transform of the array */ public static ComplexNumber[] fullTransform1DReal(final double[] h) { Validate.notNull(h, "array of doubles"); final int n = h.length; Validate.isTrue(n > 0); final double[] a = Arrays.copyOf(h, 2 * n); DoubleFFT_1D fft = CACHE_1D.get(n); if (fft == null) { fft = new DoubleFFT_1D(n); CACHE_1D.put(n, fft); } fft.realForwardFull(a); return unpackFull(a); }
From source file:com.falcon.orca.actors.Generator.java
public Generator(final ActorRef collector, final String url, final HttpMethods method, final byte[] data, final List<Header> headers, final List<Cookie> cookies, final boolean isBodyDynamic, final boolean isUrlDynamic, final DynDataStore dataStore) throws URISyntaxException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException { this.collector = collector; this.dataStore = dataStore; this.isBodyDynamic = isBodyDynamic; this.method = method; this.url = url; this.headers = headers; this.staticRequestData = data != null ? Arrays.copyOf(data, data.length) : new byte[0]; this.isUrlDynamic = isUrlDynamic; CookieStore cookieStore = new BasicCookieStore(); if (cookies != null) { cookies.forEach(cookieStore::addCookie); }//from w ww . j av a 2 s .c om TrustStrategy trustStrategy = (x509Certificates, s) -> true; SSLContext sslContext = SSLContextBuilder.create().loadTrustMaterial(null, trustStrategy).build(); this.client = HttpClientBuilder.create().setSSLContext(sslContext) .setSSLHostnameVerifier(new NoopHostnameVerifier()).setDefaultCookieStore(cookieStore).build(); }
From source file:com.consol.citrus.admin.web.ProjectSetupInterceptor.java
/** * Sets the excludes./* w w w. j a v a 2 s .co m*/ * @param excludes the excludes to set */ public void setExcludes(String[] excludes) { this.excludes = Arrays.copyOf(excludes, excludes.length); }
From source file:com.baidu.oped.apm.common.buffer.FixedBufferTest.java
@Test public void readPadBytes() { byte[] bytes = new byte[10]; random.nextBytes(bytes);// w ww . j a va 2 s.c o m Buffer writeBuffer = new FixedBuffer(32); writeBuffer.putPadBytes(bytes, 20); writeBuffer.put(255); Buffer readBuffer = new FixedBuffer(writeBuffer.getBuffer()); byte[] readPadBytes = readBuffer.readPadBytes(20); Assert.assertArrayEquals(bytes, Arrays.copyOf(readPadBytes, 10)); int readInt = readBuffer.readInt(); Assert.assertEquals(255, readInt); }
From source file:com.l2jserver.util.calculator.ComplexCalculator.java
/** * Creates a new calculator with <tt>functions</tt> in the declaration * order./*from w w w. j a v a2s.c o m*/ * * @param type * the {@link Class} for attribute set * @param functions * the calculator functions */ @SafeVarargs public ComplexCalculator(Class<V> type, Function<T, V>... functions) { this(type); add(functions); for (final Function<T, V> func : functions) { Function<T, V>[] funcs = getList(func.type()); funcs = Arrays.copyOf(funcs, funcs.length + 1); funcs[funcs.length - 1] = func; setList(func.type(), funcs); } for (final Function<T, V>[] funcs : this.functions.values()) { Arrays.sort(funcs, FunctionOrderComparator.SHARED_INSTANCE); } }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Sort.java
/** * Sorts values statelessly in order given by enumeration * @param v1 the values to sort (a native backed array) * @param d the direction in which the sorted array should be returned (based on {@link direction}) * @return tmp the sorted values// w w w . j ava2 s .c o m */ public static double[] stateless(double[] v1, direction d) { Validate.notNull(v1); double[] tmp = Arrays.copyOf(v1, v1.length); Arrays.sort(tmp); switch (d) { case ascend: break; case descend: Reverse.inPlace(tmp); } return tmp; }
From source file:com.eucalyptus.auth.crypto.StringCrypto.java
public static byte[] cat(byte[] bs, byte[] bs2) { byte[] result = Arrays.copyOf(bs, bs.length + bs2.length); System.arraycopy(bs2, 0, result, bs.length, bs2.length); return result; }
From source file:coolmap.data.state.CoolMapState.java
private CoolMapState(CoolMapState oldState) { //pass object _objectID = oldState._objectID;/* ww w . j a v a2 s .com*/ _logRowNodes = oldState._logRowNodes; _logColNodes = oldState._logColNodes; _logSelections = oldState._logSelections; //but it could be null _operationName = oldState._operationName; //refer to other parameters if (oldState._otherParameters == null) { _otherParameters = null; } else { _otherParameters = Arrays.copyOf(oldState._otherParameters, oldState._otherParameters.length); } if (_logRowNodes) { //duplicate the rowNodes _rowBaseNodes = new ArrayList<>(); _rowTreeNodes = new ArrayList<>(); HashMap<String, VNode> newRowNodeHash = new HashMap<>(); List<VNode> baseNodes = new ArrayList<VNode>(); List<VNode> treeNodes = new ArrayList<VNode>(); baseNodes.addAll(oldState._rowBaseNodes); treeNodes.addAll(oldState._rowTreeNodes); //rowbase node for (VNode node : baseNodes) { try { VNode dup = node.duplicate(); newRowNodeHash.put(dup.getID(), dup); _rowBaseNodes.add(dup); } catch (Exception e) { e.printStackTrace(); } } //rowtreenodes for (VNode node : treeNodes) { try { VNode dup = node.duplicate(); newRowNodeHash.put(dup.getID(), dup); _rowTreeNodes.add(dup); } catch (Exception e) { e.printStackTrace(); } } for (VNode treeNode : treeNodes) { VNode newTreeNode = newRowNodeHash.get(treeNode.getID()); List<VNode> childNodes = treeNode.getChildNodes(); //existing tree for (VNode child : childNodes) { VNode newChildNode = newRowNodeHash.get(child.getID()); if (newChildNode != null) { newTreeNode.addChildNode(newChildNode); } else { System.err.println( "Error when trying to create a state storage row nodes - when duplicating"); } } } } else { _rowBaseNodes = null; _rowTreeNodes = null; } if (_logColNodes) { _colBaseNodes = new ArrayList<>(); _colTreeNodes = new ArrayList<>(); HashMap<String, VNode> newColNodeHash = new HashMap<>(); List<VNode> baseNodes = new ArrayList<VNode>(); List<VNode> treeNodes = new ArrayList<VNode>(); baseNodes.addAll(oldState._colBaseNodes); baseNodes.addAll(oldState._colTreeNodes); //save col base nodes for (VNode node : baseNodes) { try { VNode dup = node.duplicate(); newColNodeHash.put(dup.getID(), dup); _colBaseNodes.add(dup); } catch (Exception e) { e.printStackTrace(); } } //save col tree nodes for (VNode node : treeNodes) { try { VNode dup = node.duplicate(); newColNodeHash.put(dup.getID(), dup); _colTreeNodes.add(dup); } catch (Exception e) { e.printStackTrace(); } } for (VNode treeNode : treeNodes) { VNode newTreeNode = newColNodeHash.get(treeNode.getID()); List<VNode> childNodes = treeNode.getChildNodes(); for (VNode child : childNodes) { VNode newChildNode = newColNodeHash.get(child.getID()); if (newChildNode != null) { newTreeNode.addChildNode(newChildNode); } else { System.err.println( "Error when trying to create a state storage col nodes - when duplicating"); } } } } else { _colBaseNodes = null; _colTreeNodes = null; } //duplidate selections if (_logSelections) { _selections = new HashSet<Rectangle>(); _rowSelections = new ArrayList<Range<Integer>>(); _colSelections = new ArrayList<Range<Integer>>(); if (_selections != null && !_selections.isEmpty()) { _selections.addAll(oldState._selections); _rowSelections.addAll(oldState._rowSelections); _colSelections.addAll(oldState._colSelections); } } else { _selections = null; _rowSelections = null; _colSelections = null; } if (oldState._configurations == null) { _configurations = null; } else { _configurations = new JSONObject(oldState._configurations); } _createdTime = oldState._createdTime; }
From source file:com.offbynull.voip.kademlia.internalmessages.Start.java
/** * Constructs a {@link Start} object./*from w w w. jav a 2 s.c om*/ * @param addressTransformer address transformer to use for converting node links to addresses (and vice-versa) * @param baseId ID to use for the node being started * @param bootstrapLink link to connect to the network (if {@code null} if means this node is the first node in the network) * @param kademliaParameters Kademlia parameters * @param seed1 random number generator seed value 1 * @param seed2 random number generator seed value 2 * @param timerAddress address of timer * @param graphAddress address of visualizer graph * @param logAddress address of logger * @throws NullPointerException if any argument other than {@code bootstrapLink} is {@code null} * @throws IllegalArgumentException if {@code seed1} or {@code seed2} is less than {@link IdGenerator#MIN_SEED_SIZE} */ public Start(AddressTransformer addressTransformer, Id baseId, String bootstrapLink, KademliaParameters kademliaParameters, byte[] seed1, byte[] seed2, Address timerAddress, Address graphAddress, Address logAddress) { Validate.notNull(addressTransformer); Validate.notNull(baseId); // bootstrapNode can be null Validate.notNull(kademliaParameters); Validate.notNull(seed1); Validate.notNull(seed2); Validate.notNull(timerAddress); Validate.notNull(graphAddress); Validate.isTrue(seed1.length >= IdGenerator.MIN_SEED_SIZE); Validate.isTrue(seed2.length >= IdGenerator.MIN_SEED_SIZE); this.addressTransformer = addressTransformer; this.baseId = baseId; this.bootstrapLink = bootstrapLink; this.kademliaParameters = kademliaParameters; this.seed1 = Arrays.copyOf(seed1, seed1.length); this.seed2 = Arrays.copyOf(seed2, seed2.length); this.timerAddress = timerAddress; this.graphAddress = graphAddress; this.logAddress = logAddress; }