We write down the definition of expectation and then break down the integral into segments:
$E[X] = \int_{-\infty}^\infty xf(x) dx = \int_{-\infty}^0 x \cdot 0 dx + \int_0^1 x \cdot x dx + \int_1^2 x(2-x)dx + \int_0^{\infty} x \cdot 0 dx= 0 + \frac{1}{3} + \frac{2}{3} + 0 = 1$