Example 9 Given the function $f(x)=x^{2}+a|x|+x, x \in \mathbf{R}, a \in \mathbf{R}$.
(1) If $x_{1}, x_{2} \in(0,+\infty)$, compare $\frac{1}{2}\left[f\left(x_{1}\right)+f\left(x_{2}\right)\right]$ with $f\left(\frac{x_{1}+x_{2}}{2}\right)$.
(2) If $x_{1}, x_{2} \in \mathbf{R}$, and $\frac{1}{2}\left[f\left(x_{1}\right)+f\left(x_{2}\right)\right]$ is compared with $f\left(\frac{x_{1}+x_{2}}{2}\right)$, and the result is consistent with (1), find the range of values for $a$.
(1) When $x_{1}, x_{2} \in(0,+\infty)$, $\frac{x_{1}+x_{2}}{2} \in(0,+\infty)$.

Then
$$
\begin{aligned}
& \frac{1}{2}\left[f\left(x_{1}\right)+f\left(x_{2}\right)\right]-f\left(\frac{x_{1}+x_{2}}{2}\right) \\
= & \frac{1}{2}\left[x_{1}^{2}+(a+1) x_{1}+x_{2}^{2}+(a+1) x_{2}\right]-\left(\frac{x_{1}+x_{2}}{2}\right)^{2}+(a+1) \cdot \frac{x_{1}+x_{2}}{2} \\
= & \frac{1}{4}\left(x_{1}-x_{2}\right)^{2} \geqslant 0, \text { with equality if and only if } x_{1}=x_{2},
\end{aligned}
$$

i.e., $\frac{1}{2}\left[f\left(x_{1}\right)+f\left(x_{2}\right)\right] \geqslant f\left(\frac{x_{1}+x_{2}}{2}\right)$, with equality if $x_{1}=x_{2}$.
(2) When $x \in \mathbf{R}$, $f(x)=\left\{\begin{array}{l}x^{2}+(a+1) x, x \geqslant 0 . \\ x^{2}+(1-a) x, x<0 .\end{array}\right.$
It is clear that when $x_{1}, x_{2} \in(-\infty, 0)$, $\frac{1}{2}\left[f\left(x_{1}\right)+f\left(x_{2}\right)\right] \geqslant f\left(\frac{x_{1}+x_{2}}{2}\right)$ always holds.
When $x_{1} \in(-\infty, 0), x_{2} \in[0,+\infty)$,
there are two cases: $\frac{x_{1}+x_{2}}{2} \in[0,+\infty)$ or $\frac{x_{1}+x_{2}}{2} \in(-\infty, 0)$.
$$
\begin{array}{l}
\text { If } \frac{x_{1}+x_{2}}{2} \in[0,+\infty), \\
\frac{1}{2}\left[f\left(x_{1}\right)+f\left(x_{2}\right)\right]-f\left(\frac{x_{1}+x_{2}}{2}\right) \\
=\frac{1}{2}\left[x_{1}^{2}+(1-a) x_{1}+x_{2}^{2}+(a+1) x_{2}\right]-\left(\frac{x_{1}+x_{2}}{2}\right)^{2}-(a+1) \frac{x_{1}+x_{2}}{2} \\
=\frac{1}{4}\left[x_{1}^{2}+x_{2}^{2}-2 x_{1} x_{2}-4 a x_{1}\right] \\
=\frac{1}{4}\left(x_{1}-x_{2}\right)^{2}-a x_{1} \geqslant 0 \text { always holds. } \\
\end{array}
$$

Since $x_{1} \in(-\infty, 0)$, it suffices that $a \geqslant 0$.
If $\frac{x_{1}+x_{2}}{2} \in(-\infty, 0)$.
$$
\begin{aligned}
& \frac{1}{2}\left[f\left(x_{1}\right)+f\left(x_{2}\right)\right]-f\left(\frac{x_{1}+x_{2}}{2}\right) \\
= & \frac{1}{2}\left[x_{2}^{2}+(1-a) x_{1}+x_{2}^{2}+(a+1) x_{2}\right]-\left(\frac{x_{1}+x_{2}}{2}\right)^{2}-(1-a) \cdot \frac{x_{1}+x_{2}}{2} \\
= & \frac{1}{4}\left[x_{1}^{2}+x_{2}^{2}-2 x_{1} x_{2}+4 a x_{2}\right]=\frac{1}{4}\left(x_{1}-x_{2}\right)^{2}+a x_{2} \geqslant 0 .
\end{aligned}
$$

Since $x_{2} \in[0,+\infty)$, it suffices that $a \geqslant 0$.
In summary, $a \geqslant 0$.