Example #1
1
  @SuppressWarnings("unchecked")
  public <T> T getOrConstruct(Prop<T> key) {

    Prop<T> cc = key.findCannon();
    if (cc != null && cc.autoConstructor != null) {
      return (T) dictionary.computeIfAbsent(key, k -> cc.autoConstructor.get());
    }
    return get(key);
  }
Example #2
1
    public static <T> Prop<T> cannonicalize(Prop<T> p) {
      Prop<T> prop = cannon.computeIfAbsent(p.name, x -> p);
      if (p.isCannon() && !prop.isCannon()) {
        cannon.put(p.name, p);
        prop = p;
      } else if (p.isCannon() && prop.isCannon() && p != prop) {
        // should be an Error?
        System.err.println(" WARNING: two competing canonical definitions of a Prop <" + p + ">");
        if (p.typeInformation != null && prop.typeInformation == null) {
          cannon.put(p.name, p);
          prop = p;
        } else if (p.typeInformation == null && prop.typeInformation != null) {

        } else if (p.typeInformation != null && prop.typeInformation != null) {
          if (!Conversions.typeInformationEquals(p.typeInformation, prop.typeInformation)) {
            System.err.println(
                " ERROR: the two competing canonical definitions of "
                    + p
                    + " have different type information");
            throw new IllegalArgumentException(
                p.typeInformation + " " + prop.typeInformation + " " + p + " " + prop);
          }
        }
      }
      prop.setCannon();
      return prop;
    }
Example #3
0
 @Test
 public void testLoad() {
   assertTrue(prop.get("section1.a").equals("1"));
   assertTrue(prop.get("section1.a.b").equals("1999"));
   assertTrue(prop.get("section 2.a.b").equals("100"));
   assertTrue(prop.get("section 2.a.b.d").equals("5555555"));
   System.out.println("true");
 }
Example #4
0
  public static Prop makeFireProp(String name) {

    Prop fire = new Prop();
    fire.setId("fire");
    fire.setBrief("fire");
    fire.setAlias("fire");
    return fire;
  }
 void declareProperty(String name, String val, String expectEval, boolean isFinal)
     throws IOException {
   appendProperty(name, val, isFinal);
   Prop p = new Prop();
   p.name = name;
   p.val = val;
   p.expectEval = expectEval;
   props.add(p);
 }
Example #6
0
  @Test
  public void testStore() throws IOException {
    BufferedWriter writer = new BufferedWriter(new FileWriter("/home/x/tmp/ccc.prop"));
    // prop.store(writer);

    prop.add("section3", "abc.d", "abcccc", "some ttt");
    prop.add(null, "cc", "my name is cc", null);
    prop.store(writer);
  }
Example #7
0
 public static void postProperty() {
   String name = params.get("name");
   String value = params.get("value");
   Prop p = new Prop();
   p.name = name;
   p.value = value;
   p.save();
   renderText(p.id.toString());
 }
Example #8
0
  private int safeHash(Map<Prop, Object> d) {

    Set<Entry<Prop, Object>> ee = d.entrySet();
    int c = 0;
    for (Entry<Prop, Object> e : ee) {
      Prop k = e.getKey();
      Object v = e.getValue();
      c += k.hashCode();
      c += (v == null ? 0 : v.hashCode());
    }
    return c;
  }
Example #9
0
 public Dict getAttributes() {
   Prop on = this;
   if (!isCannon()) {
     Prop<T> already = (Prop<T>) findCannon();
     if (already == null) {
       toCannon();
       on.setCannon();
     } else {
       on = already;
     }
   }
   return on.attributes == null ? (on.attributes = new Dict()) : on.attributes;
 }
Example #10
0
    public <T> Prop<T> doc(String doc) {
      Prop on = this;
      if (!isCannon()) {
        Prop<T> already = (Prop<T>) findCannon();
        if (already == null) {
          toCannon();
          on.setCannon();
        } else {
          on = already;
        }
      }

      on.documentation = doc;
      return (Prop<T>) on;
    }
