@Test
  public void testCopyTo() {
    graph = createGraph();
    initExampleGraph(graph);
    GraphStorage gs = newRAMGraph();
    gs.setSegmentSize(8000);
    gs.create(10);
    try {
      graph.copyTo(gs);
      checkExampleGraph(gs);
    } catch (Exception ex) {
      ex.printStackTrace();
      assertTrue(ex.toString(), false);
    }

    try {
      Helper.close((Closeable) graph);
      graph = createGraph();
      gs.copyTo(graph);
      checkExampleGraph(graph);
    } catch (Exception ex) {
      ex.printStackTrace();
      assertTrue(ex.toString(), false);
    }
    Helper.close((Closeable) graph);
  }
  @Test
  public void testGetLocations() {
    graph = createGraph();
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 12, 23);
    na.setNode(1, 22, 23);
    assertEquals(2, graph.getNodes());

    graph.edge(0, 1, 10, true);
    assertEquals(2, graph.getNodes());

    graph.edge(0, 2, 10, true);
    assertEquals(3, graph.getNodes());
    Helper.close((Closeable) graph);

    graph = createGraph();
    assertEquals(0, graph.getNodes());
  }
  @Test
  public void testClone() {
    graph = createGraph();
    graph.edge(1, 2, 10, true);
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 12, 23);
    na.setNode(1, 8, 13);
    na.setNode(2, 2, 10);
    na.setNode(3, 5, 9);
    graph.edge(1, 3, 10, true);

    Graph clone = graph.copyTo(createGraph(locationParent + "/clone", false));
    assertEquals(graph.getNodes(), clone.getNodes());
    assertEquals(
        count(carOutExplorer.setBaseNode(1)),
        count(clone.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    clone.edge(1, 4, 10, true);
    assertEquals(3, count(clone.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    assertEquals(graph.getBounds(), clone.getBounds());
    Helper.close((Closeable) clone);
  }
 @After
 public void tearDown() {
   Helper.close((Closeable) graph);
   Helper.removeDir(new File(locationParent));
 }
Exemple #5
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
      return true;
    }

    if (id == R.id.action_append) {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setTitle(R.string.title_new);
      builder.setMessage(R.string.message_new);

      LayoutInflater inflater = getLayoutInflater();
      View view = inflater.inflate(R.layout.edittext, null);
      builder.setView(view);

      builder.setNegativeButton(R.string.button_cancel, null);
      final AlertDialog alertDialog = builder.create();
      EditText editText = (EditText) view.findViewById(R.id.editText);

      editText.setOnKeyListener(
          new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
              if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                EditText editText = (EditText) v;
                Editable editable = editText.getText();
                ContentValues contentValues = new ContentValues();
                contentValues.put("name", editable.toString());
                SQLiteDatabase database = helper.getWritableDatabase();
                database.insert(tableName, null, contentValues);
                adapter.changeCursor(helper.getCursor());
                alertDialog.dismiss();
                return true;
              }
              return false;
            }
          });

      alertDialog.show();
      return true;
    }

    if (id == R.id.action_delete_all) {
      // Delete all the records, but do not destroy the database itself.
      SQLiteDatabase database = helper.getWritableDatabase();
      database.delete(tableName, null, null);
      adapter.changeCursor(helper.getCursor());
      return true;
    }

    if (id == R.id.action_reset) {
      // Destroy the database and re-create it.
      helper.close();
      deleteDatabase(databaseName);
      helper = new Helper(this, databaseName);
      adapter.changeCursor(helper.getCursor());
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
 public void close() {
   if (helper != null) {
     helper.close();
   }
 }