Example usage for java.io Serializable Serializable

List of usage examples for java.io Serializable Serializable

Introduction

In this page you can find the example usage for java.io Serializable Serializable.

Prototype

Serializable

Source Link

Usage

From source file:com.ebay.pulsar.analytics.metricstore.druid.aggregator.AggregatorTest.java

public void testCardinalityAggregator() {
    String aggregatorName = "CardAggrTest";
    List<String> fieldNames = new ArrayList<String>();
    String field1 = "Field1";
    String field2 = "Field2";
    fieldNames.add(field1);//from w  w  w  . jav  a2 s . c o m
    fieldNames.add(field2);

    CardinalityAggregator cardAggr = new CardinalityAggregator(aggregatorName, fieldNames);

    cardAggr.setByRow(true);
    boolean byRow = cardAggr.getByRow();
    assertTrue("Property byRow must be TRUE", byRow);
    List<String> fieldNamesGot = cardAggr.getFieldNames();
    assertEquals("1st Field must be 'Field1'", field1, fieldNamesGot.get(0));
    assertEquals("2nd Field must be 'Field2'", field2, fieldNamesGot.get(1));

    byte[] cacheKey = cardAggr.cacheKey();

    String hashCacheKeyExpected = "ecdec9686d4e3f4e137ae430691c5becc2a21192";
    String hashCacheKeyGot = DigestUtils.shaHex(cacheKey);
    assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot);
    AggregatorType type = cardAggr.getType();
    assertEquals("Type NOT Equals", AggregatorType.cardinality, type);

    String aggregatorName2 = "CardAggrTest2";
    List<String> fieldNames2 = new ArrayList<String>();
    String field21 = "Field21";
    String field22 = "Field22";
    fieldNames2.add(field21);
    fieldNames2.add(field22);

    CardinalityAggregator agg2 = new CardinalityAggregator(aggregatorName2, fieldNames2);
    CardinalityAggregator agg3 = new CardinalityAggregator(aggregatorName2, fieldNames2);
    assertTrue(agg2.hashCode() == agg3.hashCode());
    assertTrue(agg2.equals(agg3));
    assertTrue(agg2.equals(agg2));
    agg3.setByRow(true);
    assertTrue(!agg2.equals(agg3));
    assertTrue(!agg3.equals(agg2));
    agg3.setByRow(false);
    assertTrue(agg2.equals(agg2));
    assertTrue(!agg2.equals(cardAggr));
    assertTrue(!agg2.equals(null));
    agg3 = new CardinalityAggregator(aggregatorName2, null);
    assertTrue(!agg2.equals(agg3));
    assertTrue(!agg3.equals(agg2));
    assertTrue(!agg2.equals(new Serializable() {
        private static final long serialVersionUID = 1L;
    }));
    assertTrue(!new Serializable() {
        private static final long serialVersionUID = 1L;
    }.equals(agg2));

}

From source file:com.ebay.pulsar.analytics.metricstore.druid.aggregator.AggregatorTest.java

public void testCountAggregator() {
    String aggregatorName = "CountAggrTest";

    CountAggregator countAggr = new CountAggregator(aggregatorName);

    byte[] cacheKey = countAggr.cacheKey();

    String hashCacheKeyExpected = "36f680f51c5c6c258211a80db8498fda80c748f9";
    String hashCacheKeyGot = DigestUtils.shaHex(cacheKey);
    assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot);
    AggregatorType type = countAggr.getType();
    assertEquals("Type NOT Equals", AggregatorType.count, type);

    String aggregatorName2 = "CardAggrTest2";
    CountAggregator agg2 = new CountAggregator(aggregatorName2);
    CountAggregator agg3 = new CountAggregator(aggregatorName2);
    assertTrue(agg2.hashCode() == agg3.hashCode());
    assertTrue(agg2.equals(agg2));/*w w w. j a va  2s.  c o  m*/
    assertTrue(agg2.equals(agg3));
    assertTrue(!agg2.equals(null));
    agg3 = new CountAggregator(aggregatorName);
    assertTrue(!agg2.equals(agg3));
    assertTrue(!agg3.equals(agg2));
    assertTrue(!agg2.equals(new Serializable() {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;
    }));
    assertTrue(!new Serializable() {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;
    }.equals(agg2));

}

From source file:org.nanocontainer.avalon.AvalonUtilTestCase.java

public void testGetActivityLifecycleProxyHandlesEqualsAndHashCodeProperly() throws Exception {
    final Object obj = new Serializable() {
        public String toString() {
            return "blaat";
        }//w  w  w  . j  av  a  2s  . c o  m
    };
    final Object proxy = AvalonUtil.getActivityLifecycleProxy(obj);

    assertFalse(proxy.equals(obj));
    assertTrue(proxy.equals(proxy));

    assertTrue(proxy.hashCode() == proxy.hashCode());
    assertFalse(proxy.hashCode() == obj.hashCode());

    assertFalse("blaat".equals(proxy.toString()));
}

From source file:org.seasar.mayaa.impl.engine.specification.SpecificationNodeImpl.java

private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
    out.defaultWriteObject();/*ww w.  j a  va2 s .  co  m*/
    // namespace
    out.writeUTF(super.toString());
    if (getParentSpace() != null && getParentSpace().getClass() == NamespaceImpl.class) {
        out.writeObject(getParentSpace());
    } else {
        out.writeObject(new Serializable() {
            private static final long serialVersionUID = 1L;
        });
    }
}