Example usage for com.google.common.collect Multimap isEmpty

List of usage examples for com.google.common.collect Multimap isEmpty

Introduction

In this page you can find the example usage for com.google.common.collect Multimap isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this multimap contains no key-value pairs.

Usage

From source file:moa2014.MOAH52014.java

public static int principal(int[][] matrizatual) {
    long startTime = System.currentTimeMillis();
    Multimap<Integer, String> open_list = TreeMultimap.create();
    HashMap<String, Estado> processados = new HashMap();

    int h1x = MOAH12014.diferencaMatriz(matrizatual);
    int h2x = MOAH22014.diferencaMatriz(matrizatual);
    int h3x = MOAH32014.diferencaMatriz(matrizatual);

    int difmatrizatual = maior(h1x, h2x, h3x);

    String stringmatriz = transformaMatrizString(matrizatual);
    open_list.put(difmatrizatual, stringmatriz);
    Estado estadoatual = new Estado(matrizatual, 0);
    processados.put(stringmatriz, estadoatual);

    int arvoresgeradas = 0;
    int arvoresprocessadas = 0;

    while (!open_list.isEmpty()) {

        Iterator iterator = open_list.keySet().iterator();

        Integer key = (Integer) iterator.next();
        String matrizatualx1 = open_list.asMap().get(key).iterator().next();
        Estado estadomenor = processados.get(matrizatualx1);
        int altura = estadomenor.getCusto();

        //LOCALIZA O ZERO
        int[] zerot = localizazero(estadomenor.getMatriz());
        int x = zerot[0];
        int y = zerot[1];
        int x0 = x - 1;
        int x1 = x + 1;
        int y0 = y - 1;
        int y1 = y + 1;
        int difmatrizatualx = MOAH32014.diferencaMatriz(estadomenor.getMatriz());
        if (difmatrizatualx == 0) {
            long endTime = System.currentTimeMillis();
            System.out.println("---------------------------------------");
            System.out.println("Arvores Geradas: " + arvoresgeradas);
            System.out.println("Arvores Processadas: " + arvoresprocessadas);
            System.out.println("Quantidade de Movimentos: " + estadomenor.getCusto());
            System.out.println("Tempo de processamento " + (endTime - startTime) + " ms");
            System.out.println("---------------------------------------\n\n");
            return 0;
        }//from   www.  j a  va2s .c o  m
        int[][] matrizatualx = estadomenor.getMatriz();
        arvoresprocessadas++;
        if (x0 >= 0) {

            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x0][y];
            matriz[x0][y] = matrizatualx[x][y];

            String stringmatriz1 = transformaMatrizString(matriz);
            if (!(processados.containsKey(stringmatriz1))) {
                arvoresgeradas++;
                h1x = MOAH12014.diferencaMatriz(matriz);
                h2x = MOAH22014.diferencaMatriz(matriz);
                h3x = MOAH32014.diferencaMatriz(matriz);
                int diferencamatriz = maior(h1x, h2x, h3x);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz1);

                processados.put(stringmatriz1, estadonovo);

            }
        }
        if (x1 <= 3) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x1][y];
            matriz[x1][y] = matrizatualx[x][y];
            String stringmatriz2 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz2))) {
                arvoresgeradas++;
                h1x = MOAH12014.diferencaMatriz(matriz);
                h2x = MOAH22014.diferencaMatriz(matriz);
                h3x = MOAH32014.diferencaMatriz(matriz);
                int diferencamatriz = maior(h1x, h2x, h3x);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz2);

                processados.put(stringmatriz2, estadonovo);

            }
        }
        if (y0 >= 0) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x][y0];
            matriz[x][y0] = matrizatualx[x][y];
            String stringmatriz3 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz3))) {
                arvoresgeradas++;
                h1x = MOAH12014.diferencaMatriz(matriz);
                h2x = MOAH22014.diferencaMatriz(matriz);
                h3x = MOAH32014.diferencaMatriz(matriz);
                int diferencamatriz = maior(h1x, h2x, h3x);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz3);

                processados.put(stringmatriz3, estadonovo);

            }
        }
        if (y1 <= 3) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x][y1];
            matriz[x][y1] = matrizatualx[x][y];

            String stringmatriz4 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz4))) {
                arvoresgeradas++;
                h1x = MOAH12014.diferencaMatriz(matriz);
                h2x = MOAH22014.diferencaMatriz(matriz);
                h3x = MOAH32014.diferencaMatriz(matriz);
                int diferencamatriz = maior(h1x, h2x, h3x);
                int custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz4);

                processados.put(stringmatriz4, estadonovo);

            }
        }
        open_list.remove(key, matrizatualx1);
    }
    return 0;

}

