/** Clear all properties that already exist in destination PropertySet. */
  private void clearDestination() throws PropertyException {
    Iterator keys = destination.getKeys().iterator();

    while (keys.hasNext()) {
      String key = (String) keys.next();
      destination.remove(key);
    }
  }
  @Test
  public void storePropertySet() {
    PropertySet set = PropertySet.apply(propertySetName);
    set.set("host", "localhost");
    set.set("port", "6969");

    assertSuccess(storage.store(set));

    // assert the paths exist as expected
    try (CloseableZooKeeper zk = connection()) {
      assertSuccess(true, zk.exists(propertySetPath));
      assertSuccess(true, zk.exists(propertySetPath + "/host"));
      assertSuccess(true, zk.exists(propertySetPath + "/port"));
    }
  }
  @Test
  public void getPropertySet() {
    storePropertySet();

    Try<Option<PropertySet>> propertySet = storage.get(propertySetName);
    assertSuccess(propertySet);
    assertSome(propertySet.orNull()); // orNull will never happen, just to avoid exception mgmt
    PropertySet set =
        propertySet.orNull().orNull(); // //orNull will never happen, just to avoid exception mgmt

    // assert we got the properties stored in "storePropertySet"
    assertEquals(2, set.properties().size());
    assertSome("localhost", set.property("host"));
    assertSome("6969", set.property("port"));
  }
Example #4
0
 public int getHasPropertySetInternalId() {
   if (hasPropertySet == null) {
     return -1;
   } else {
     return hasPropertySet.getId();
   }
 }
  @Test
  public void storePropertyPath_overwrite() {
    storePropertySet();

    PropertySet set = PropertySet.apply(propertySetName);
    set.set("host", "localhost");

    assertSuccess(storage.store(set));

    // assert the paths exist as expected
    try (CloseableZooKeeper zk = connection()) {
      assertSuccess(true, zk.exists(propertySetPath));
      assertSuccess(true, zk.exists(propertySetPath + "/host"));
      assertSuccess(
          false, zk.exists(propertySetPath + "/port")); // there shall be no port node anymore
    }
  }
  public void cloneProperties() throws PropertyException {
    clearDestination();

    Iterator keys = source.getKeys().iterator();

    while (keys.hasNext()) {
      String key = (String) keys.next();
      cloneProperty(key);
    }
  }
Example #7
0
 public void test_of_list() {
   PropertiesFile test = PropertiesFile.of(CharSource.wrap(FILE2));
   Multimap<String, String> keyValues = ImmutableListMultimap.of("a", "x", "a", "y");
   assertEquals(test.getProperties(), PropertySet.of(keyValues));
   assertEquals(test.toString(), "{a=[x, y]}");
 }
 /**
  * Load.
  *
  * @throws Exception the exception
  */
 public void load() throws Exception {
   this.internalLoad(PropertySet.getFirstClassProperties());
 }
  /** Copy individual property from source to destination. */
  private void cloneProperty(String key) throws PropertyException {
    switch (source.getType(key)) {
      case PropertySet.BOOLEAN:
        destination.setBoolean(key, source.getBoolean(key));

        break;

      case PropertySet.INT:
        destination.setInt(key, source.getInt(key));

        break;

      case PropertySet.LONG:
        destination.setLong(key, source.getLong(key));

        break;

      case PropertySet.DOUBLE:
        destination.setDouble(key, source.getDouble(key));

        break;

      case PropertySet.STRING:
        destination.setString(key, source.getString(key));

        break;

      case PropertySet.TEXT:
        destination.setText(key, source.getText(key));

        break;

      case PropertySet.DATE:
        destination.setDate(key, source.getDate(key));

        break;

      case PropertySet.OBJECT:
        destination.setObject(key, source.getObject(key));

        break;

      case PropertySet.XML:
        destination.setXML(key, source.getXML(key));

        break;

      case PropertySet.DATA:
        destination.setData(key, source.getData(key));

        break;

      case PropertySet.PROPERTIES:
        destination.setProperties(key, source.getProperties(key));

        break;
    }
  }
