Example usage for java.util Arrays fill

List of usage examples for java.util Arrays fill

Introduction

In this page you can find the example usage for java.util Arrays fill.

Prototype

public static void fill(Object[] a, Object val) 

Source Link

Document

Assigns the specified Object reference to each element of the specified array of Objects.

Usage

From source file:bftsmart.paxosatwar.executionmanager.Round.java

private void updateArrays() {

    if (lastView.getId() != manager.getCurrentViewId()) {

        int n = manager.getCurrentViewN();

        byte[][] weak = new byte[n][];
        byte[][] strong = new byte[n][];

        boolean[] weakSetted = new boolean[n];
        boolean[] strongSetted = new boolean[n];

        Arrays.fill(weakSetted, false);
        Arrays.fill(strongSetted, false);

        for (int pid : lastView.getProcesses()) {

            if (manager.isCurrentViewMember(pid)) {

                int currentPos = manager.getCurrentViewPos(pid);
                int lastPos = lastView.getPos(pid);

                weak[currentPos] = this.weak[lastPos];
                strong[currentPos] = this.strong[lastPos];

                weakSetted[currentPos] = this.weakSetted[lastPos];
                strongSetted[currentPos] = this.strongSetted[lastPos];

            }/*w  ww .  j  a  v  a 2s  . c o  m*/
        }

        this.weak = weak;
        this.strong = strong;

        this.weakSetted = weakSetted;
        this.strongSetted = strongSetted;

        lastView = manager.getCurrentView();

    }
}

From source file:kishida.cnn.layers.FullyConnect.java

@Override
public float[] forward(float[] in) {
    prepareDropout();//from  www.ja v a 2 s  .c om
    Arrays.fill(result, 0);
    FullyForwardKernel.INSTANCE.forward(outputSize, dropout, in, result, weight, bias, useGpu);
    /*
    IntStream.range(0, out).parallel().filter(j -> dropout[j] == 1).forEach(j -> {
    for (int i = 0; i < in.length; ++i) {
        result[j] += in[i] * weight[i * out + j];
    }
    result[j] += bias[j];
    });*/
    activation.applyAfter(result);
    return result;
}

From source file:de.tuberlin.uebb.jbop.example.DSCompilerFactory.java

/**
 * Compile the sizes array./*from   w w w  .  ja  v  a2 s.  co  m*/
 * 
 * @param parameters
 *          number of free parameters
 * @param order
 *          derivation order
 * @param valueCompiler
 *          compiler for the value part
 * @return sizes array
 */
private static int[][] compileSizes(final int parameters, final int order, final IDSCompiler valueCompiler) {

    final int[][] sizes = new int[parameters + 1][order + 1];
    if (parameters == 0) {
        Arrays.fill(sizes[0], 1);
    } else {
        System.arraycopy(valueCompiler.getSizes(), 0, sizes, 0, parameters);
        sizes[parameters][0] = 1;
        for (int i = 0; i < order; ++i) {
            sizes[parameters][i + 1] = sizes[parameters][i] + sizes[parameters - 1][i + 1];
        }
    }

    return sizes;

}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.core.operator.AdaptiveMultimethodVariation.java

/**
 * Returns the array of probabilities of applying each operator.
 * //from  ww w  .j a  v a  2  s  . co m
 * @return the array of probabilities of applying each operator
 */
protected double[] getOperatorProbabilities() {
    double[] count = new double[operators.size()];
    Arrays.fill(count, 1.0);

    for (Solution solution : archive) {
        if (solution.hasAttribute(OPERATOR_ATTRIBUTE)) {
            count[(Integer) solution.getAttribute(OPERATOR_ATTRIBUTE)]++;
        }
    }

    double sum = StatUtils.sum(count);
    double[] probabilities = new double[count.length];

    for (int i = 0; i < count.length; i++) {
        probabilities[i] = count[i] / sum;
    }

    return probabilities;
}

From source file:com.gemstone.gemfire.cache.lucene.internal.filesystem.FileSystemJUnitTest.java

