Example usage for com.mongodb BasicDBList get

List of usage examples for com.mongodb BasicDBList get

Introduction

In this page you can find the example usage for com.mongodb BasicDBList get.

Prototype

public Object get(final String key) 

Source Link

Document

Gets a value at an index.

Usage

From source file:tango.gui.MeasurementDisplayer.java

License:Open Source License

public void setObjects(List selectedObjects) {
    eraseText();//from   ww  w  .  j a v  a 2  s. c o m
    if (currentStructures == null) {
        refreshText();
        return;
    }
    if (selectedObjects == null || selectedObjects.size() == 0) { //display misc & number
        if (currentDBOs != null)
            for (BasicDBObject o : currentDBOs)
                append(o);
        label.setText("structures");
    } else if (selectedObjects.size() == 1) { //display o
        Object3DGui o = (Object3DGui) selectedObjects.get(0);
        append(Core.getExperiment().getConnector().getObject(nucId, o.getChannel().getIdx(), o.getLabel(),
                null));
        label.setText("object");
    } else if (selectedObjects.size() == 2) { //display o2o

        BasicDBObject disp = new BasicDBObject();
        Object3DGui o1 = (Object3DGui) selectedObjects.get(0);
        Object3DGui o2 = (Object3DGui) selectedObjects.get(1);
        int[] selStruct = new int[] { o1.getChannel().getIdx(), o2.getChannel().getIdx() };
        MeasurementKey key = new MeasurementKey(selStruct, MeasurementStructure.ArrayO2O); //currentStructures
        int size;
        int idx1 = 0;
        int idx2 = 0;
        for (int i = 0; i < currentStructures.length; i++) {
            if (currentStructures[i] == o1.getChannel().getIdx())
                idx1 = i;
            if (currentStructures[i] == o2.getChannel().getIdx())
                idx2 = i;
        }
        int idx, idxInv;
        if (idx1 != idx2) {
            idx = (o1.getLabel() - 1) * getCount(o2.getChannel().getIdx()) + o2.getLabel() - 1;
            idxInv = (o2.getLabel() - 1) * getCount(o1.getChannel().getIdx()) + o1.getLabel() - 1;
            size = getCount(o1.getChannel().getIdx()) * getCount(o2.getChannel().getIdx());
        } else {
            idx = (o1.getLabel() - 1) * getCount(o1.getChannel().getIdx())
                    - ((o1.getLabel() - 1) * o1.getLabel()) / 2 + o2.getLabel() - o1.getLabel() - 1;
            idxInv = idx;
            size = getCount(o1.getChannel().getIdx());
            size = size * (size - 1) / 2;
        }
        //System.out.println("idx"+idx+ " idx1:"+o1.getLabel()+ " idx2:"+o2.getLabel()+ " count1:"+getCount(o1.getChannel().getIdx())+ " count2:"+getCount(o2.getChannel().getIdx()));
        for (Map.Entry<MeasurementKey, ArrayList<String>> entry : Core.getExperiment().getKeys().entrySet()) {
            if (entry.getKey().includeO2O(key)) {
                BasicDBObject dbo = o2o.get(entry.getKey());
                if (dbo == null) {
                    dbo = Core.getExperiment().getConnector().getMeasurementStructure(nucId,
                            entry.getKey().getStructures(), entry.getValue(), true)[0];
                    o2o.put(entry.getKey(), dbo);
                }
                for (String k : entry.getValue()) {
                    Object o = dbo.get(k);
                    if (o != null) {
                        if (o instanceof BasicDBList) {
                            BasicDBList list = (BasicDBList) o;
                            if (list.size() == size) {
                                if (entry.getKey().invertedOrder(o1.getChannel().getIdx(),
                                        o2.getChannel().getIdx()))
                                    disp.append(k, list.get(idxInv));
                                else
                                    disp.append(k, list.get(idx));
                            }
                        } else if (size == 1 && o instanceof Number) {
                            disp.append(k, o);
                        }
                        //else disp.append(k, "Wrong Array Size");
                    } else
                        disp.append(k, null);
                }
            }
        }
        append(disp);
        label.setText("object to object");
    } else
        label.setText("");
    refreshText();
}

From source file:tango.gui.parameterPanel.MultiParameterPanel.java

License:Open Source License

