001/*
002 * Copyright c 2018 Rusi Popov, MDA Tools.net All rights reserved.
003 *
004 * This program and the accompanying materials are made available under the terms of the
005 * Eclipse Public License v2.0 which accompanies this distribution, and is available at
006 * http://www.eclipse.org/legal/epl-v20.html
007 */
008package net.mdatools.modelant.core.operation.format;
009
010/**
011 * Concatenate the words "." separators, where all words are in lower case.
012 * The letter case change, the spaces and "_" are NOT treated as words separators.
013 * @author Rusi Popov (popovr@mdatools.net)
014 */
015public class FormatPackageName extends FormatWordsString {
016
017  /*
018   * INVARIANT
019   *   all words are in lower case
020   */
021
022  /**
023   * No separator between the words
024   */
025  public FormatPackageName() {
026    this( "." );
027  }
028
029  /**
030   * @see net.mdatools.modelant.core.operation.format.FormatWordsString#prepare(java.lang.String)
031   */
032  protected final String prepare(String source) {
033    String result;
034
035    result = source.toLowerCase() // see the invariant
036                   .replace( " ", "")
037                   .replace( "_", "");
038    return result;
039  }
040
041  /**
042   * @param separator non-null separator of the identified words
043   */
044  public FormatPackageName(String separator) {
045    super( separator );
046  }
047
048  /**
049   * @see net.mdatools.modelant.core.operation.format.FormatWordsString#formatFirstWord(java.lang.StringBuilder, java.lang.String, boolean)
050   */
051  protected final void formatFirstWord(StringBuilder result, String word, boolean nextWordExists) {
052    result.append( word );
053  }
054
055  /**
056   * @see net.mdatools.modelant.core.operation.format.FormatWordsString#formatNextWord(java.lang.StringBuilder, java.lang.String, boolean)
057   */
058  protected final void formatNextWord(StringBuilder result, String word, boolean nextWordExists) {
059    result.append( word );
060  }
061}