Example usage for java.util Map isEmpty

List of usage examples for java.util Map isEmpty

Introduction

In this page you can find the example usage for java.util Map isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this map contains no key-value mappings.

Usage

From source file:io.fabric8.maven.core.util.kubernetes.KubernetesClientUtil.java

public static FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> withSelector(
        NonNamespaceOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods,
        LabelSelector selector, Logger log) {
    FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> answer = pods;
    Map<String, String> matchLabels = selector.getMatchLabels();
    if (matchLabels != null && !matchLabels.isEmpty()) {
        answer = answer.withLabels(matchLabels);
    }//from  w ww. ja v  a2s  .co m
    List<LabelSelectorRequirement> matchExpressions = selector.getMatchExpressions();
    if (matchExpressions != null) {
        for (LabelSelectorRequirement expression : matchExpressions) {
            String key = expression.getKey();
            List<String> values = expression.getValues();
            if (StringUtils.isBlank(key)) {
                log.warn("Ignoring empty key in selector expression %s", expression);
                continue;
            }
            if (values == null || values.isEmpty()) {
                log.warn("Ignoring empty values in selector expression %s", expression);
                continue;
            }
            String[] valuesArray = values.toArray(new String[values.size()]);
            String operator = expression.getOperator();
            switch (operator) {
            case "In":
                answer = answer.withLabelIn(key, valuesArray);
                break;
            case "NotIn":
                answer = answer.withLabelNotIn(key, valuesArray);
                break;
            default:
                log.warn("Ignoring unknown operator %s in selector expression %s", operator, expression);
            }
        }
    }
    return answer;
}

From source file:com.datumbox.framework.core.common.dataobjects.DataframeMatrix.java

/**
 * Parses a single Record and converts it to RealVector by using an already
 * existing mapping between feature names and column ids. 
 * /*from   w ww  . j  a  v a 2s . c  o  m*/
 * @param r
 * @param featureIdsReference
 * @return 
 */
public static RealVector parseRecord(Record r, Map<Object, Integer> featureIdsReference) {
    if (featureIdsReference.isEmpty()) {
        throw new IllegalArgumentException("The featureIdsReference map should not be empty.");
    }

    int d = featureIdsReference.size();

    //create an Map-backed vector only if we have available info about configuration.
    RealVector v = (storageEngine != null) ? new MapRealVector(d) : new OpenMapRealVector(d);

    boolean addConstantColumn = featureIdsReference.containsKey(Dataframe.COLUMN_NAME_CONSTANT);

    if (addConstantColumn) {
        v.setEntry(0, 1.0); //add the constant column
    }
    for (Map.Entry<Object, Object> entry : r.getX().entrySet()) {
        Object feature = entry.getKey();
        Double value = TypeInference.toDouble(entry.getValue());
        if (value != null) {
            Integer featureId = featureIdsReference.get(feature);
            if (featureId != null) {//if the feature exists
                v.setEntry(featureId, value);
            }
        } else {
            //else the X matrix maintains the 0.0 default value
        }
    }

    return v;
}

From source file:edu.umass.cs.gigapaxos.paxospackets.PrepareReplyPacket.java

private static int getMinSlot(int firstSlot, Map<Integer, PValuePacket> acceptedMap) {
    Integer minSlot = null;//from  w w w .j a v  a  2 s.  c o  m
    if (acceptedMap != null && !acceptedMap.isEmpty()) {
        for (Integer curSlot : acceptedMap.keySet()) {
            if (minSlot == null)
                minSlot = curSlot;
            else if (curSlot - minSlot < 0)
                minSlot = curSlot;
        }
    }
    if (minSlot == null)
        minSlot = firstSlot;
    return minSlot;
}

From source file:com.codelanx.codelanxlib.inventory.iinterface.InventoryPanel.java

static InventoryPanel valueOf(InventoryInterface ii, Object o) {
    Map<String, Object> map = Config.getConfigSectionValue(o);
    if (map == null || map.isEmpty()) {
        return null;
    }//from   w  w w  .j ava2s .  c o  m
    List<Object> objs = (List<Object>) map.get("icons");
    Boolean root = Boolean.valueOf(String.valueOf(map.get("root")));
    String name = String.valueOf(map.get("name"));
    if (objs != null && root != null) {
        List<MenuIcon> icons = objs.stream().map(obj -> MenuIcon.valueOf(ii, obj)).filter(Lambdas::notNull)
                .collect(Collectors.toList());
        int rows;
        if (map.get("rows") == null) {
            rows = (icons.size() / 9) + 1;
        } else {
            rows = Integer.valueOf(String.valueOf(map.get("rows")));
        }
        InventoryPanel ip = ii.newPanel(name, rows);
        ip.icons.addAll(icons);
        ip.icons.forEach(i -> ip.locations.put(ip.index++, i));
        if (root) {
            ii.setRootPanel(ip);
        }
        return ip;
    } else {
        return null;
    }
}

From source file:com.hhi.bigdata.platform.push.client.RegisterUtil.java

