1   /*
2    * Copyright 2017 LINE Corporation
3    *
4    * LINE Corporation licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  
17  package com.linecorp.centraldogma.internal.thrift;
18  
19  import com.google.common.base.Converter;
20  
21  /**
22   * Provides a function converting back and forth between {@link Markup} and
23   * {@link com.linecorp.centraldogma.common.Markup}.
24   */
25  public final class MarkupConverter extends Converter<com.linecorp.centraldogma.common.Markup, Markup> {
26      public static final Converter<com.linecorp.centraldogma.common.Markup, Markup> TO_DATA =
27              new MarkupConverter();
28  
29      public static final Converter<Markup, com.linecorp.centraldogma.common.Markup> TO_MODEL =
30              TO_DATA.reverse();
31  
32      private MarkupConverter() {}
33  
34      @Override
35      protected Markup doForward(com.linecorp.centraldogma.common.Markup markup) {
36          switch (markup) {
37              case PLAINTEXT:
38                  return Markup.PLAINTEXT;
39              case MARKDOWN:
40                  return Markup.MARKDOWN;
41              default:
42                  return Markup.UNKNOWN;
43          }
44      }
45  
46      @Override
47      protected com.linecorp.centraldogma.common.Markup doBackward(Markup markup) {
48          switch (markup) {
49              case PLAINTEXT:
50                  return com.linecorp.centraldogma.common.Markup.PLAINTEXT;
51              case MARKDOWN:
52                  return com.linecorp.centraldogma.common.Markup.MARKDOWN;
53              default:
54                  return com.linecorp.centraldogma.common.Markup.UNKNOWN;
55          }
56      }
57  }