/** * Replaces the genotype in this context -- note for efficiency * reasons we do not add the genotype if it's not present. The * return value will be null indicating this happened. * * Note this operation is preserves the map cache Sample -> Offset but * invalidates the sorted list of samples. Using replace within a loop * containing any of the SampleNameInOrder operation requires an O(n log n) * resorting after each replace operation. * * @param genotype a non null genotype to bind in this context * @return null if genotype was not added, otherwise returns the previous genotype */ public Genotype replace(final Genotype genotype) { checkImmutability(); Integer offset = getSampleI(genotype.getSampleName()); if ( offset == null ) return null; else return set(offset, genotype); }
/** * Replaces the genotype in this context -- note for efficiency * reasons we do not add the genotype if it's not present. The * return value will be null indicating this happened. * * Note this operation is preserves the map cache Sample -> Offset but * invalidates the sorted list of samples. Using replace within a loop * containing any of the SampleNameInOrder operation requires an O(n log n) * resorting after each replace operation. * * @param genotype a non null genotype to bind in this context * @return null if genotype was not added, otherwise returns the previous genotype */ public Genotype replace(final Genotype genotype) { checkImmutability(); Integer offset = getSampleI(genotype.getSampleName()); if ( offset == null ) return null; else return set(offset, genotype); }
@Test(enabled = true, dataProvider = "GenotypesContextProvider") public void testSet(GenotypesContextProvider cfg) { Genotype set = GenotypeBuilder.create("replace", Arrays.asList(Aref, Aref)); int n = cfg.makeContext().size(); for ( int i = 0; i < n; i++ ) { GenotypesContext gc = cfg.makeContext(); Genotype setted = gc.set(i, set); Assert.assertNotNull(setted); ArrayList<Genotype> l = new ArrayList<Genotype>(cfg.initialSamples); l.set(i, set); testGenotypesContextContainsExpectedSamples(gc, l); } }
/** * Replaces the genotype in this context -- note for efficiency * reasons we do not add the genotype if it's not present. The * return value will be null indicating this happened. * * Note this operation is preserves the map cache Sample -> Offset but * invalidates the sorted list of samples. Using replace within a loop * containing any of the SampleNameInOrder operation requires an O(n log n) * resorting after each replace operation. * * @param genotype a non null genotype to bind in this context * @return null if genotype was not added, otherwise returns the previous genotype */ @Requires("genotype != null") public Genotype replace(final Genotype genotype) { checkImmutability(); Integer offset = getSampleI(genotype.getSampleName()); if ( offset == null ) return null; else return set(offset, genotype); }