Example #11
0
    public <T> Prop<T> autoConstructs(Supplier<T> t) {
      Prop on = this;
      if (!isCannon()) {
        Prop<T> already = (Prop<T>) findCannon();
        if (already == null) {
          toCannon();
          on.setCannon();
        } else {
          on = already;
        }
      }

      on.autoConstructor = (Supplier) t;
      return (Prop<T>) on;
    }
Example #12
0
    @CallerSensitive
    public <T> Prop<T> type() {

      Prop on = this;
      if (!isCannon()) {
        Prop<T> already = (Prop<T>) findCannon();
        if (already == null) {
          toCannon();
          on.setCannon();
        } else {
          on = already;
        }
      }

      Class c = sun.reflect.Reflection.getCallerClass(2);

      on.definedInClass = c;

      Field f = null;
      try {
        f = c.getField(name);
      } catch (NoSuchFieldException e) {

        try {
          f = c.getField("_" + name);
        } catch (NoSuchFieldException e3) {
          if (name.startsWith("_"))
            try {
              f = c.getField(name.substring(1));
            } catch (NoSuchFieldException e1) {
              if (name.startsWith("__"))
                try {
                  f = c.getField(name.substring(1));
                } catch (NoSuchFieldException e2) {
                }
            }
        }
      }
      if (f == null)
        throw new IllegalStateException(
            " cannot type a Dict.Prop<T> that we can't find. Name is :" + name + " class is :" + c);

      on.typeInformation = Conversions.linearize(f.getGenericType());

      on.typeInformation.remove(0);

      return (Prop<T>) on;
    }
Example #13
0
 @BeforeClass
 public static void setUpBeforeClass() throws Exception {
   prop = new Prop();
   prop.load(
       new BufferedReader(
           new InputStreamReader(new FileInputStream(filePath), Charset.forName("utf-8"))));
 }
Example #14
0
 public void destroyProp() {
   prop.setDestroyed(true);
   // setDestroyed(true) b/c need to remove from CellGrid.PropList
   if (prop.isDestructable()) {
     // prop=null;
     solid = false;
   } else if (prop.isItemholder()) {
     // prop=null;
     solid = false;
   } else if (this.isLocked()) {
     solid = false;
   } else {
     System.out.println("Nothing to destroy. Why was Cell.destroyProp() called?");
   }
   // Add any other changes to conditionals here too
 }
Example #15
0
  public static void removeProperty() {
    String id = params.get("id");
    Prop p = Prop.findById(Long.valueOf(id));
    List<Specification> specifications =
        Specification.em()
            .createQuery(
                "select r from Specification r join fetch r.properties s where s.id="
                    + Long.valueOf(id),
                Specification.class)
            .getResultList();

    for (Specification spec : specifications) {
      spec.properties.remove(p);
      spec.save();
    }
    if (p != null) p.delete();
    renderText(id);
  }
Example #16
0
  /**
   * Initializes the scanner.
   *
   * @param f input file
   * @param pr database properties
   * @param frag allow parsing of document fragment
   * @throws IOException I/O exception
   */
  XMLScanner(final IO f, final Prop pr, final boolean frag) throws IOException {
    input = new XMLInput(f);
    fragment = frag;

    try {
      for (int e = 0; e < ENTITIES.length; e += 2) {
        ents.add(token(ENTITIES[e]), token(ENTITIES[e + 1]));
      }
      dtd = pr.is(Prop.DTD);
      chop = pr.is(Prop.CHOP);

      String enc = null;
      // process document declaration...
      if (consume(DOCDECL)) {
        if (s()) {
          if (!version()) error(DECLSTART);
          boolean s = s();
          enc = encoding();
          if (enc != null) {
            if (!s) error(WSERROR);
            s = s();
          }
          if (sddecl() != null && !s) error(WSERROR);
          s();
          final int ch = nextChar();
          if (ch != '?' || nextChar() != '>') error(DECLWRONG);
        } else {
          prev(5);
        }
      }
      encoding = enc == null ? UTF8 : enc;

      if (!fragment) {
        final int n = consume();
        if (!s(n)) {
          if (n != '<') error(BEFOREROOT);
          prev(1);
        }
      }
    } catch (final IOException ex) {
      input.close();
      throw ex;
    }
  }
