@Test
  public void checkInstanceReplication() {

    TestApplicationTemplate tpl = new TestApplicationTemplate();
    Application app = new Application(tpl);

    Assert.assertEquals(5, InstanceHelpers.getAllInstances(app).size());
    Assert.assertEquals(5, InstanceHelpers.getAllInstances(tpl).size());

    for (Instance inst : InstanceHelpers.getAllInstances(tpl)) {

      String instancePath = InstanceHelpers.computeInstancePath(inst);
      Instance copiedInstance = InstanceHelpers.findInstanceByPath(app, instancePath);
      Assert.assertNotNull(copiedInstance);

      Assert.assertEquals(inst.getName(), copiedInstance.getName());
      Assert.assertEquals(inst.getComponent(), copiedInstance.getComponent());
      Assert.assertEquals(inst.getImports(), copiedInstance.getImports());
      Assert.assertEquals(inst.getParent(), copiedInstance.getParent());
      Assert.assertEquals(inst.getChildren().size(), copiedInstance.getChildren().size());

      // Paths are the same, so the children are equal (even if they are not the same object)
      Assert.assertEquals(inst.getChildren(), copiedInstance.getChildren());
      Assert.assertEquals(inst.channels, copiedInstance.channels);
      Assert.assertEquals(inst.overriddenExports, copiedInstance.overriddenExports);
      Assert.assertEquals(inst.data, copiedInstance.data);

      Assert.assertFalse(inst == copiedInstance);
    }
  }
Exemplo n.º 2
0
 public void testUndoCreateSimpleInstance() {
   Cls cls = createCls();
   Instance instance = createSimpleInstance(cls);
   String name = instance.getName();
   assertNotNull("name", name);
   Frame frame = getFrame(name);
   assertEquals("created", instance, frame);
   assertTrue("can undo", _frameStore.canUndo());
   _frameStore.undo();
   frame = getFrame(name);
   assertNull("undone", frame);
   _frameStore.redo();
   instance = (Instance) getFrame(name);
   assertEquals("recreated", instance.getName(), name);
 }
Exemplo n.º 3
0
 public Instance pipe(Instance carrier) {
   TokenSequence ts = (TokenSequence) carrier.getData();
   TokenSequence targets =
       carrier.getTarget() instanceof TokenSequence ? (TokenSequence) carrier.getTarget() : null;
   TokenSequence source =
       carrier.getSource() instanceof TokenSequence ? (TokenSequence) carrier.getSource() : null;
   StringBuffer sb = new StringBuffer();
   if (prefix != null) sb.append(prefix);
   sb.append("name: " + carrier.getName() + "\n");
   for (int i = 0; i < ts.size(); i++) {
     if (source != null) {
       sb.append(source.get(i).getText());
       sb.append(' ');
     }
     if (carrier.getTarget() instanceof TokenSequence) {
       sb.append(((TokenSequence) carrier.getTarget()).get(i).getText());
       sb.append(' ');
     }
     if (carrier.getTarget() instanceof FeatureSequence) {
       sb.append(((FeatureSequence) carrier.getTarget()).getObjectAtPosition(i).toString());
       sb.append(' ');
     }
     PropertyList pl = ts.get(i).getFeatures();
     if (pl != null) {
       PropertyList.Iterator iter = pl.iterator();
       while (iter.hasNext()) {
         iter.next();
         double v = iter.getNumericValue();
         if (v == 1.0) sb.append(iter.getKey());
         else sb.append(iter.getKey() + '=' + v);
         sb.append(' ');
       }
     }
     sb.append('\n');
   }
   System.out.print(sb.toString());
   return carrier;
 }
  /**
   * @param args
   * @throws InvalidEducationValueException
   */
  public static void main(String[] args) throws InvalidEducationValueException {
    final ClusterNumberFormat cnf = new ClusterNumberFormat();
    final ClusterTestData ctd = new ClusterTestData();

    Cluster tempClusterI = null;
    Cluster tempClusterJ = null;
    Cluster minClusterA = null;
    Cluster minClusterB = null;
    Instance tempClusterIInstance = null;
    Instance tempClusterJInstance = null;
    Instance minInstanceA = null;
    Instance minInstanceB = null;

    double dist = 0.0;
    double minDist = Double.POSITIVE_INFINITY;

    ArrayList<Cluster> clusters = ctd.getClusters();

    while (clusters.size() > 1) {
      for (int i = 0; i < clusters.size(); i++) {
        for (int j = i + 1; j < clusters.size(); j++) {
          tempClusterI = clusters.get(i);
          tempClusterJ = clusters.get(j);

          System.out.println(
              "Cluster "
                  + tempClusterI.getName()
                  + " has Instance(s) "
                  + tempClusterI.getInstancesNameSet());
          System.out.println(
              "Cluster "
                  + tempClusterJ.getName()
                  + " has Instance(s) "
                  + tempClusterJ.getInstancesNameSet());

          for (int k = 0; k < tempClusterI.size(); k++) {
            for (int l = 0; l < tempClusterJ.size(); l++) {
              tempClusterIInstance = tempClusterI.get(k);
              tempClusterJInstance = tempClusterJ.get(l);

              dist = ClusterCalculation.distance(tempClusterIInstance, tempClusterJInstance);

              System.out.println(
                  "   DIST("
                      + tempClusterIInstance.getName()
                      + ","
                      + tempClusterJInstance.getName()
                      + ") = "
                      + cnf.format(dist));

              if (dist < minDist) {
                minDist = dist;
                minClusterA = tempClusterI;
                minInstanceA = tempClusterIInstance;
                minClusterB = tempClusterJ;
                minInstanceB = tempClusterJInstance;
              }
            }
          }
        }
      }

      System.out.println(
          "*** Minimum exists between Instance "
              + minInstanceA.getName()
              + " of Cluster "
              + minClusterA.getName()
              + " and Instance "
              + minInstanceB.getName()
              + " of Cluster "
              + minClusterB.getName()
              + " with a distance of "
              + cnf.format(minDist));
      System.out.print(
          "  * Merging cluster "
              + minClusterB.getName()
              + " into cluster "
              + minClusterA.getName()
              + ": ");

      // minClusterA and minClusterB are the two clusters with the closest member Instance(s).
      // Merge B into A and remove B from the list of Clusters.
      minClusterA.merge(minClusterB);
      clusters.remove(minClusterB);

      System.out.println(
          "Cluster "
              + minClusterA.getName()
              + " now contains instance(s) "
              + minClusterA.getInstancesNameSet());

      minDist = Double.POSITIVE_INFINITY;
    }
  }
Exemplo n.º 5
0
 public String toString() {
   return index + " : " + inst.getName() + "\t// " + DF.format(score);
 }