public MultiParameterPanel(Core core, DBObject data, int minNb, int maxNb, Dimension minimumSize,
        PanelDisplayer panelDisplayer, boolean enableTest, Class<T> clazz) {
    this.core = core;
    this.enableTest = enableTest;
    this.minNbRows = maxNb == 1 ? 1 : Math.max(2, minimumSize.height / 40);
    this.maxNb = maxNb;
    this.minNb = minNb;
    this.panelDisplayer = panelDisplayer;
    this.clazz = clazz;
    this.data = data;
    this.panelElements = new ArrayList<PanelElementAbstract>();
    listLayout = new GridLayout(0, 1, 5, 0);
    this.listPanel = new JPanel(listLayout);
    this.listPanel.setMinimumSize(minimumSize);
    this.add = new JButton("Add");
    if (maxNb > 1) {
        Box addJP = Box.createHorizontalBox();
        addJP.add(Box.createHorizontalStrut(5));
        addJP.add(add);/*w w w .  ja  va2s.  c o m*/
        addJP.add(Box.createHorizontalGlue());
        listPanel.add(addJP);
        add.addActionListener(this);
    }
    if (this.data != null && maxNb > 1) {
        BasicDBList list = (BasicDBList) data;
        for (int i = 0; i < list.size(); i++) {
            addElement((BasicDBObject) list.get(i), i);
        }
    } else if (maxNb == 1) {
        if (this.data != null)
            addElement((BasicDBObject) data, 0);
        else
            addElement(null, 0);
    } else if (minNb > 0) {
        for (int i = 0; i < minNb; i++) {
            addElement(null, i);
        }
    }
}

From source file:tango.mongo.MongoConnector.java

License:Open Source License

public synchronized ImageHandler getInputImage(ObjectId field_id, int idx) {
    BasicDBObject query = new BasicDBObject("field_id", field_id).append("fileRank", idx);
    GridFSDBFile f = this.gfsField.findOne(query);
    if (f != null) {
        ImageHandler res = createImage(f);
        if (res != null) {
            return res;
        }/*ww w.  jav  a 2  s  .  c  om*/
    }
    // open from directory
    BasicDBObject field = this.getField(field_id);
    String error = "could'nt open file:" + idx + " from field:" + field.getString("name")
            + " please relink files by launching the command \"import files\"";
    if (field.containsField("files")) {
        BasicDBList files = (BasicDBList) field.get("files");
        if (files.size() > 1) { // separated files
            if (idx >= files.size()) {
                IJ.log(error);
            } else {
                BasicDBObject fileObj = (BasicDBObject) files.get(idx);
                File file = new File(fileObj.getString("path"));
                if (file.exists()) {
                    return ImageOpener.OpenChannel(file, 0, 0, 0);
                }

            }
        } else {
            BasicDBObject fileObj = (BasicDBObject) files.get(0);
            File file = new File(fileObj.getString("path"));
            if (file.exists()) {
                return ImageOpener.OpenChannel(file, idx, fileObj.getInt("series"),
                        fileObj.getInt("timePoint"));
            }
        }
    } else {
        IJ.log(error);
    }

    return null;
}

From source file:tango.mongo.MongoConnector.java

License:Open Source License

public synchronized byte[] createInputImageThumbnail(ObjectId field_id, int idx) {
    BasicDBObject query = new BasicDBObject("field_id", field_id).append("fileRank", idx);
    GridFSDBFile f = this.gfsField.findOne(query);
    if (f != null) {
        ImageHandler res = createImage(f);
        if (res != null) {
            return res.getThumbNail(Field.tmbSize, Field.tmbSize);
        }/* w  w w  . j a va2 s.  c o m*/
    }
    // open from directory
    BasicDBObject field = this.getField(field_id);
    String error = "could'nt open file:" + idx + " from field:" + field.getString("name")
            + " please relink files by launching the command \"import files\"";
    if (field.containsField("files")) {
        BasicDBList files = (BasicDBList) field.get("files");
        if (files.size() > 1) { // separated files
            if (idx >= files.size()) {
                IJ.log(error);
            } else {
                BasicDBObject fileObj = (BasicDBObject) files.get(idx);
                File file = new File(fileObj.getString("path"));
                if (file.exists()) {
                    return ImageOpener.openThumbnail(file, 0, 0, 0, Field.tmbSize, Field.tmbSize);
                }

            }
        } else {
            BasicDBObject fileObj = (BasicDBObject) files.get(0);
            File file = new File(fileObj.getString("path"));
            if (file.exists()) {
                return ImageOpener.openThumbnail(file, idx, fileObj.getInt("series"),
                        fileObj.getInt("timePoint"), Field.tmbSize, Field.tmbSize);
            }
        }
    } else {
        IJ.log(error);
    }
    return null;
}

From source file:tango.mongo.MongoUtils.java

License:Open Source License

