@SuppressWarnings("unchecked")
  public static List<Object> asList(final Object key) {
    final Optional<Windowed<Object>> windowed = key instanceof Windowed
        ? Optional.of((Windowed<Object>) key)
        : Optional.empty();

    final Object naturalKey = windowed
        .map(Windowed::key)
        .orElse(key);

    if (naturalKey != null && !(naturalKey instanceof GenericKey)) {
      throw new IllegalArgumentException("Non generic key: " + key);
    }

    final Optional<GenericKey> genericKey = Optional.ofNullable((GenericKey) naturalKey);

    final List<Object> data = new ArrayList<>(
        genericKey.map(GenericKey::size).orElse(0)
            + (windowed.isPresent() ? 2 : 0)
    );

    genericKey.ifPresent(k -> data.addAll(k.values()));

    windowed
        .map(Windowed::window)
        .ifPresent(wnd -> {
          data.add(wnd.start());
          data.add(wnd.end());
        });

    return data;
  }
@Test
  public void shouldConvertNonWindowedKeyToList() {
    // Given:
    final GenericKey key = GenericKey.genericKey(10);

    // When:
    final List<?> result = KeyUtil.asList(key);

    // Then:
    assertThat(result, is(ImmutableList.of(10)));
  }