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

Java example source code file (Layers.js)

This example Java source code file (Layers.js) 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

layers

The Layers.js Java example source code

function Layers() {
    this.layers = [];
    this.totalLayers = 0;
    this.maximumX = 0;
    this.maximumY = 0;


    this.attach = function( layer) {
        this.layers.push(layer);
        this.totalLayers++;
        if (this.maximumX < layer.x) this.maximumX = layer.x;
        if (this.maximumY < layer.y) this.maximumY = layer.y;
    }

    this.getLayersForY = function(y) {
        var result = [];
            for (var i = 0; i < this.layers.length; i++) {
                if (this.layers[i].y == y) {
                    result.push(this.layers[i]);
                }
            }
         return result;
    }

    this.getLayersForX = function (x) {
        var result = [];
        for (var i = 0; i < this.layers.length; i++) {
            if (this.layers[i].x == x) {
                result.push(this.layers[i]);
            }
        }
        return result;
    }

    this.getLayerForXY = function (x, y) {
        var layerX = this.getLayersForX(x);
        for (var i = 0; i < layerX.length; i++) {
            if (layerX[i].y == y) return layerX[i];
        }
        return null;
    }

    this.getLayerForYX = function (x, y) {
            var layerY = this.getLayersForY(y);
            for (var i = 0; i < layerY.length; i++) {
                if (layerY[i].x == x) return layerY[i];
            }
            return null;
        }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java Layers.js 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.