Java String Extract extractNoPublicDomains(String domains)

Here you can find the source of extractNoPublicDomains(String domains)

Description

extract No Public Domains

License

Open Source License

Declaration

public static int extractNoPublicDomains(String domains) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static int extractNoPublicDomains(String domains) {
        if (domains == null)
            return 0;
        return extractNoItems(domains) - extractNoPrivateDomains(domains);
    }//from  w  ww  .  ja  v a 2s.  com

    public static int extractNoItems(String items) {
        if (items == null)
            return 0;
        List<String> itemList = extractItems(items);
        return itemList.size();
    }

    public static int extractNoPrivateDomains(String domains) {
        if (domains == null)
            return 0;
        if (domains.contains("\"owned\"")) //we can have at most one private domain
            return 1;
        return 0;
    }

    /**
     * splits a string of type {("A","B<C,D>","C")} into ["A", "B<C,D>", "C"]
     * */
    public static List<String> extractItems(String items) {
        List<String> itemList = new ArrayList<String>();
        if (items == null)
            return itemList;
        items = items.replace(" ", ""); //remove all spaces      
        if (items.split("\"(.)*\"").length == 1)
            return itemList;
        String[] arrayItems = items.split("\",");

        for (int i = 0; i < arrayItems.length; i++) {
            //there is exactly one " in each arrayItem[i], and we need the string from the right of it
            String[] rightStr = arrayItems[i].split("\"");
            if (rightStr.length > 0)
                itemList.add(rightStr[1]);
        }
        return itemList;
    }
}

Related

  1. extractHorizontalTabs(String line, int tabSize)
  2. extractItems(String items)
  3. extractJobId(String line)
  4. extractKeyCodes(String codes)
  5. extractLines(String data, int tabWidth)
  6. extractNumberFromInput(String command)
  7. extractNumbers(String text)
  8. extractPacket(String serverPacket)
  9. extractParameters(String uri)