Example #10
0
  private void loadStylesFromDOM(
      Document stylesDOM, Document contentDOM, boolean bAllParagraphsAreSoft) {
    // Flat xml: stylesDOM will be null and contentDOM contain everything
    // This is only the case for old versions of xmerge; newer versions
    // creates DOM for styles, content, meta and settings.
    NodeList list;

    // font declarations: Try old format first
    if (stylesDOM == null) {
      list = contentDOM.getElementsByTagName(XMLString.OFFICE_FONT_DECLS);
    } else {
      list = stylesDOM.getElementsByTagName(XMLString.OFFICE_FONT_DECLS);
    }
    // If that fails, try oasis format
    if (list.getLength() == 0) {
      if (stylesDOM == null) {
        list = contentDOM.getElementsByTagName(XMLString.OFFICE_FONT_FACE_DECLS);
      } else {
        list = stylesDOM.getElementsByTagName(XMLString.OFFICE_FONT_FACE_DECLS);
      }
    }

    if (list.getLength() != 0) {
      Node node = list.item(0);
      if (node.hasChildNodes()) {
        NodeList nl = node.getChildNodes();
        int nLen = nl.getLength();
        for (int i = 0; i < nLen; i++) {
          Node child = nl.item(i);
          if (child.getNodeType() == Node.ELEMENT_NODE) {
            if (child.getNodeName().equals(XMLString.STYLE_FONT_DECL)) {
              font.loadStyleFromDOM(child, false);
            } else if (child.getNodeName().equals(XMLString.STYLE_FONT_FACE)) {
              font.loadStyleFromDOM(child, false);
            }
          }
        }
      }
    }

    // soft formatting:
    if (stylesDOM == null) {
      list = contentDOM.getElementsByTagName(XMLString.OFFICE_STYLES);
    } else {
      list = stylesDOM.getElementsByTagName(XMLString.OFFICE_STYLES);
    }
    if (list.getLength() != 0) {
      loadStylesFromDOM(list.item(0), bAllParagraphsAreSoft);
    }

    // master styles:
    if (stylesDOM == null) {
      list = contentDOM.getElementsByTagName(XMLString.OFFICE_MASTER_STYLES);
    } else {
      list = stylesDOM.getElementsByTagName(XMLString.OFFICE_MASTER_STYLES);
    }
    if (list.getLength() != 0) {
      loadStylesFromDOM(list.item(0), bAllParagraphsAreSoft);
    }

    // hard formatting:
    // Load from styles.xml first. Problem: There may be name clashes
    // with automatic styles from content.xml
    if (stylesDOM != null) {
      list = stylesDOM.getElementsByTagName(XMLString.OFFICE_AUTOMATIC_STYLES);
      if (list.getLength() != 0) {
        loadStylesFromDOM(list.item(0), bAllParagraphsAreSoft);
      }
    }
    list = contentDOM.getElementsByTagName(XMLString.OFFICE_AUTOMATIC_STYLES);
    if (list.getLength() != 0) {
      loadStylesFromDOM(list.item(0), bAllParagraphsAreSoft);
    }

    // footnotes configuration:
    if (stylesDOM == null) {
      list = contentDOM.getElementsByTagName(XMLString.TEXT_FOOTNOTES_CONFIGURATION);
    } else {
      list = stylesDOM.getElementsByTagName(XMLString.TEXT_FOOTNOTES_CONFIGURATION);
    }
    if (list.getLength() != 0) {
      footnotes = new PropertySet();
      footnotes.loadFromDOM(list.item(0));
    }

    // endnotes configuration:
    if (stylesDOM == null) {
      list = contentDOM.getElementsByTagName(XMLString.TEXT_ENDNOTES_CONFIGURATION);
    } else {
      list = stylesDOM.getElementsByTagName(XMLString.TEXT_ENDNOTES_CONFIGURATION);
    }
    if (list.getLength() != 0) {
      endnotes = new PropertySet();
      endnotes.loadFromDOM(list.item(0));
    }

    // if it failed, try oasis format
    if (footnotes == null || endnotes == null) {
      if (stylesDOM == null) {
        list = contentDOM.getElementsByTagName(XMLString.TEXT_NOTES_CONFIGURATION);
      } else {
        list = stylesDOM.getElementsByTagName(XMLString.TEXT_NOTES_CONFIGURATION);
      }
      int nLen = list.getLength();
      for (int i = 0; i < nLen; i++) {
        String sClass = Misc.getAttribute(list.item(i), XMLString.TEXT_NOTE_CLASS);
        if ("endnote".equals(sClass)) {
          endnotes = new PropertySet();
          endnotes.loadFromDOM(list.item(i));
        } else {
          footnotes = new PropertySet();
          footnotes.loadFromDOM(list.item(i));
        }
      }
    }
  }
