source: java/main/src/main/java/com/framsticks/model/F0Genotype.java @ 78

Last change on this file since 78 was 78, checked in by psniegowski, 11 years ago

Add f0 parsing and f0->Model transformation.

File size: 2.4 KB
Line 
1package com.framsticks.model;
2
3import com.framsticks.util.Casting;
4import com.framsticks.util.Containers;
5import org.apache.log4j.Logger;
6
7import java.util.ArrayList;
8import java.util.Iterator;
9import java.util.List;
10
11/**
12 * Author: Piotr Śniegowski
13 */
14public class F0Genotype {
15
16        private final static Logger LOGGER = Logger.getLogger(F0Genotype.class);
17
18        public Double startingEnergy;
19        public Double getEnerg0() { return startingEnergy; }
20        public void setEnerg0(Double energ0) { startingEnergy = energ0; }
21
22        public Double getSe() { return startingEnergy; }
23        public void setSe(Double se) { startingEnergy = se; }
24
25        /** Vstyle */
26        public String visualizationStyle;
27        public String getVstyle() { return visualizationStyle; }
28        public void setVstyle(String Vstyle) { visualizationStyle = Vstyle; }
29
30        public final List<Part> parts = new ArrayList<Part>();
31        public final List<Joint> joints = new ArrayList<Joint>();
32        public final List<NeuroDef> neurodefs = new ArrayList<NeuroDef>();
33
34        public Double getNumparts() { return (double)parts.size(); }
35        public Double getNumjoints() { return (double)joints.size(); }
36        public Double getNumneurons() { return (double)neurodefs.size(); }
37
38        //this is impossible to use, because numparts field is marked as readonly
39        public void setNumparts(Double numparts) { Containers.resizeList(parts, (int) (double) numparts); }
40        public void setNumjoints(Double numjoints) { Containers.resizeList(joints, (int)(double)numjoints); }
41        public void setNumneurons(Double numneurons) { Containers.resizeList(neurodefs, (int)(double)numneurons); }
42
43        public List<Part> getParts() { return parts; }
44        public List<Joint> getJoints() { return joints; }
45        public List<NeuroDef> getNeuroDefs() { return neurodefs; }
46
47        public static F0Genotype build(List<Object> objects) {
48                Iterator<Object> i = objects.iterator();
49                if (!i.hasNext()) {
50                        return null;
51                }
52                F0Genotype f0Genotype = Casting.tryCast(F0Genotype.class, i.next());
53                if (f0Genotype == null) {
54                        LOGGER.fatal("first object is not a Model");
55                        return null;
56                }
57                while (i.hasNext()) {
58                        Object object = i.next();
59                        if (object instanceof Joint) {
60                                f0Genotype.joints.add((Joint)object);
61                                continue;
62                        }
63                        if (object instanceof Part) {
64                                f0Genotype.parts.add((Part)object);
65                                continue;
66                        }
67                        if (object instanceof NeuroDef) {
68                                f0Genotype.neurodefs.add((NeuroDef) object);
69                                continue;
70                        }
71                        LOGGER.error("invalid class: " + object.getClass().getCanonicalName());
72                }
73                return f0Genotype;
74        }
75}
Note: See TracBrowser for help on using the repository browser.