Neuron implements Serializable { public boolean compareAndSetFeatures(double[] expect, double[] update) { if (update.length != size) { throw new DimensionMismatchException(update.length, size); } final double[] current = features.get(); if (!containSameValues(current, expect)) { return false; } if (features.compareAndSet(current, update.clone())) { return true; } else { return false; } } Neuron(long identifier,
           double[] features); long getIdentifier(); int getSize(); double[] getFeatures(); boolean compareAndSetFeatures(double[] expect,
                                         double[] update);  }
@Test public void testCompareAndSetFeatures() { final Neuron n = new Neuron(1, new double[] { 0 }); double[] expect = n.getFeatures(); double[] update = new double[] { expect[0] + 1.23 }; boolean ok = n.compareAndSetFeatures(expect, update); Assert.assertTrue(ok); Assert.assertEquals(update[0], n.getFeatures()[0], 0d); double[] update1 = new double[] { update[0] + 4.56 }; ok = n.compareAndSetFeatures(expect, update1); Assert.assertFalse(ok); Assert.assertEquals(update[0], n.getFeatures()[0], 0d); }