Skip to content

Commit

Permalink
#645: Deprecate getter for BitGene.
Browse files Browse the repository at this point in the history
  • Loading branch information
jenetics committed Jan 23, 2020
1 parent 216f15f commit 5ce7c1e
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 15 deletions.
Expand Up @@ -55,7 +55,7 @@ public OnesCounting(final int length, final double onesProbability) {

@Override
public Function<ISeq<BitGene>, Integer> fitness() {
return genes -> (int)genes.stream().filter(BitGene::getBit).count();
return genes -> (int)genes.stream().filter(BitGene::bit).count();
}

@Override
Expand Down
24 changes: 23 additions & 1 deletion jenetics.prog/src/main/java/io/jenetics/prog/ProgramGene.java
Expand Up @@ -52,7 +52,7 @@
* }</pre>
*
* @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
* @version 3.9
* @version !__version__!
* @since 3.9
*/
public final class ProgramGene<A>
Expand Down Expand Up @@ -124,6 +124,17 @@ public final A eval(final A... args) {
*
* @return the allowed operations
*/
public ISeq<Op<A>> operations() {
return ISeq.upcast(_operations);
}

/**
* Return the allowed operations.
*
* @return the allowed operations
* @deprecated Use {@link #operations()} instead
*/
@Deprecated
public ISeq<Op<A>> getOperations() {
return ISeq.upcast(_operations);
}
Expand All @@ -133,6 +144,17 @@ public ISeq<Op<A>> getOperations() {
*
* @return the allowed terminal operations
*/
public ISeq<Op<A>> terminals() {
return ISeq.upcast(_terminals);
}

/**
* Return the allowed terminal operations.
*
* @return the allowed terminal operations
* @deprecated Use {@link #terminals()} instead
*/
@Deprecated
public ISeq<Op<A>> getTerminals() {
return ISeq.upcast(_terminals);
}
Expand Down
2 changes: 1 addition & 1 deletion jenetics/src/main/java/io/jenetics/BitChromosome.java
Expand Up @@ -351,7 +351,7 @@ public byte[] toByteArray() {
public BitSet toBitSet() {
final BitSet set = new BitSet(length());
for (int i = 0, n = length(); i < n; ++i) {
set.set(i, get(i).getBit());
set.set(i, get(i).bit());
}
return set;
}
Expand Down
13 changes: 12 additions & 1 deletion jenetics/src/main/java/io/jenetics/BitGene.java
Expand Up @@ -28,7 +28,7 @@
*
* @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
* @since 1.0
* @version 4.0
* @version !__version__!
*/
public enum BitGene
implements
Expand All @@ -55,6 +55,17 @@ private BitGene(final boolean value) {
*
* @return The value of the BitGene.
*/
public final boolean bit() {
return _value;
}

/**
* Return the value of the BitGene.
*
* @return The value of the BitGene.
* @deprecated Use {@link #bit()} instead
*/
@Deprecated
public final boolean getBit() {
return _value;
}
Expand Down
10 changes: 5 additions & 5 deletions jenetics/src/test/java/io/jenetics/BitChromosomeTest.java
Expand Up @@ -77,7 +77,7 @@ public void invert() {
final BitChromosome c3 = c1.invert();

for (int i = 0; i < c1.length(); ++i) {
Assert.assertTrue(c1.get(i).getBit() != c3.get(i).getBit());
Assert.assertTrue(c1.get(i).bit() != c3.get(i).bit());
}

BitChromosome c4 = c3.invert();
Expand All @@ -99,12 +99,12 @@ public void numValue() {
public void intProbability() {
BitChromosome c = BitChromosome.of(10, 0);
for (BitGene g : c) {
assertFalse(g.getBit());
assertFalse(g.bit());
}

c = BitChromosome.of(10, 1);
for (BitGene g : c) {
assertTrue(g.getBit());
assertTrue(g.bit());
}
}

Expand All @@ -117,7 +117,7 @@ public void bitChromosomeBitSet() {

BitChromosome c = BitChromosome.of(bits);
for (int i = 0; i < bits.length(); ++i) {
assertEquals(c.get(i).getBit(), i % 2 == 0);
assertEquals(c.get(i).bit(), i % 2 == 0);
}
}

Expand Down Expand Up @@ -154,7 +154,7 @@ public void toBitSet() {
BitChromosome c2 = BitChromosome.of(c1.toBitSet(), 34);

for (int i = 0; i < c1.length(); ++i) {
assertEquals(c1.get(i).getBit(), c2.get(i).getBit());
assertEquals(c1.get(i).bit(), c2.get(i).bit());
}
}

Expand Down
8 changes: 4 additions & 4 deletions jenetics/src/test/java/io/jenetics/BitGeneTest.java
Expand Up @@ -47,10 +47,10 @@ public void equalsVerifier() {

@Test
public void testGetValue() {
assertFalse(BitGene.FALSE.getBit());
assertFalse(BitGene.ZERO.getBit());
assertTrue(BitGene.TRUE.getBit());
assertTrue(BitGene.ONE.getBit());
assertFalse(BitGene.FALSE.bit());
assertFalse(BitGene.ZERO.bit());
assertTrue(BitGene.TRUE.bit());
assertTrue(BitGene.ONE.bit());
}

@Test
Expand Down
Expand Up @@ -178,7 +178,7 @@ private static Phenotype<DoubleGene, Double> phenotype(final double value) {
@Test(invocationCount = 5)
public void onesCountLimit() {
final Problem<ISeq<BitGene>, BitGene, Integer> problem = Problem.of(
genes -> (int)genes.stream().filter(BitGene::getBit).count(),
genes -> (int)genes.stream().filter(BitGene::bit).count(),
Codec.of(
Genotype.of(BitChromosome.of(20, 0.125)),
gt -> ISeq.of(gt.chromosome())
Expand Down
Expand Up @@ -94,7 +94,7 @@ private static Phenotype<DoubleGene, Double> phenotype(final double value) {
@Test(invocationCount = 5)
public void onesCountLimit() {
final Problem<ISeq<BitGene>, BitGene, Integer> problem = Problem.of(
genes -> (int)genes.stream().filter(BitGene::getBit).count(),
genes -> (int)genes.stream().filter(BitGene::bit).count(),
Codec.of(
Genotype.of(BitChromosome.of(20, 0.125)),
gt -> ISeq.of(gt.chromosome())
Expand Down

0 comments on commit 5ce7c1e

Please sign in to comment.