public static int[] getIntArray(DBObject dbo, String key) {
    //IJ.log("mongoutils:"+dbo.get(key));
    if (!dbo.containsField(key))
        return null;
    Object o = dbo.get(key);//from  w w  w.  j  av a 2s . co m
    if (o instanceof BasicDBList) {
        BasicDBList list = ((BasicDBList) dbo.get(key));
        int[] res = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            res[i] = (Integer) (list.get("" + i));
        }
        return res;
    } else if (o instanceof int[])
        return (int[]) o;
    else
        return new int[] { (Integer) o };
}

From source file:tango.mongo.MongoUtils.java

License:Open Source License

public static double[] getDoubleArray(DBObject dbo, String key) {
    if (!dbo.containsField(key))
        return null;
    BasicDBList list = ((BasicDBList) dbo.get(key));
    double[] res = new double[list.size()];
    for (int i = 0; i < list.size(); i++) {
        res[i] = (Double) (list.get("" + i));
    }/*from  ww w. j  a v a 2s.  c o m*/
    return res;
}

From source file:tango.mongo.MongoUtils.java

License:Open Source License

public static float[] getFloatArray(BasicDBList list, String key) {
    float[] res = new float[list.size()];
    boolean field = false;
    for (int i = 0; i < list.size(); i++) {
        BasicDBObject o = ((BasicDBObject) list.get(i));
        if (o.containsField(key)) {
            field = true;//from   w  w  w  . j ava  2s .c  o  m
            res[i] = (float) o.getDouble(key);
        }
    }
    return field ? res : null;
}

From source file:tango.parameter.MultiParameter.java

License:Open Source License

@Override
public void dbGet(BasicDBObject dbo) {
    BasicDBObject subDBO = (BasicDBObject) dbo.get(id);
    if (subDBO == null)
        return;/*from www .j ava2s  . c o  m*/
    nb.dbGet(subDBO);
    majParameters(nb.getValue());
    Object o = subDBO.get("parameters");
    if (o != null) {
        BasicDBList list = (BasicDBList) o;
        int size = Math.min(parameters.size(), list.size()); // case of invalid parametrization 
        for (int i = 0; i < size; i++) {
            Parameter[] ps = parameters.get(i);
            BasicDBObject subSubDBO = (BasicDBObject) list.get(i);
            for (Parameter p : ps)
                p.dbGet(subSubDBO);
        }
    }
    toggleVisibility(!subDBO.getBoolean("isCollapsed", false));
    majPanel();
}

From source file:tango.plugin.filter.PostFilterSequence.java

License:Open Source License

public PostFilterSequence(BasicDBObject type, int nbCPUs, boolean verbose) {
    if (type == null || !type.containsField("postFilters"))
        return;/*from  ww w.ja v a  2s  .  c om*/
    BasicDBList prefilters = (BasicDBList) type.get("postFilters");
    filters = new ArrayList<PostFilter>(prefilters.size());
    for (int i = 0; i < prefilters.size(); i++) {
        Object o = prefilters.get(i);
        if (o != null) {
            BasicDBObject data = (BasicDBObject) o;
            if (!data.getBoolean("isActivated", true)) {
                filters.add(new DummyPostFilter());
                continue;
            }
            PostFilter f = PluginFactory.getPostFilter(data.getString("method"));
            if (f != null) {
                Parameter[] parameters = f.getParameters();
                for (Parameter p : parameters)
                    p.dbGet(data);
                filters.add(f);
                f.setMultithread(nbCPUs);
                f.setVerbose(verbose);
            }
        }
    }
}

From source file:tango.plugin.filter.PreFilterSequence.java

License:Open Source License

public PreFilterSequence(BasicDBObject settings, int nbCPUs, boolean verbose) {
    if (settings == null || !settings.containsField("preFilters"))
        return;//from  www.ja  v a 2s  .c o  m
    BasicDBList prefilters = (BasicDBList) settings.get("preFilters");
    filters = new ArrayList<PreFilter>(prefilters.size());
    for (int i = 0; i < prefilters.size(); i++) {
        //IJ.log(i+"");
        Object o = prefilters.get(i);
        if (o != null) {
            BasicDBObject data = (BasicDBObject) o;
            //IJ.log("preFilter:"+data);
            if (!data.getBoolean("isActivated", true)) {
                filters.add(new DummyPreFilter());
                continue;
            }
            PreFilter f = PluginFactory.getPreFilter(data.getString("method"));
            if (f != null) {
                //IJ.log("preFilter loaded:"+f.getId());
                Parameter[] parameters = f.getParameters();
                for (Parameter p : parameters)
                    p.dbGet(data);
                filters.add(f);
                f.setMultithread(nbCPUs);
                f.setVerbose(verbose);
            }
        }
    }
}