Example #17
0
  /**
   * Initializes this object loading the initialization parameters. Does nothing if this method has
   * already been called, even if the previous call threw any exception.
   *
   * @throws Exception If any required parameter is undefined.
   */
  public void init(ServletConfig sc, Log log) throws Exception {
    if (!initCalled) {
      initCalled = true;
      // Read in the required properties:
      for (Prop prop : Prop.values()) {
        String value = sc.getInitParameter(prop.getName());
        if (value != null && value.trim().length() > 0) {
          prop.setValue(value);
        } else if (prop.getValue() == null) {
          throw new Exception("Required init parameter not defined: " + prop.getName());
        }
      }

      if (log != null && log.isDebugEnabled()) {
        for (Prop prop : Prop.values()) {
          log.debug(prop.getName() + " = " + prop.getValue());
        }
      }
    }
  }
Example #18
0
 public Model getModel() {
   Model model = ModelFactory.createDefaultModel();
   Resource itemNode = model.createResource(uri);
   for (Prop prop : values) {
     if (prop.isLiteral()) {
       itemNode.addLiteral(prop.getType(), model.createLiteral(prop.getValue()));
     } else {
       itemNode.addProperty(prop.getType(), model.createResource(prop.getValue()));
     }
   }
   return model;
 }
Example #19
0
  public synchronized void buildLines() {
    consumableArea = panel.getChildConsumableBounds();
    lines = new LinkedList<TextLayout>();

    if (text != null && text.length() > 0) {
      StyledTextParser parser = new StyledTextParser();
      textChunks = parser.parse(text);

      final Scene root = getRoot();
      if (root
          != null) // TODO MDM - It happens.... but how?  Ah!  Need to acquire tree lock when
                   // removing panels.
      {
        Map<String, RichStyle> styleMap = root.getStyles();
        for (StyledText styledText : textChunks) styledText.setupStyles(styleMap, getStyle(), this);
        // TODO MDM StyleObservers may cause a memory leak.  Styles keep track of panels that are no
        // longer used?

        addLines();
      }
    }
  }
Example #20
0
  @Override
  public String toString() {
    String content = "Item description:" + this.getUri();

    Iterator i = values.iterator();

    while (i.hasNext()) {
      Prop me = (Prop) i.next();
      String isL = "Uri";
      if (me.isLiteral()) isL = "Lit";
      String isS = " ";
      if (me.isIsSearchable()) isS = "*";
      content += "\n\t" + isS + " " + isL + " " + me.getType() + " : ";
      if (me.getValue().length() > 100) {
        content += me.getValue().substring(0, 100) + "...";
      } else {
        content += me.getValue();
      }
    }
    return content;
  }
Example #21
0
 public boolean canInteract() {
   return (hasProp() && prop.isInteractable());
 }