From source file:moa2014.MOAH42014.java

public static int principal(int[][] matrizatual, double c1, double c2, double c3) {
    long startTime = System.currentTimeMillis();
    Multimap<Double, String> open_list = TreeMultimap.create();
    HashMap<String, Estado> processados = new HashMap();

    double h1 = c1 * h1(matrizatual);
    double h2 = c2 * h2(matrizatual);
    double h3 = c3 * h3(matrizatual);
    double difmatrizatual = h1 + h2 + h3;

    String stringmatriz = transformaMatrizString(matrizatual);
    open_list.put(difmatrizatual, stringmatriz);
    Estado estadoatual = new Estado(matrizatual, 0);
    processados.put(stringmatriz, estadoatual);

    int arvoresgeradas = 0;
    int arvoresprocessadas = 0;

    while (!open_list.isEmpty()) {

        Iterator iterator = open_list.keySet().iterator();

        Double key = (Double) iterator.next();
        String matrizatualx1 = open_list.asMap().get(key).iterator().next();
        Estado estadomenor = processados.get(matrizatualx1);
        int altura = estadomenor.getCusto();

        //LOCALIZA O ZERO
        int[] zerot = localizazero(estadomenor.getMatriz());
        int x = zerot[0];
        int y = zerot[1];
        int x0 = x - 1;
        int x1 = x + 1;
        int y0 = y - 1;
        int y1 = y + 1;
        int difmatrizatualx = h1(estadomenor.getMatriz());
        if (difmatrizatualx == 0) {
            long endTime = System.currentTimeMillis();
            System.out.println("---------------------------------------");
            System.out.println("Arvores Geradas: " + arvoresgeradas);
            System.out.println("Arvores Processadas: " + arvoresprocessadas);
            System.out.println("Quantidade de Movimentos: " + estadomenor.getCusto());
            System.out.println("Tempo de processamento " + (endTime - startTime) + " ms");
            System.out.println("---------------------------------------\n\n");
            return 0;
        }//from  w  w w . j av a2 s .c  om
        arvoresprocessadas++;
        int[][] matrizatualx = estadomenor.getMatriz();
        if (x0 >= 0) {

            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x0][y];
            matriz[x0][y] = matrizatualx[x][y];

            String stringmatriz1 = transformaMatrizString(matriz);
            if (!(processados.containsKey(stringmatriz1))) {
                arvoresgeradas++;
                h1 = c1 * h1(matriz);
                h2 = c2 * h2(matriz);
                h3 = c3 * h3(matriz);
                double diferencamatriz = h1 + h2 + h3;
                double custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz1);

                processados.put(stringmatriz1, estadonovo);

            }
        }
        if (x1 <= 3) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x1][y];
            matriz[x1][y] = matrizatualx[x][y];
            String stringmatriz2 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz2))) {
                arvoresgeradas++;
                h1 = c1 * h1(matriz);
                h2 = c2 * h2(matriz);
                h3 = c3 * h3(matriz);
                double diferencamatriz = h1 + h2 + h3;
                double custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz2);

                processados.put(stringmatriz2, estadonovo);

            }
        }
        if (y0 >= 0) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x][y0];
            matriz[x][y0] = matrizatualx[x][y];
            String stringmatriz3 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz3))) {
                arvoresgeradas++;
                h1 = c1 * h1(matriz);
                h2 = c2 * h2(matriz);
                h3 = c3 * h3(matriz);
                double diferencamatriz = h1 + h2 + h3;
                double custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz3);

                processados.put(stringmatriz3, estadonovo);

            }
        }
        if (y1 <= 3) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x][y1];
            matriz[x][y1] = matrizatualx[x][y];

            String stringmatriz4 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz4))) {
                arvoresgeradas++;
                h1 = c1 * h1(matriz);
                h2 = c2 * h2(matriz);
                h3 = c3 * h3(matriz);
                double diferencamatriz = h1 + h2 + h3;
                double custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz4);

                processados.put(stringmatriz4, estadonovo);

            }
        }
        open_list.remove(key, matrizatualx1);
    }
    return 0;

}

