delete some builders
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 12 Apr 2025 15:16:17 +0000 (08:16 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 12 Apr 2025 15:16:17 +0000 (08:16 -0700)
rust/pspp/src/output/pivot/mod.rs
rust/pspp/src/output/pivot/test.rs

index 0d8b006e307946462cd8eee7776ba95c3a4955e7..97427729c53d1f57854007e0192eb32568d7a852 100644 (file)
@@ -271,9 +271,6 @@ impl Iterator for AxisIterator {
 }
 
 impl PivotTable {
-    fn builder(title: impl Into<Value>, dimensions: Vec<DimensionBuilder>) -> 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<Path<'_>> {
         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<Value>) -> 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<Value>,
-    children: Vec<CategoryBuilder>,
-    show_label: Option<bool>,
-}
-
-impl GroupBuilder {
-    pub fn new(name: impl Into<Value>) -> Self {
-        Self {
-            name: Box::new(name.into()),
-            children: Vec::new(),
-            show_label: None,
-        }
-    }
-    pub fn push<T>(&mut self, value: T)
-    where
-        T: Into<CategoryBuilder>,
-    {
-        self.children.push(value.into());
-    }
-    pub fn with<T>(mut self, value: T) -> Self
-    where
-        T: Into<CategoryBuilder>,
-    {
-        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<GroupBuilder>),
-    Leaf {
-        name: Box<Value>,
-        class: Option<Class>,
-    },
-}
-
-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<GroupBuilder> for CategoryBuilder {
-    fn from(value: GroupBuilder) -> Self {
-        Self::Group(Box::new(value))
-    }
-}
-
-impl From<Value> 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<Arc<Footnote>>);
 
@@ -621,27 +472,6 @@ impl PivotTableBuilder {
             footnotes: Footnotes::new(),
         }
     }
-    pub fn from_builders(
-        title: impl Into<Value>,
-        dimension_builders: Vec<DimensionBuilder>,
-    ) -> 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<Look>) -> Self {
         self.look = look;
         self
index 46eb9e63fca0a49beb83a069fd092f69dce7ccf0..dace8ff0094ecaf8ffe8b052758906f6784d2217 100644 (file)
@@ -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() {