1 package org.synchronoss.cpo.core.meta.domain;
2
3 /*-
4 * [[
5 * core
6 * ==
7 * Copyright (C) 2003 - 2026 Exaxis LLC, Synchronoss Technologies Inc
8 * ==
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Lesser Public License for more details.
18 *
19 * You should have received a copy of the GNU General Lesser Public
20 * License along with this program. If not, see
21 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22 * ]]
23 */
24
25 import java.util.ArrayList;
26 import java.util.List;
27 import org.synchronoss.cpo.core.meta.bean.CpoFunctionGroupBean;
28
29 /**
30 * Runtime metadata for a named group of {@link CpoFunction}s that together implement one CRUD
31 * operation (e.g. all the INSERT functions named {@code "cpo_default"}) for a {@link CpoClass}.
32 *
33 * @author dberry
34 */
35 public class CpoFunctionGroup extends CpoFunctionGroupBean implements Comparable<CpoFunctionGroup> {
36
37 private static final long serialVersionUID = 1L;
38
39 /** The functions in this group. */
40 List<CpoFunction> functions = new ArrayList<>();
41
42 /** Creates an empty instance. */
43 public CpoFunctionGroup() {}
44
45 /**
46 * Gets the functions in this group.
47 *
48 * @return the functions in this group
49 */
50 public List<CpoFunction> getFunctions() {
51 return functions;
52 }
53
54 /**
55 * Appends a function to this group. A no-op if {@code function} is {@code null}.
56 *
57 * @param function the function to add
58 */
59 public void addFunction(CpoFunction function) {
60 if (function != null) {
61 functions.add(function);
62 }
63 }
64
65 /**
66 * Removes a function from this group.
67 *
68 * @param function the function to remove
69 * @return {@code true} if the function was found and removed, {@code false} otherwise
70 */
71 public boolean removeFunction(CpoFunction function) {
72 if (function != null) {
73 return functions.remove(function);
74 }
75 return false;
76 }
77
78 /** Removes all functions from this group. */
79 public void clearFunctions() {
80 functions.clear();
81 }
82
83 /**
84 * {@inheritDoc}
85 *
86 * <p>Returns this group's {@link #getType() type} and {@link #getName() name}.
87 */
88 @Override
89 public String toString() {
90 return this.getType() + " - " + this.getName();
91 }
92
93 /**
94 * Gets the full field-by-field string representation of this function group, as produced by
95 * {@link CpoFunctionGroupBean#toString()}.
96 *
97 * @return the full string representation
98 */
99 public String toStringFull() {
100 return super.toString();
101 }
102
103 /**
104 * {@inheritDoc}
105 *
106 * <p>Orders function groups by their {@link #toString()} representation (type, then name).
107 */
108 @Override
109 public int compareTo(CpoFunctionGroup fg) {
110 return this.toString().compareTo(fg.toString());
111 }
112 }