/**
 * A test of reading and writing to a file.
 *///from   w  w  w .j  av a 2 s. co  m
@Test
public void testReadWriteBytes() throws Exception {
    long start = System.currentTimeMillis();

    File file1 = system.createFile("testFile1");

    assertEquals(0, file1.getLength());

    OutputStream outputStream1 = file1.getOutputStream();

    //Write some random data. Make sure it fills several chunks
    outputStream1.write(2);
    byte[] data = new byte[LARGE_CHUNK];
    rand.nextBytes(data);
    outputStream1.write(data);
    outputStream1.write(44);
    outputStream1.close();

    assertEquals(2 + LARGE_CHUNK, file1.getLength());
    assertTrue(file1.getModified() >= start);

    //Append to the file with a new outputstream
    OutputStream outputStream2 = file1.getOutputStream();
    outputStream2.write(123);
    byte[] data2 = new byte[SMALL_CHUNK];
    rand.nextBytes(data2);
    outputStream2.write(data2);
    outputStream2.close();

    assertEquals(3 + LARGE_CHUNK + SMALL_CHUNK, file1.getLength());

    //Make sure we can read all of the data back and it matches
    InputStream is = file1.getInputStream();

    assertEquals(2, is.read());
    byte[] resultData = new byte[LARGE_CHUNK];
    assertEquals(LARGE_CHUNK, is.read(resultData));
    assertArrayEquals(data, resultData);
    assertEquals(44, is.read());
    assertEquals(123, is.read());

    //Test read to an offset
    Arrays.fill(resultData, (byte) 0);
    assertEquals(SMALL_CHUNK, is.read(resultData, 50, SMALL_CHUNK));

    //Make sure the data read matches
    byte[] expectedData = new byte[LARGE_CHUNK];
    Arrays.fill(expectedData, (byte) 0);
    System.arraycopy(data2, 0, expectedData, 50, data2.length);
    assertArrayEquals(expectedData, resultData);

    assertEquals(-1, is.read());
    assertEquals(-1, is.read(data));
    is.close();

    //Test the skip interface
    is = file1.getInputStream();
    is.skip(LARGE_CHUNK + 3);

    Arrays.fill(resultData, (byte) 0);
    assertEquals(SMALL_CHUNK, is.read(resultData));

    Arrays.fill(expectedData, (byte) 0);
    System.arraycopy(data2, 0, expectedData, 0, data2.length);
    assertArrayEquals(expectedData, resultData);

    assertEquals(-1, is.read());
}

From source file:edu.utah.further.core.api.collections.ArrayUtil.java

/**
 * @param size//from   w  w  w  . j  a  va  2  s .c o  m
 * @param fillValue
 * @return
 */
public static String[] newStringVector(final int size, final String fillValue) {
    final String[] a = new String[size];
    Arrays.fill(a, fillValue);
    return a;
}

From source file:org.wso2.greg.plugin.client.GregManagerClient.java

/**
 * This method will generate artifact list in json format.
 * JSON objects contain information required to display artifact information in the plugin UI.
 *//* www . j  a v  a 2  s .  com*/
