class TtmlRenderUtil {

  public static TtmlStyle resolveStyle(TtmlStyle style, String[] styleIds,
      Map<String, TtmlStyle> globalStyles) {
    if (style == null && styleIds == null) {
      // No styles at all.
      return null;
    } else if (style == null && styleIds.length == 1) {
      // Only one single referential style present.
      return globalStyles.get(styleIds[0]);
    } else if (style == null && styleIds.length > 1) {
      // Only multiple referential styles present.
      TtmlStyle chainedStyle = new TtmlStyle();
      for (String id : styleIds) {
        chainedStyle.chain(globalStyles.get(id));
      }
      return chainedStyle;
    } else if (style != null && styleIds != null && styleIds.length == 1) {
      // Merge a single referential style into inline style.
      return style.chain(globalStyles.get(styleIds[0]));
    } else if (style != null && styleIds != null && styleIds.length > 1) {
      // Merge multiple referential styles into inline style.
      for (String id : styleIds) {
        style.chain(globalStyles.get(id));
      }
      return style;
    }
    // Only inline styles available.
    return style;
  }

  private  TtmlRenderUtil();

}