Example #11
0
  RTreeLoad(String[] args) {
    try {
      if (args.length != 4) {
        System.err.println(
            "Usage: RTreeLoad input_file tree_file capacity query_type [intersection | 10NN].");
        System.exit(-1);
      }

      LineNumberReader lr = null;

      try {
        lr = new LineNumberReader(new FileReader(args[0]));
      } catch (FileNotFoundException e) {
        System.err.println("Cannot open data file " + args[0] + ".");
        System.exit(-1);
      }

      // Create a disk based storage manager.
      PropertySet ps = new PropertySet();

      Boolean b = new Boolean(true);
      ps.setProperty("Overwrite", b);
      // overwrite the file if it exists.

      ps.setProperty("FileName", args[1]);
      // .idx and .dat extensions will be added.

      Integer i = new Integer(4096);
      ps.setProperty("PageSize", i);
      // specify the page size. Since the index may also contain user defined data
      // there is no way to know how big a single node may become. The storage manager
      // will use multiple pages per node if needed. Off course this will slow down performance.

      IStorageManager diskfile = new DiskStorageManager(ps);

      IBuffer file = new RandomEvictionsBuffer(diskfile, 10, false);
      // applies a main memory random buffer on top of the persistent storage manager
      // (LRU buffer, etc can be created the same way).

      // Create a new, empty, RTree with dimensionality 2, minimum load 70%, using "file" as
      // the StorageManager and the RSTAR splitting policy.
      PropertySet ps2 = new PropertySet();

      Double f = new Double(0.7);
      ps2.setProperty("FillFactor", f);

      i = new Integer(args[2]);
      ps2.setProperty("IndexCapacity", i);
      ps2.setProperty("LeafCapacity", i);
      // Index capacity and leaf capacity may be different.

      i = new Integer(2);
      ps2.setProperty("Dimension", i);

      ISpatialIndex tree = new RTree(ps2, file);

      int count = 0;
      int indexIO = 0;
      int leafIO = 0;
      int id, op;
      double x1, x2, y1, y2;
      double[] f1 = new double[2];
      double[] f2 = new double[2];

      long start = System.currentTimeMillis();
      String line = lr.readLine();

      while (line != null) {
        StringTokenizer st = new StringTokenizer(line);
        op = new Integer(st.nextToken()).intValue();
        id = new Integer(st.nextToken()).intValue();
        x1 = new Double(st.nextToken()).doubleValue();
        y1 = new Double(st.nextToken()).doubleValue();
        x2 = new Double(st.nextToken()).doubleValue();
        y2 = new Double(st.nextToken()).doubleValue();

        if (op == 0) {
          // delete

          f1[0] = x1;
          f1[1] = y1;
          f2[0] = x2;
          f2[1] = y2;
          Region r = new Region(f1, f2);

          if (tree.deleteData(r, id) == false) {
            System.err.println("Cannot delete id: " + id + " , count: " + count + ".");
            System.exit(-1);
          }
        } else if (op == 1) {
          // insert

          f1[0] = x1;
          f1[1] = y1;
          f2[0] = x2;
          f2[1] = y2;
          Region r = new Region(f1, f2);

          String data = r.toString();
          // associate some data with this region. I will use a string that represents the
          // region itself, as an example.
          // NOTE: It is not necessary to associate any data here. A null pointer can be used. In
          // that
          // case you should store the data externally. The index will provide the data IDs of
          // the answers to any query, which can be used to access the actual data from the external
          // storage (e.g. a hash table or a database table, etc.).
          // Storing the data in the index is convinient and in case a clustered storage manager is
          // provided (one that stores any node in consecutive pages) performance will improve
          // substantially,
          // since disk accesses will be mostly sequential. On the other hand, the index will need
          // to
          // manipulate the data, resulting in larger overhead. If you use a main memory storage
          // manager,
          // storing the data externally is highly recommended (clustering has no effect).
          // A clustered storage manager is NOT provided yet.
          // Also you will have to take care of converting you data to and from binary format, since
          // only
          // array of bytes can be inserted in the index (see RTree::Node::load and
          // RTree::Node::store for
          // an example of how to do that).

          // tree.insertData(data.getBytes(), r, id);

          tree.insertData(null, r, id);
          // example of passing a null pointer as the associated data.
        } else if (op == 2) {
          // query

          f1[0] = x1;
          f1[1] = y1;
          f2[0] = x2;
          f2[1] = y2;

          MyVisitor vis = new MyVisitor();

          if (args[3].equals("intersection")) {
            Region r = new Region(f1, f2);
            tree.intersectionQuery(r, vis);
            // this will find all data that intersect with the query range.
          } else if (args[3].equals("10NN")) {
            Point p = new Point(f1);
            tree.nearestNeighborQuery(10, p, vis);
            // this will find the 10 nearest neighbors.
          } else {
            System.err.println("Unknown query type.");
            System.exit(-1);
          }
        }

        if ((count % 1000) == 0) System.err.println(count);

        count++;
        line = lr.readLine();
      }

      long end = System.currentTimeMillis();

      System.err.println("Operations: " + count);
      System.err.println(tree);
      System.err.println("Minutes: " + ((end - start) / 1000.0f) / 60.0f);

      // since we created a new RTree, the PropertySet that was used to initialize the structure
      // now contains the IndexIdentifier property, which can be used later to reuse the index.
      // (Remember that multiple indices may reside in the same storage manager at the same time
      //  and every one is accessed using its unique IndexIdentifier).
      Integer indexID = (Integer) ps2.getProperty("IndexIdentifier");
      System.err.println("Index ID: " + indexID);

      boolean ret = tree.isIndexValid();
      if (ret == false) System.err.println("Structure is INVALID!");

      // flush all pending changes to persistent storage (needed since Java might not call finalize
      // when JVM exits).
      tree.flush();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }