Java List Reverse formatToIp(final List shortList, final boolean reverseOrder)

Here you can find the source of formatToIp(final List shortList, final boolean reverseOrder)

Description

Formats a List with short values into it's IP-Address representation.

License

Apache License

Parameter

Parameter Description
shortList List with short values.
reverseOrder TRUE if the incoming list shall be sorted in reverse order, otherwise FALSE .

Return

IP-Address.

Declaration

public static String formatToIp(final List<Short> shortList,
        final boolean reverseOrder) 

Method Source Code

//package com.java2s;
/*/*from  w  ww  .  jav  a  2  s.com*/
 * Copyright 2013, Carsten J?ger
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.Collections;

import java.util.List;

public class Main {
    /**
     * Formats a List with short values into it's IP-Address representation.
     *
     * @param shortList List with short values.
     * @param reverseOrder {@code TRUE} if the incoming list shall be sorted in reverse order, otherwise {@code FALSE}.
     * @return IP-Address.
     */
    public static String formatToIp(final List<Short> shortList,
            final boolean reverseOrder) {
        if (shortList == null) {
            return null;
        }
        if (reverseOrder) {
            Collections.reverse(shortList);
        }
        return shortList.toString().replaceAll(",[ ]*", ".")
                .replaceAll("[\\[\\]]", "");
    }
}

Related

  1. compareVersions(List list1, List list2)
  2. compareVersions(List version1, List version2)
  3. compareVersions(String version1, String version2)
  4. createReversedList(List inputList)
  5. firstElementOf(List list, int reverseIndexPosition)
  6. getReversedListIterable(final List inList)
  7. iterateReverse(final List elements)
  8. listToArrowSep(List strings, String highlightFirst, String highlightSecond, boolean reversed)
  9. reverse(Collection list)