home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (ModelInfo.java)

This example Java source code file (ModelInfo.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

arraylist, data, layerinfo, linkedhashset, modelinfo, serializable, set, util

The ModelInfo.java Java example source code

package org.deeplearning4j.ui.flow.beans;

import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import lombok.Data;
import lombok.NonNull;
import org.deeplearning4j.berkeley.Pair;

import java.io.Serializable;
import java.util.*;

/**
 * This bean works as holder for unbounded list of layers. Each layer has it's own place in model's virtual coordinate space.
 * For now, coordinate space is limited to 2 dimensions
 *
 * @author raver119@gmail.com
 */
@Data
public class ModelInfo implements Serializable {
    private final static long serialVersionUID = 119L;
    private long time = System.currentTimeMillis();
    private transient int counter = 0;

    // PLEASE NOTE: Inverted coords here -> Y, X LayerInfo
    //private Table<Integer, Integer, LayerInfo> layers = HashBasedTable.create();
   // private Map<Pair layers = new LinkedHashMap<>();
    private List<LayerInfo> layers = new ArrayList<>();

    /**
     * This method maps given layer into model coordinate space
     * @param layer
     */
    public synchronized void addLayer(@NonNull LayerInfo layer) {
        if (!layers.contains(layer)) {
            layer.setId(counter);
            this.layers.add(layer);
            counter++;
        }
    }

    /**
     * This method returns LayerInfo for specified layer name
     * @param name
     * @return
     */
    public LayerInfo getLayerInfoByName(String name) {
        for (LayerInfo layerInfo: layers) {
            if (layerInfo.getName().equalsIgnoreCase(name)) return layerInfo;
        }
        return null;
    }

    /**
     * This method returns LayerInfo for specified grid coordinates
     * @param x
     * @param y
     * @return
     */
    public LayerInfo getLayerInfoByCoords(int x, int y) {
        for (LayerInfo layerInfo: layers) {
            if (layerInfo.getX() == x && layerInfo.getY() == y) return layerInfo;
        }

        return null;
    }

    /**
     * This method returns the total number of nodes within described model
     *
     * @return number of elements
     */
    public int size() {
        return layers.size();
    }

    /**
     * This method returns all LayerTypes used in this model
     * @return
     */
    public Set<String> getLayerTypes() {
        Set<String> set = new LinkedHashSet<>();

        for (LayerInfo layerInfo: layers) {
            set.add(layerInfo.getLayerType());
        }
        return set;
    }

    public Set<LayerInfo> getLayersByType(String layerType) {
        Set<LayerInfo> set = new LinkedHashSet<>();

        for (LayerInfo layerInfo: layers) {
            if (layerInfo.getLayerType().equals(layerType)) set.add(layerInfo);
        }

        return set;
    }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java ModelInfo.java source code file:



my book on functional programming

 

new blog posts

 

Copyright 1998-2019 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.