/**
 * <pre>//from w  ww  . j  a v a  2 s.com
 * 3rd party? app ??   API 
 * </pre>
 * @param webUrl
 * @param appName
 * @param keyFile
 * @param dplFile
 * @return
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public static APIInfo registCertificate(String webUrl, String appName, PrivateKey key, URI dplFile)
        throws Exception {
    String result = null;

    /*
     * url :   api url + "/{appName}"
     * param : appName - 3rd party app name
     *         appNameEnc - 3rd party app name? HHI? ? private key ? ? (byte[] base-64 ?)
     *         dpl - HHI? ? dpl file
     */
    Client client = ClientBuilder.newBuilder().register(MultiPartFeature.class).build();
    WebTarget webTarget = client.target(webUrl + "/" + appName);

    MultiPart multiPart = new MultiPart();
    multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);

    FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("dpl", new File(dplFile),
            MediaType.APPLICATION_OCTET_STREAM_TYPE);

    multiPart.bodyPart(new FormDataBodyPart("appNameEnc", getAppNameEnc(key, appName)));
    multiPart.bodyPart(fileDataBodyPart);

    Response response = webTarget.request().post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA));
    result = response.readEntity(String.class);

    System.err.println("result : " + result);

    Map<String, Object> map = new HashMap<String, Object>();
    map = mapper.readValue(result, new TypeReference<HashMap<String, Object>>() {
    });

    if (map.get("message") != null) {
        throw new Exception((String) map.get("message"));
    }

    APIInfo apiInfo = null;
    Map<String, String> apiInfoMap = (Map<String, String>) map.get("apiInfo");
    if (apiInfoMap != null && !apiInfoMap.isEmpty()) {
        apiInfo = new APIInfo();

        apiInfo.setUsername(apiInfoMap.get("username"));
        apiInfo.setPassword(apiInfoMap.get("password"));
        apiInfo.setConsumerKey(apiInfoMap.get("consumerKey"));
        apiInfo.setConsumerSecret(apiInfoMap.get("consumerSecret"));
    }

    return apiInfo;
}

From source file:com.github.util.HttpHandler.java

/**
 * Convert a Map to UrlEncodedFormEntity
 *
 * @param parameters A Map of key:value//w ww.ja v a2s .c om
 * @return UrlEncodedFormEntity using UTF-8 encoding
 * @throws java.io.UnsupportedEncodingException
 *          if UTF-8 encoding is not supported
 */
private static UrlEncodedFormEntity mapToEntity(Map<String, String> parameters)
        throws UnsupportedEncodingException {
    if (parameters == null) {
        throw new IllegalArgumentException("Invalid parameters unable map to Entity");
    }

    if (parameters.isEmpty()) {
        return null;
    }

    ArrayList<NameValuePair> parametersList = new ArrayList<NameValuePair>();

    for (@SuppressWarnings("rawtypes")
    Map.Entry element : parameters.entrySet()) {
        NameValuePair nameValuePair = new BasicNameValuePair((String) element.getKey(),
                (String) element.getValue());
        parametersList.add(nameValuePair);
    }

    return new UrlEncodedFormEntity(parametersList, HTTP.UTF_8);
}

From source file:com.glaf.core.entity.mybatis.MyBatisSessionFactory.java

public static Map<String, byte[]> getLibMappers() {
    List<String> includes = new ArrayList<String>();
    includes.add("Mapper.xml");
    Map<String, byte[]> dataMap = new HashMap<String, byte[]>();
    String path = SystemProperties.getConfigRootPath() + "/lib";
    File dir = new File(path);
    File contents[] = dir.listFiles();
    if (contents != null) {
        ZipInputStream zipInputStream = null;
        for (int i = 0; i < contents.length; i++) {
            if (contents[i].isFile() && contents[i].getName().startsWith("glaf")
                    && contents[i].getName().endsWith(".jar")) {
                try {
                    zipInputStream = new ZipInputStream(
                            FileUtils.getInputStream(contents[i].getAbsolutePath()));
                    Map<String, byte[]> zipMap = getZipBytesMap(zipInputStream);
                    if (zipMap != null && !zipMap.isEmpty()) {
                        dataMap.putAll(zipMap);
                    }//from  ww  w. j  a  va  2 s .  co  m
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
    return dataMap;
}

From source file:com.carlomicieli.jtrains.value.objects.LocalizedField.java

/**
 * Builds a new {@code LocalizedField} using the value from the provided map.
 * <p>//  w  w w.  j a v a 2  s  .co  m
 *     The method returns {@code null} if the provided map is either null or
 *     empty.
 * </p>
 *
 * @param values the map
 * @return a {@code LocalizedField}
 */
public static <T> LocalizedField<T> of(Map<String, T> values) {
    if (values == null || values.isEmpty()) {
        return null;
    }
    return new LocalizedField<>(values);
}

From source file:edu.umass.cs.gigapaxos.paxospackets.PrepareReplyPacket.java

private static int getMaxSlot(int firstSlot, Map<Integer, PValuePacket> acceptedMap) {
    Integer maxSlot = firstSlot - 1;
    if (acceptedMap != null && !acceptedMap.isEmpty()) {
        for (Integer curSlot : acceptedMap.keySet())
            if (curSlot - maxSlot > 0)
                maxSlot = curSlot;//from ww w .j a v a  2  s  .com
    }
    return maxSlot;
}

From source file:org.opendatakit.api.forms.FormService.java

static String getTableIdFromFiles(Map<String, byte[]> files) {
    String tableId = null;/*from  www . jav  a2s .  c  om*/
    if (files != null && !files.isEmpty()) {
        for (String filename : files.keySet()) {
            if (filename.endsWith("definition.csv")) {

                tableId = FileManager.getTableIdForFilePath(filename);
                break;
            }
        }
    }
    if (tableId == null) {
        throw new WebApplicationException(ErrorConsts.NO_TABLE_ID_IN_DEFINITION_FILE,
                HttpServletResponse.SC_BAD_REQUEST);
    }
    return tableId;
}