Example #22
0
  public static void impSpec(File file) {
    if (file != null) {
      List<Specification> specifications = new ArrayList<Specification>();
      Specification spec = null;
      Material material = null;
      try {
        FileInputStream fileInputStream = new FileInputStream(file);
        HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
        HSSFSheet worksheet = workbook.getSheetAt(0);
        HSSFRow row = null;
        HSSFCell cell = null;
        Map<Integer, String> headerMap = new HashMap<Integer, String>();
        Prop prop = null;
        if (worksheet.getLastRowNum() > 0) {
          row = worksheet.getRow(0);
          for (int i = 0; i < row.getLastCellNum(); i++) {
            headerMap.put(Integer.valueOf(i), row.getCell(i).getStringCellValue());
          }
        }
        for (int i = 1; i < worksheet.getLastRowNum(); i++) {
          row = worksheet.getRow(i);
          cell = row.getCell(0);
          String materialName = cell.getStringCellValue();

          cell = row.getCell(1);
          String specification = cell.getStringCellValue();

          cell = row.getCell(2);
          Double number = cell.getNumericCellValue();

          cell = row.getCell(3);
          String unit = cell.getStringCellValue();

          cell = row.getCell(4);
          String company = cell.getStringCellValue();

          cell = row.getCell(5);
          Date date = cell.getDateCellValue();

          cell = row.getCell(6);
          String description = cell.getStringCellValue();

          spec = new Specification();

          for (int x = 7; x < row.getLastCellNum(); x++) {
            cell = row.getCell(x);
            String value = "";
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            prop = new Prop();
            prop.name = headerMap.get(x);
            prop.value = value;
            prop.save();
            spec.properties.add(prop);
          }

          spec.name = specification;
          spec.specification = specification;
          if (number != null && !"".equals(number)) spec.amount = number;
          spec.unit = unit;
          spec.company = company;
          if (materialName != null && !"".equals(materialName)) {
            material = Material.find("name=?", materialName.trim()).first();
            spec.material = material;
          }
          spec.arrival_time = date;
          spec.description = description;
          spec.save();
          specifications.add(spec);
        }

        renderJSON(specifications);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Example #23
0
 public Graphics2D getGraphics() {
   if (graphics != null) return graphics;
   else return panel.getGraphics();
 }
Example #24
0
 public ScreenableStyle getStyle() {
   return panel.getStyle();
 }
Example #25
0
  /**
   * The main method.
   *
   * @param args the args
   */
  public static void main(String[] args) {

    ControladorDades cd = new ControladorDades();

    Vector<Activitat> v = new Vector<Activitat>();

    Sessio s = new Sessio();

    Descans d1 = new Descans("Coffe Break", 30);
    Descans d2 = new Descans("Short Break", 10);

    Temps tmp1 = new Temps(10, 10);
    Temps tmp2 = new Temps(14, 33);
    Temps tmp3 = new Temps(11, 55);
    Temps tmp4 = new Temps(15, 21);

    Tema t1 = new Tema("Prop");
    Tema t2 = new Tema("Historia");
    Tema t3 = new Tema("Filosofia");

    Autor a1 = new Autor("John", "Williams");
    Autor a2 = new Autor("James", "Horner");
    Comunicacio c1 = null, c2 = null;
    InclouDescans id1 = null, id2 = null;
    try {
      c1 = new Comunicacio("Como aprobar PROP en un fin de semana", 30);
      c1.AfegirTema(t1);
      c1.AfegirTema(t3);
      c1.SetSessio(s);
      c1.SetHInici(tmp1);
      c1.SetAutor(a1);

      id1 = new InclouDescans(tmp3, d1);
      id1.SetSessio(s);

      id2 = new InclouDescans(tmp4, d2);
      id2.SetSessio(s);

      c2 = new Comunicacio("Como incentivar al grupo de trabajo", 45);
      c2.AfegirTema(t2);
      c2.SetSessio(s);
      c2.SetHInici(tmp2);
      c2.SetAutor(a2);

    } catch (Exception e) {
      Prop.PS("Error en las pruebas");
    }
    v.add(c1);
    v.add(id1);
    v.add(c2);
    v.add(id2);

    cd.EscriureDadesDiscXML("horarix.xml", v);

    // ControladorDades cd2=new ControladorDades();
    // cd2.

    ControladorDades cd1 = new ControladorDades();
    Vector<Activitat> vww = cd1.LlegirDadesDiscXML("horarix.xml");
    Prop.PS("El vector te " + vww.size() + " elements");
    cd1.EscriureDadesDiscXML("horarix2.xml", vww);
  }
 @Override
 public boolean eval(Prop prop) throws Exception {
   return prop.getAnnotation(annotated) != null;
 }
Example #27
0
 public Image getPropImage() {
   return (prop.getSprite());
 }
Example #28
0
 public NodeSubscription(Prop p, String path, NodeFactory f, Callback cb) {
   mFactory = f;
   mCb = cb;
   id = STCore.subNodes((int) (p != null ? p.getPropId() : 0), path, this);
 }