Skip to content

Commit 02b0ece

Browse files
committed
Add copy constructor to FastqBuilder.
1 parent 1e59bb5 commit 02b0ece

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

biojava-genome/src/main/java/org/biojava/nbio/genome/io/fastq/Fastq.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,19 @@ public static final FastqBuilder builder()
145145
{
146146
return new FastqBuilder();
147147
}
148+
149+
/**
150+
* Create and return a new FastqBuilder configured from the
151+
* specified FASTQ formatted sequence.
152+
* The FastqBuilder will not be null.
153+
*
154+
* @since 6.0.0
155+
* @param fastq FASTQ formatted sequence, must not be null
156+
* @return a new FastqBuilder configured from the specified FASTQ
157+
* formatted sequence
158+
*/
159+
public static final FastqBuilder builder(final Fastq fastq)
160+
{
161+
return new FastqBuilder(fastq);
162+
}
148163
}

biojava-genome/src/main/java/org/biojava/nbio/genome/io/fastq/FastqBuilder.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@ public FastqBuilder()
5151
// empty
5252
}
5353

54+
/**
55+
* Create a new FASTQ formatted sequence builder configured
56+
* from the specified FASTQ formatted sequence.
57+
*
58+
* @since 6.0.0
59+
* @param fastq FASTQ formatted sequence, must not be null
60+
*/
61+
public FastqBuilder(final Fastq fastq)
62+
{
63+
if (fastq == null)
64+
{
65+
throw new IllegalArgumentException("fastq must not be null");
66+
}
67+
withDescription(fastq.getDescription());
68+
withSequence(fastq.getSequence());
69+
withQuality(fastq.getQuality());
70+
withVariant(fastq.getVariant());
71+
}
72+
5473

5574
/**
5675
* Return the description for this FASTQ formatted sequence builder.

biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqBuilderTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,41 @@ public void testConstructor()
3636
Assert.assertNotNull(fastqBuilder);
3737
}
3838

39+
@Test
40+
public void testConstructorFastq()
41+
{
42+
FastqBuilder fastqBuilder = new FastqBuilder()
43+
.withDescription("description")
44+
.withSequence("sequence")
45+
.withQuality("quality_")
46+
.withVariant(FastqVariant.FASTQ_SOLEXA);
47+
48+
Fastq fastq = fastqBuilder.build();
49+
50+
FastqBuilder fastqBuilder2 = new FastqBuilder(fastq);
51+
Assert.assertNotNull(fastqBuilder2);
52+
53+
Fastq fastq2 = fastqBuilder2.build();
54+
Assert.assertEquals("description", fastq2.getDescription());
55+
Assert.assertEquals("sequence", fastq2.getSequence());
56+
Assert.assertEquals("quality_", fastq2.getQuality());
57+
Assert.assertEquals(FastqVariant.FASTQ_SOLEXA, fastq2.getVariant());
58+
}
59+
60+
@Test
61+
public void testConstructorNullFastq()
62+
{
63+
try
64+
{
65+
new FastqBuilder(null);
66+
Assert.fail("builder(null) expected IllegalArgumentException");
67+
}
68+
catch (IllegalArgumentException e)
69+
{
70+
// expected
71+
}
72+
}
73+
3974
@Test
4075
public void testBuildDefault()
4176
{

biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ public void testBuilder()
111111
Assert.assertNotNull(Fastq.builder());
112112
}
113113

114+
@Test
115+
public void testBuilderNullFastq()
116+
{
117+
try
118+
{
119+
Fastq.builder(null);
120+
Assert.fail("builder(null) expected IllegalArgumentException");
121+
}
122+
catch (IllegalArgumentException e)
123+
{
124+
// expected
125+
}
126+
}
127+
114128
@Test
115129
public void testEquals()
116130
{

0 commit comments

Comments
 (0)