public List<ResourceInfo> generateArtifactList(String hostName, String port, String resourceType,
        String userName, char[] password, String tenantDomain, String productVersion)
        throws GregReadyPluginException {

    if (StringUtils.isNullOrEmpty(tenantDomain)) {
        tenantDomain = ResourceConstants.CARBON_SUPER;
    }

    JSONArray resourcesArray = getRegistryResources(hostName, port, resourceType, userName, password,
            tenantDomain);

    List<ResourceInfo> resourceInfos = new ArrayList();

    for (Object apiJsonObject : resourcesArray) {

        JSONObject assetJson = (JSONObject) apiJsonObject;

        String resourceName = assetJson.get(ResourceConstants.ArtifactInfo.NAME).toString();
        String version = assetJson.get(ResourceConstants.ArtifactInfo.VERSION).toString();
        String description = "";

        if (assetJson.get(ResourceConstants.ArtifactInfo.DESCRIPTION) != null) {
            description = assetJson.get(ResourceConstants.ArtifactInfo.DESCRIPTION).toString();
        }

        ResourceInfo resourceInfo = new ResourceInfo();
        resourceInfo.setName(resourceName);
        resourceInfo.setVersion(version);
        resourceInfo.setDescription(description);
        resourceInfo.setArtifactId(assetJson.get(ResourceConstants.ArtifactInfo.ID).toString());
        resourceInfo.setProductVersion(productVersion);

        String contentDocLink = "https://" + userName + ":" + String.valueOf(password) + "@" + hostName + ":"
                + port + ResourceConstants.URLS.GOVERNANCE_API_URL;

        if (resourceType.equals(ResourceConstants.RESOURCE_TYPE_SWAGGER)) {
            contentDocLink += ResourceConstants.URLS.RESOURCE_SWAGGERS + "/";
        } else {
            contentDocLink += ResourceConstants.URLS.RESOURCES_WSDLS + "/";
        }
        contentDocLink += resourceInfo.getArtifactId() + ResourceConstants.URLS.CONTENT_URL + "?"
                + ResourceConstants.URLS.TENANT + "=" + tenantDomain;
        resourceInfo.setResourceContentDocLink(contentDocLink);
        resourceInfo.setResType(resourceType);
        resourceInfos.add(resourceInfo);
    }
    Arrays.fill(password, '*');
    return resourceInfos;
}

From source file:com.vmware.identity.rest.idm.data.PrivateKeyDTO.java

private static PrivateKey decodePrivateKey(String encoded, String algorithm)
        throws InvalidKeySpecException, NoSuchAlgorithmException {
    if (encoded == null) {
        return null;
    }//from   ww w  .java  2 s  .com

    byte[] clear = Base64.decodeBase64(encoded);
    PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(clear);
    KeyFactory fact = KeyFactory.getInstance(algorithm);
    PrivateKey privateKey = fact.generatePrivate(keySpec);
    Arrays.fill(clear, (byte) 0);
    return privateKey;
}

From source file:OogieDocumentConverter.java