From source file:com.gwtplatform.dispatch.rest.client.serialization.MultimapJsonSerializer.java

public String serialize(Multimap<?, ?> parameters) {
    if (parameters.isEmpty()) {
        return "{}";
    }// www .j a  v  a2 s  .  c o m

    return "{\"" + Joiner.on(",\"").withKeyValueSeparator("\":").join(parameters.asMap()) + "}";
}

From source file:eu.esdihumboldt.hale.ui.views.mapping.CellComparator.java

private boolean emptyOrNull(Multimap<?, ?> source) {
    return source == null || source.isEmpty();
}

From source file:com.ardor3d.util.TextureManager.java

/**
 * Deletes all textures from card for a specific gl context. This will gather all texture ids believed to be on the
 * card for the given context and try to delete them. If a deleter is passed in, textures that are part of the
 * currently active context (if one is active) will be deleted immediately. If a deleter is not passed in, we do not
 * have an active context, or we encounter textures that are not part of the current context, then we will queue
 * those textures to be deleted later using the GameTaskQueueManager.
 * /*from   ww  w.  j a v a 2s . c  o m*/
 * If a non null map is passed into futureStore, it will be populated with Future objects for each queued context.
 * These objects may be used to discover when the deletion tasks have all completed.
 * 
 * @param deleter
 *            if not null, this renderer will be used to immediately delete any textures in the currently active
 *            context. All other textures will be queued to delete in their own contexts.
 * @param context
 *            the context to delete for.
 * @param futureStore
 *            if not null, this map will be populated with any Future task handles created during cleanup.
 */
public static void cleanAllTextures(final Renderer deleter, final RenderContext context,
        final Map<Object, Future<Void>> futureStore) {
    // gather up expired textures... these don't exist in our cache
    Multimap<Object, Integer> idMap = gatherGCdIds();

    final Object glRep = context.getGlContextRep();
    // Walk through the cached items and gather those too.
    for (final TextureKey key : _tCache.keySet()) {
        // possibly lazy init
        if (idMap == null) {
            idMap = ArrayListMultimap.create();
        }

        final Integer id = key.getTextureIdForContext(glRep);
        if (id != 0) {
            idMap.put(context.getGlContextRep(), id);
            key.removeFromIdCache(glRep);
        }
    }

    // delete the ids
    if (!idMap.isEmpty()) {
        handleTextureDelete(deleter, idMap, futureStore);
    }
}

From source file:com.qcadoo.mes.workPlans.pdf.document.operation.grouping.container.util.OrderIdOperationNumberOperationComponentIdMap.java

private boolean isEmpty(Multimap<String, Long> innerMap) {
    return innerMap == null || innerMap.isEmpty();
}

From source file:matteroverdrive.items.android.TritaniumSpine.java

@Override
public Multimap<String, AttributeModifier> getModifiers(AndroidPlayer player, ItemStack itemStack) {
    Multimap multimap = super.getModifiers(player, itemStack);
    if (multimap.isEmpty()) {
        multimap.put(SharedMonsterAttributes.maxHealth.getAttributeUnlocalizedName(),
                new AttributeModifier(healthModifierID, MOStringHelper.translateToLocal(
                        "attribute.name." + SharedMonsterAttributes.maxHealth.getAttributeUnlocalizedName()),
                        2f, 0));//from   w  w  w  . j  ava  2s .  com
        multimap.put(AndroidAttributes.attributeGlitchTime.getAttributeUnlocalizedName(),
                new AttributeModifier(glitchModifierID,
                        MOStringHelper.translateToLocal("attribute.name.android.glitchTime"), -0.5f, 2));
    }
    return multimap;
}

