RelTraitSet getOrAdd(List<RelTrait> traits) { RelTraitSet traitSet1 = map.get(traits); if (traitSet1 != null) { return traitSet1; } final RelTraitSet traitSet = new RelTraitSet(this, traits.toArray(new RelTrait[0])); map.put(traits, traitSet); return traitSet; } }
RelTraitSet getOrAdd(List<RelTrait> traits) { RelTraitSet traitSet1 = map.get(traits); if (traitSet1 != null) { return traitSet1; } final RelTraitSet traitSet = new RelTraitSet(this, traits.toArray(new RelTrait[0])); map.put(traits, traitSet); return traitSet; } }
/** * Creates an empty trait set. * * <p>It has a new cache, which will be shared by any trait set created from * it. Thus each empty trait set is the start of a new ancestral line. */ public static RelTraitSet createEmpty() { return new RelTraitSet(new Cache(), EMPTY_TRAITS); }
/** * Creates an empty trait set. * * <p>It has a new cache, which will be shared by any trait set created from * it. Thus each empty trait set is the start of a new ancestral line. */ public static RelTraitSet createEmpty() { return new RelTraitSet(new Cache(), EMPTY_TRAITS); }
/** * Replaces an existing RelTrait in the set. * Returns a different trait set; does not modify this trait set. * * @param index 0-based index into ordered RelTraitSet * @param trait the new RelTrait * @return the old RelTrait at the index */ public RelTraitSet replace(int index, RelTrait trait) { assert traits[index].getTraitDef() == trait.getTraitDef() : "RelTrait has different RelTraitDef than replacement"; RelTrait canonizedTrait = canonize(trait); if (traits[index] == canonizedTrait) { return this; } RelTrait[] newTraits = traits.clone(); newTraits[index] = canonizedTrait; return cache.getOrAdd(new RelTraitSet(cache, newTraits)); }
/** * Replaces an existing RelTrait in the set. * Returns a different trait set; does not modify this trait set. * * @param index 0-based index into ordered RelTraitSet * @param trait the new RelTrait * @return the old RelTrait at the index */ public RelTraitSet replace(int index, RelTrait trait) { assert traits[index].getTraitDef() == trait.getTraitDef() : "RelTrait has different RelTraitDef than replacement"; RelTrait canonizedTrait = canonize(trait); if (traits[index] == canonizedTrait) { return this; } RelTrait[] newTraits = traits.clone(); newTraits[index] = canonizedTrait; return cache.getOrAdd(new RelTraitSet(cache, newTraits)); }