From: Ben Pfaff Date: Sat, 12 Apr 2025 15:16:17 +0000 (-0700) Subject: delete some builders X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dcb86721b521573d422cac857d7e579e7ac09621;p=pspp delete some builders --- diff --git a/rust/pspp/src/output/pivot/mod.rs b/rust/pspp/src/output/pivot/mod.rs index 0d8b006e30..97427729c5 100644 --- a/rust/pspp/src/output/pivot/mod.rs +++ b/rust/pspp/src/output/pivot/mod.rs @@ -271,9 +271,6 @@ impl Iterator for AxisIterator { } impl PivotTable { - fn builder(title: impl Into, dimensions: Vec) -> PivotTableBuilder { - PivotTableBuilder::from_builders(title, dimensions) - } fn axis_values(&self, axis: Axis3) -> AxisIterator { AxisIterator { indexes: repeat_n(0, self.axes[axis].dimensions.len()).collect(), @@ -348,10 +345,6 @@ impl Dimension { pub fn leaf_path(&self, index: usize) -> Option> { self.root.leaf_path(index, SmallVec::new()) } - - pub fn builder(axis: Axis3, root: GroupBuilder) -> DimensionBuilder { - DimensionBuilder::new(axis, root) - } } #[derive(Clone, Debug)] @@ -402,10 +395,6 @@ impl Group { self } - pub fn builder(name: impl Into) -> GroupBuilder { - GroupBuilder::new(name) - } - pub fn nth_leaf(&self, mut index: usize) -> Option<&Leaf> { for child in &self.children { let len = child.len(); @@ -438,144 +427,6 @@ impl Group { } } -#[derive(Clone)] -pub struct DimensionBuilder { - axis: Axis3, - dimension: Dimension, -} - -impl DimensionBuilder { - pub fn new(axis: Axis3, root: GroupBuilder) -> Self { - let root = root.build(true); - Self { - axis, - dimension: Dimension { - presentation_order: (0..root.len()).collect(), - root, - hide_all_labels: false, - }, - } - } - pub fn with_all_labels_hidden(mut self) -> Self { - self.dimension.hide_all_labels = true; - self - } - fn build(self) -> Dimension { - self.dimension - } -} - -#[derive(Clone)] -pub struct GroupBuilder { - name: Box, - children: Vec, - show_label: Option, -} - -impl GroupBuilder { - pub fn new(name: impl Into) -> Self { - Self { - name: Box::new(name.into()), - children: Vec::new(), - show_label: None, - } - } - pub fn push(&mut self, value: T) - where - T: Into, - { - self.children.push(value.into()); - } - pub fn with(mut self, value: T) -> Self - where - T: Into, - { - self.push(value); - self - } - pub fn with_label_hidden(self) -> Self { - self.with_show_label(false) - } - pub fn with_label_shown(self) -> Self { - self.with_show_label(true) - } - pub fn with_show_label(mut self, show_label: bool) -> Self { - self.show_label = Some(show_label); - self - } - fn len(&self) -> usize { - self.children.iter().map(|category| category.len()).sum() - } - fn build(self, is_root: bool) -> Group { - Group { - len: self.children.iter().map(|c| c.len()).sum(), - name: self.name, - children: self.children.into_iter().map(|c| c.build()).collect(), - show_label: { - // By default, nested group labels are shown, but not dimension root labels. - self.show_label.unwrap_or(!is_root) - }, - } - } -} - -#[derive(Clone)] -pub enum CategoryBuilder { - Group(Box), - Leaf { - name: Box, - class: Option, - }, -} - -impl CategoryBuilder { - fn len(&self) -> usize { - match self { - CategoryBuilder::Group(group) => group.len(), - CategoryBuilder::Leaf { .. } => 1, - } - } - fn build(self) -> Category { - match self { - Self::Group(group) => Category::Group(group.build(false)), - Self::Leaf { name, class } => Category::Leaf(Leaf { name, class }), - } - } -} - -impl From for CategoryBuilder { - fn from(value: GroupBuilder) -> Self { - Self::Group(Box::new(value)) - } -} - -impl From for CategoryBuilder { - fn from(name: Value) -> Self { - Self::Leaf { - name: Box::new(name), - class: None, - } - } -} - -impl From<(Value, Class)> for CategoryBuilder { - fn from((name, class): (Value, Class)) -> Self { - Self::Leaf { - name: Box::new(name), - class: Some(class), - } - } -} - -impl From<&str> for CategoryBuilder { - fn from(name: &str) -> Self { - Self::Leaf { - name: Box::new(Value::new_text(name)), - class: None, - } - } -} - #[derive(Clone, Debug, Default)] pub struct Footnotes(Vec>); @@ -621,27 +472,6 @@ impl PivotTableBuilder { footnotes: Footnotes::new(), } } - pub fn from_builders( - title: impl Into, - dimension_builders: Vec, - ) -> Self { - let mut dimensions = Vec::with_capacity(dimension_builders.len()); - let mut axes = EnumMap::from_fn(|_axis| Axis { - dimensions: Vec::with_capacity(dimension_builders.len()), - }); - for d in dimension_builders { - axes[d.axis].dimensions.push(dimensions.len()); - dimensions.push(d.build()); - } - Self { - look: Settings::global().look.clone(), - title: Box::new(title.into()), - axes, - dimensions, - cells: HashMap::new(), - footnotes: Footnotes::new(), - } - } pub fn with_look(mut self, look: Arc) -> Self { self.look = look; self diff --git a/rust/pspp/src/output/pivot/test.rs b/rust/pspp/src/output/pivot/test.rs index 46eb9e63fc..dace8ff009 100644 --- a/rust/pspp/src/output/pivot/test.rs +++ b/rust/pspp/src/output/pivot/test.rs @@ -7,7 +7,7 @@ use crate::output::pivot::{ HeadingRegion, LabelPosition, Look, PivotTable, RowColBorder, Stroke, }; -use super::{Axis3, DimensionBuilder, GroupBuilder, PivotTableBuilder, Value}; +use super::{Axis3, PivotTableBuilder, Value}; #[test] fn color() {