From source file:org.apache.pulsar.broker.loadbalance.impl.WRRPlacementStrategy.java

/**
 * <code>/*from  w w w . ja v  a  2 s . c  om*/
 * Function : getByWeightedRoundRobin
 *            returns ResourceUnit selected by WRR algorithm based on available resource on RU
 * ^
 * |
 * |
 * |
 * |                |                        |                                |     |
 * |                |                        |                                |     |
 * |   Broker 2     |       Broker 3         |         Broker 1               |  B4 |
 * |                |                        |                                |     |
 * +----------------+------------------------+--------------------------------+--------->
 * 0                20                       50                               90    100
 *
 * This is weighted Round robin, we calculate weight based on availability of resources;
 * total availability is taken as a full range then each broker is given range based on
 *  its resource availability, if the number generated within total range happens to be in
 * broker's range, that broker is selected
 * </code>
 */
public ResourceUnit findBrokerForPlacement(Multimap<Long, ResourceUnit> finalCandidates) {
    if (finalCandidates.isEmpty()) {
        return null;
    }
    log.debug("Total Final Candidates selected - [{}]", finalCandidates.size());
    int totalAvailability = 0;
    for (Map.Entry<Long, ResourceUnit> candidateOwner : finalCandidates.entries()) {
        totalAvailability += candidateOwner.getKey().intValue();
    }
    ResourceUnit selectedRU = null;
    if (totalAvailability <= 0) {
        // todo: this means all the brokers are overloaded and we can't assign this namespace to any broker
        // for now, pick anyone and return that one, because when we don't have ranking we put O for each broker
        return Iterables.get(finalCandidates.get(0L), rand.nextInt(finalCandidates.size()));
    }
    int weightedSelector = rand.nextInt(totalAvailability);
    log.debug("Generated Weighted Selector Number - [{}] ", weightedSelector);
    int weightRangeSoFar = 0;
    for (Map.Entry<Long, ResourceUnit> candidateOwner : finalCandidates.entries()) {
        weightRangeSoFar += candidateOwner.getKey();
        if (weightedSelector < weightRangeSoFar) {
            selectedRU = candidateOwner.getValue();
            log.debug(" Weighted Round Robin Selected RU - [{}]", candidateOwner.getValue().getResourceId());
            break;
        }
    }
    return selectedRU;
}

From source file:com.isotrol.impe3.freemarker.FreeMarker.java

private static String returnUri(URI uri, List<String> args, int index) {
    if (uri == null) {
        return EMPTY;
    }/* w  w  w .  jav  a  2s  . c  om*/
    final Multimap<String, String> map = getParameters(args, index);
    if (map.isEmpty()) {
        return uri.toASCIIString();
    }
    final UriBuilder b = UriBuilder.fromUri(uri);
    for (Entry<String, ?> entry : map.entries()) {
        b.queryParam(entry.getKey(), entry.getValue());
    }
    return b.build().toASCIIString();
}

From source file:com.isotrol.impe3.freemarker.FreeMarker.java

private static String returnUri(String uri, List<String> args, int index) {
    if (uri == null) {
        return EMPTY;
    }// w  w  w .ja v  a  2 s  .co  m
    final Multimap<String, String> map = getParameters(args, index);
    if (map.isEmpty()) {
        return uri;
    }
    try {
        final UriBuilder b = UriBuilder.fromUri(uri);
        for (Entry<String, ?> entry : map.entries()) {
            b.queryParam(entry.getKey(), entry.getValue());
        }
        return b.build().toASCIIString();
    } catch (IllegalArgumentException e) {
        return uri;
    }
}