Exemplo n.º 1
0
  /**
   * Asserts that the given protos are not equal and have different hash codes.
   *
   * @warning It's valid for non-equal objects to have the same hash code, so this test is stricter
   *     than it needs to be. However, this should happen relatively rarely.
   */
  private void checkNotEqual(Message m1, Message m2) {
    String equalsError = String.format("%s should not be equal to %s", m1, m2);
    assertFalse(equalsError, m1.equals(m2));
    assertFalse(equalsError, m2.equals(m1));

    assertFalse(
        String.format("%s should have a different hash code from %s", m1, m2),
        m1.hashCode() == m2.hashCode());
  }
Exemplo n.º 2
0
 @Override
 public CallTarget accessMessage(Message msg) {
   if (msg instanceof KnownMessage) {
     switch (msg.hashCode()) {
       case Execute.EXECUTE:
         return factory.accessExecute(((Execute) msg).getArity());
       case Execute.INVOKE:
         return factory.accessInvoke(((Execute) msg).getArity());
       case Execute.NEW:
         return factory.accessNew(((Execute) msg).getArity());
       case GetSize.HASH:
         return factory.accessGetSize();
       case HasSize.HASH:
         return factory.accessHasSize();
       case IsBoxed.HASH:
         return factory.accessIsBoxed();
       case IsExecutable.HASH:
         return factory.accessIsExecutable();
       case IsNull.HASH:
         return factory.accessIsNull();
       case Read.HASH:
         return factory.accessRead();
       case Unbox.HASH:
         return factory.accessUnbox();
       case Write.HASH:
         return factory.accessWrite();
     }
   }
   return factory.accessMessage(msg);
 }
Exemplo n.º 3
0
 /** {@inheritDoc} */
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((message == null) ? 0 : message.hashCode());
   result = prime * result + ((updateId == null) ? 0 : updateId.hashCode());
   return result;
 }
Exemplo n.º 4
0
  /** Asserts that the given protos are equal and have the same hash code. */
  private void checkEqualsIsConsistent(Message message) {
    // Object should be equal to itself.
    assertEquals(message, message);

    // Object should be equal to a dynamic copy of itself.
    DynamicMessage dynamic = DynamicMessage.newBuilder(message).build();
    assertEquals(message, dynamic);
    assertEquals(dynamic, message);
    assertEquals(dynamic.hashCode(), message.hashCode());
  }
  private void writeAll() {
    List<MessageBean> beans = messageTable.getBeans();
    HashMap<Integer, Message> map = new HashMap<Integer, Message>(2 * beans.size());

    for (MessageBean mb : beans) {
      map.put(mb.m.hashCode(), mb.m);
    }

    if (fileChooser == null)
      fileChooser = new FileManager(null, null, null, (PreferencesExt) prefs.node("FileManager"));

    String defloc = (raf.getLocation() == null) ? "." : raf.getLocation();
    String dirName = fileChooser.chooseDirectory(defloc);
    if (dirName == null) return;

    try {
      int count = 0;
      for (Message m : map.values()) {
        String header = m.getHeader();
        if (header != null) {
          header = header.split(" ")[0];
        } else {
          header = Integer.toString(Math.abs(m.hashCode()));
        }

        File file = new File(dirName + "/" + header + ".bufr");
        FileOutputStream fos = new FileOutputStream(file);
        WritableByteChannel wbc = fos.getChannel();
        wbc.write(ByteBuffer.wrap(m.getHeader().getBytes()));
        byte[] raw = scan.getMessageBytes(m);
        wbc.write(ByteBuffer.wrap(raw));
        wbc.close();
        count++;
      }
      JOptionPane.showMessageDialog(
          BufrMessageViewer.this, count + " successfully written to " + dirName);

    } catch (IOException e1) {
      JOptionPane.showMessageDialog(BufrMessageViewer.this, e1.getMessage());
      e1.printStackTrace();
    }
  }
Exemplo n.º 6
0
 /** Asserts that the given protos are equal and have the same hash code. */
 private void checkEqualsIsConsistent(Message message1, Message message2) {
   assertEquals(message1, message2);
   assertEquals(message2, message1);
   assertEquals(message2.hashCode(), message1.hashCode());
 }