List of usage examples for java.util Arrays fill
public static void fill(Object[] a, Object val)
From source file:com.opengamma.analytics.financial.equity.variance.pricing.RealizedVariance.java
@Override public Double evaluate(final VarianceSwap swap) { double[] obs = swap.getObservations(); int nObs = obs.length; if (nObs < 2) { return 0.0; }/*from w ww. j a va 2s .c o m*/ Double[] weights = new Double[obs.length - 1]; if (swap.getObservationWeights().length == 0) { Arrays.fill(weights, 1.0); } else if (swap.getObservationWeights().length == 1) { Arrays.fill(weights, swap.getObservationWeights()[0]); } else { int nWeights = swap.getObservationWeights().length; Validate.isTrue(nWeights == nObs - 1, "If provided, observationWeights must be of length one less than observations, as they weight returns log(obs[i]/obs[i-1])." + " Found " + nWeights + " weights and " + nObs + " observations."); } Validate.isTrue(obs[0] != 0.0, "In VarianceSwap, the first observation is zero so the estimate of RealizedVariance is undefined. Check time series."); double logReturns = 0; for (int i = 1; i < nObs; i++) { Validate.isTrue(obs[i] != 0.0, "Encountered an invalid observation of zero in VarianceSwap at " + i + "'th observation. " + "The estimate of RealizedVariance is undefined. Check time series."); logReturns += weights[i - 1] * FunctionUtils.square(Math.log(obs[i] / obs[i - 1])); } return logReturns / (nObs - 1) * swap.getAnnualizationFactor(); }
From source file:eu.dety.burp.joseph.utilities.Decoder.java
/** * Split JOSE value into its separate parts with fixed length * //from w w w . j av a2 s . c o m * @param input * Compact serialization JOSE value * @param assureLength * Assure a certain length of the returned string array * @return string array with the separate fixed amount of parts */ public static String[] getComponents(String input, int assureLength) { String[] components = input.split("\\."); // If length is already correct return the components if (components.length == assureLength) { return components; } String[] output = new String[assureLength]; Arrays.fill(output, ""); System.arraycopy(components, 0, output, 0, Math.min(components.length, assureLength)); return output; }
From source file:com.ibm.sbt.services.client.connections.activities.ActivityEntryPerformanceTest.java
@Test @org.junit.Ignore("Issue with Mime Depdency") public void testCreateActivityEntries() throws ClientServicesException { System.setErr(new PrintStream(new ByteArrayOutputStream())); Activity activity = createActivity(); String activityUuid = activity.getActivityUuid(); String title = activity.getThemeId(); FileField fileField = new FileField(); fileField.setName("test_file"); fileField.setHidden(true);/*from w w w . ja v a 2 s. c om*/ fileField.setPosition(2000); byte[] bytes = new byte[Integer.valueOf(1024)]; Arrays.fill(bytes, (byte) 0); StringWriter stringWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stringWriter); writer.println("#,NodeUUID,Time(ms)"); for (int i = 0; i < 500; i++) { try { long start = System.currentTimeMillis(); System.out.print(i + " "); ActivityNode activityNode = new ActivityNode(); activityNode.setActivityUuid(activityUuid); activityNode.setTitle(title + " - " + i); activityNode.setType(ActivityNode.TYPE_ENTRY); for (int j = 0; j < 5; j++) { TextField textField = new TextField(); textField.setName("test_text" + j); textField.setPosition(1000); textField.setSummary("Test_Text_Field"); activityNode.addField(textField); } activityNode.addField(fileField); activityNode.addAttachment(new ActivityAttachment("test_file", new String(bytes), "text/plain")); activityNode = activityService.createActivityNode(activityNode); long duration = System.currentTimeMillis() - start; writer.println(i + "," + activityNode.getActivityNodeUuid() + "," + duration); } catch (Exception e) { } } System.out.println(stringWriter.toString()); /* long start = System.currentTimeMillis(); Map<String, String> params = new HashMap<String, String>(); params.put("page", "1"); params.put("ps", "1"); activityService.getActivityNodeDescendants(activityUuid, params); long duration = System.currentTimeMillis() - start; System.out.println("Reading all activity descendants took "+duration+"(ms)"); start = System.currentTimeMillis(); params.put("tag", "personal"); activityService.getActivityNodeChildren(activityUuid, params); duration = System.currentTimeMillis() - start; System.out.println("Reading all activity children took "+duration+"(ms)"); */ }
From source file:de.tor.tribes.util.BuildingSettings.java
public static boolean loadSettings(String pServerID) { Arrays.fill(MAX_LEVEL, -1); Arrays.fill(MIN_LEVEL, -1);/*ww w . ja v a 2s. co m*/ Arrays.fill(BUILD_WOOD, -1); Arrays.fill(BUILD_STONE, -1); Arrays.fill(BUILD_IRON, -1); Arrays.fill(BUILD_POP, -1); Arrays.fill(BUILD_TIME, -1); Arrays.fill(BUILD_WOOD_FACTOR, Double.NaN); Arrays.fill(BUILD_STONE_FACTOR, Double.NaN); Arrays.fill(BUILD_IRON_FACTOR, Double.NaN); Arrays.fill(BUILD_POP_FACTOR, Double.NaN); Arrays.fill(BUILD_TIME_FACTOR, Double.NaN); try { logger.debug("Loading server buildings"); String buildingsPath = Constants.SERVER_DIR + "/" + pServerID + "/buildings.xml"; logger.debug("Parse buildings from '" + buildingsPath + "'"); Document d = JDomUtils.getDocument(new File(buildingsPath)); for (Element b : d.getRootElement().getChildren()) { String name = b.getName(); int index = ArrayUtils.indexOf(BUILDING_NAMES, name); if (index < 0) { logger.warn("Found unknown Building {}", name); continue; } try { MAX_LEVEL[index] = Integer.parseInt(b.getChildTextTrim("max_level")); MIN_LEVEL[index] = Integer.parseInt(b.getChildTextTrim("min_level")); BUILD_WOOD[index] = Integer.parseInt(b.getChildTextTrim("wood")); BUILD_STONE[index] = Integer.parseInt(b.getChildTextTrim("stone")); BUILD_IRON[index] = Integer.parseInt(b.getChildTextTrim("iron")); BUILD_POP[index] = Integer.parseInt(b.getChildTextTrim("pop")); BUILD_TIME[index] = Integer.parseInt(b.getChildTextTrim("build_time")); BUILD_WOOD_FACTOR[index] = Double.parseDouble(b.getChildTextTrim("wood_factor")); BUILD_STONE_FACTOR[index] = Double.parseDouble(b.getChildTextTrim("stone_factor")); BUILD_IRON_FACTOR[index] = Double.parseDouble(b.getChildTextTrim("iron_factor")); BUILD_POP_FACTOR[index] = Double.parseDouble(b.getChildTextTrim("pop_factor")); BUILD_TIME_FACTOR[index] = Double.parseDouble(b.getChildTextTrim("build_time_factor")); } catch (Exception e) { logger.error("Got an excetion during reading of buildings", e); } } } catch (Exception e) { logger.error("Failed to load buildings", e); return false; } logger.info(Arrays.toString(MAX_LEVEL)); logger.info(Arrays.toString(MIN_LEVEL)); logger.info(Arrays.toString(BUILD_WOOD)); logger.info(Arrays.toString(BUILD_STONE)); logger.info(Arrays.toString(BUILD_IRON)); logger.info(Arrays.toString(BUILD_POP)); logger.info(Arrays.toString(BUILD_TIME)); logger.info(Arrays.toString(BUILD_WOOD_FACTOR)); logger.info(Arrays.toString(BUILD_STONE_FACTOR)); logger.info(Arrays.toString(BUILD_IRON_FACTOR)); logger.info(Arrays.toString(BUILD_POP_FACTOR)); logger.info(Arrays.toString(BUILD_TIME_FACTOR)); logger.debug("Successfully read buildings for server '" + pServerID + "'"); return true; }
From source file:de.tudarmstadt.lt.ltbot.postprocessor.DecesiveValuePrioritizer.java
public DecesiveValuePrioritizer() { setExtraInfoValueFieldName(SharedConstants.EXTRA_INFO_PERPLEXITY); setAssignmentBoundaries("5e2,5e3,Infinity"); // one for each priority (HIGH,MEDIUM,NORMAL) HIGHER is reserved for prerequisites setMaxvalue(15);//from w w w. j a v a 2 s . c o m _assignment_counts = new long[4]; // one for each priority Arrays.fill(_assignment_counts, 0l); _count_reject = 0l; }
From source file:com.almende.eve.algorithms.DAA.java
/** * Sets this nodes new value.//from w w w.j a v a2s . c om * * @param value * the new new value */ public void setNewValue(final double value) { localValue = new DAAValueBean(width, evictionFactor); localValue.generate(value).setTTL(DateTime.now().plus(100).getMillis()); if (currentEstimate == null) { currentEstimate = new DAAValueBean(width, evictionFactor); Arrays.fill(currentEstimate.valueArray, Double.MAX_VALUE); } currentEstimate.minimum(localValue); }
From source file:ricecompression.RiceCompression.java
public String compress(int m, int n) { String riceCode;/*w w w.j a v a 2 s . c o m*/ int nBitsM = (int) (Math.log10(m) / Math.log10(2)); if (n < 0) riceCode = "0"; //Valor negatiu else riceCode = "1"; //Valor negatiu int q = Math.abs(n) / m; char[] array = new char[q]; Arrays.fill(array, '1'); if (array.length > 0) riceCode = riceCode.concat(String.valueOf(array)); //Si el quocient es major a 0 riceCode = riceCode.concat("0"); int r = Math.abs(n) % m; String rBinary = String.format("%" + nBitsM + "s", Integer.toBinaryString(r)).replace(' ', '0'); riceCode = riceCode.concat(rBinary); return riceCode; }
From source file:hivemall.common.DenseModel.java
public DenseModel(int ndims, boolean withCovar) { int size = ndims + 1; this.size = size; this.weights = new float[size]; if (withCovar) { float[] covars = new float[size]; Arrays.fill(covars, 1f); this.covars = covars; } else {// w ww . j a v a2 s . c om this.covars = null; } }
From source file:io.milton.common.RangeUtilsTest.java
public void xtestSendBytes_Over1k() throws Exception { long length = 5000; byte[] buf = new byte[10000]; Arrays.fill(buf, (byte) 3); ByteArrayInputStream in = new ByteArrayInputStream(buf); ByteArrayOutputStream out = new ByteArrayOutputStream(); RangeUtils.sendBytes(in, out, length); assertEquals(5000, out.toByteArray().length); }
From source file:jetbrains.exodus.entitystore.processRunners.ProcessRunner.java
private void step() throws Exception { Entity entity = txn.newEntity("Person"); entity.setProperty("name", "Vadim"); entity.setProperty("password", "dummypassword"); byte[] blob = new byte[1024 * 1024]; Arrays.fill(blob, (byte) 1); entity.setBlob("weight", new ByteArrayInputStream(blob)); txn.flush();//from w w w. j a v a 2 s . c o m }