protected void loadAndExport(String inputUrl, Map/*<String,Object>*/ loadProperties, String outputUrl,
        Map/*<String,Object>*/ storeProperties) throws Exception {
    XComponentLoader desktop = openOfficeConnection.getDesktop();
    XComponent document = desktop.loadComponentFromURL(inputUrl, "_blank", 0, toPropertyValues(loadProperties));
    if (document == null) {
        throw new OpenOfficeException("conversion failed: input document is null after loading");
    }/*from ww  w  .  j ava 2s.  c  om*/

    refreshDocument(document);

    try {

        outputUrl = FilenameUtils.getFullPath(outputUrl) + FilenameUtils.getBaseName(outputUrl);

        //          filter
        PropertyValue[] loadProps = new PropertyValue[4];

        // type of image
        loadProps[0] = new PropertyValue();
        loadProps[0].Name = "MediaType";
        loadProps[0].Value = "image/png";

        // Height and width
        PropertyValue[] filterDatas = new PropertyValue[4];
        for (int i = 0; i < 4; i++) {
            filterDatas[i] = new PropertyValue();
        }

        filterDatas[0].Name = "PixelWidth";
        filterDatas[0].Value = new Integer(this.width);
        filterDatas[1].Name = "PixelHeight";
        filterDatas[1].Value = new Integer(this.height);
        filterDatas[2].Name = "LogicalWidth";

        filterDatas[2].Value = new Integer(2000);
        filterDatas[3].Name = "LogicalHeight";
        filterDatas[3].Value = new Integer(2000);

        XDrawPagesSupplier pagesSupplier = (XDrawPagesSupplier) UnoRuntime
                .queryInterface(XDrawPagesSupplier.class, document);
        //System.out.println(pagesSupplier.toString());            
        XDrawPages pages = pagesSupplier.getDrawPages();
        int nbPages = pages.getCount();
        String[] slidenames = new String[nbPages];
        Arrays.fill(slidenames, "");

        for (int i = 0; i < nbPages; i++) {

            XDrawPage page = (XDrawPage) UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPage.class,
                    pages.getByIndex(i));
            XShapes xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, page);
            int top = 0;
            String slidename = "";
            for (int j = 0; j < xShapes.getCount(); j++) {
                XShape firstXshape = (XShape) UnoRuntime.queryInterface(XShape.class, xShapes.getByIndex(j));
                Point pos = firstXshape.getPosition();
                if (pos.Y < top || top == 0) {
                    XText xText = (XText) UnoRuntime.queryInterface(XText.class, firstXshape);
                    if (xText != null && xText.getString().length() > 0) {
                        top = pos.Y;
                        slidename = xText.getString();
                    }
                }
            }

            String slidenameDisplayed = "";
            if (slidename.trim().length() == 0) {
                slidename = "slide" + (i + 1);
            } else {
                int nbSpaces = 0;
                String formatedSlidename = "";
                slidename = slidename.replaceAll(" ", "_");
                slidename = slidename.replaceAll("\n", "_");
                slidename = slidename.replaceAll("__", "_");

                for (int j = 0; j < slidename.length(); j++) {
                    char currentChar = slidename.charAt(j);
                    if (currentChar == '_') {
                        nbSpaces++;
                    }
                    if (nbSpaces == 5) {
                        break;
                    }
                    formatedSlidename += slidename.charAt(j);
                }

                slidenameDisplayed = formatedSlidename;

                slidename = formatedSlidename.toLowerCase();
                slidename = slidename.replaceAll("\\W", "_");
                slidename = slidename.replaceAll("__", "_");
                slidename = StringOperation.sansAccent(slidename);

            }
            int j = 1;
            String slidenamebackup = slidename;
            Arrays.sort(slidenames);
            while (Arrays.binarySearch(slidenames, slidename) >= 0) {
                j++;
                slidename = slidenamebackup + j;
            }
            slidenames[nbPages - (i + 1)] = slidename;

            XNamed xPageName = (XNamed) UnoRuntime.queryInterface(XNamed.class, page);

            xPageName.setName(slidename);

            XMultiComponentFactory localServiceManager = ((DokeosSocketOfficeConnection) this.openOfficeConnection)
                    .getServiceManager();
            Object GraphicExportFilter = localServiceManager.createInstanceWithContext(
                    "com.sun.star.drawing.GraphicExportFilter",
                    ((DokeosSocketOfficeConnection) this.openOfficeConnection).getComponentContext());

            XExporter xExporter = (XExporter) UnoRuntime.queryInterface(XExporter.class, GraphicExportFilter);

            XComponent xComp = (XComponent) UnoRuntime.queryInterface(XComponent.class, page);

            xExporter.setSourceDocument(xComp);
            loadProps[1] = new PropertyValue();
            loadProps[1].Name = "URL";

            loadProps[1].Value = outputUrl + "/" + xPageName.getName() + ".png";
            loadProps[2] = new PropertyValue();
            loadProps[2].Name = "FilterData";
            loadProps[2].Value = filterDatas;
            loadProps[3] = new PropertyValue();
            loadProps[3].Name = "Quality";
            loadProps[3].Value = new Integer(100);

            XFilter xFilter = (XFilter) UnoRuntime.queryInterface(XFilter.class, GraphicExportFilter);

            xFilter.filter(loadProps);
            if (slidenameDisplayed == "")
                slidenameDisplayed = xPageName.getName();
            System.out.println(slidenameDisplayed + "||" + xPageName.getName() + ".png");

        }

    } finally {
        document.dispose();
    }
}

From source file:clus.statistic.ClassificationStat.java

public void reset() {
    m_NbExamples = 0;//from  www  .  j a  v  a 2s .  c  om
    m_SumWeight = 0.0;
    Arrays.fill(m_SumWeights, 0.0);
    for (int i = 0; i < m_NbTarget; i++) {
        Arrays.fill(m_ClassCounts[i], 0.0);
    }
}