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

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

Introduction

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

Prototype

Collection<V> get(@Nullable K key);

Source Link

Document

Returns a view collection of the values associated with key in this multimap, if any.

Usage

From source file:foo.domaintest.http.HttpApiModule.java

@Provides
@Param("header")/*from w w  w .j a  va2 s . com*/
Map<String, String> provideHeader(Multimap<String, String> params) {
    return parseMap(params.get("header"));
}

From source file:org.crypto.sse.ZMF.java

public static List<boolean[]> setupSetM(byte[] key, String keyword,
        Multimap<String, String> documentsComposition, Multimap<String, String> keywordComposition,
        int maxLengthOfMask, int falsePosRate) throws InvalidKeyException, NoSuchAlgorithmException,
        NoSuchProviderException, NoSuchPaddingException, IOException {

    // Extract all documents' identifiers that are associated to the keyword

    int identifierCounter = 0;
    int blockSize = 128;

    List<boolean[]> listOfBloomFilter = new ArrayList<boolean[]>();
    for (String identifier : keywordComposition.get(keyword)) {

        // Creation of ESet
        HashSet<Integer> state = new HashSet<Integer>();

        // Bloom Filter size setup such that it is a multiple of 2. This is
        // necessary when inserting the result of a hash which has a maximum
        // multiple of 2^x-1

        double arraySize = falsePosRate * documentsComposition.get(identifier).size() / Math.log(2);

        int counter = 0;
        for (int j = 0; j < 1000; j++) {
            if (arraySize > Math.pow(2, counter)) {
                counter++;//w ww .  ja  va2s.  c  om
            } else {
                break;
            }
        }

        // Creation of the Bloom filter
        boolean[] bloomFilter = new boolean[(int) Math.pow(2, counter)];

        // Key of PRF applied to elements

        byte[] keyPRF = new byte[key.length / 3];
        System.arraycopy(key, 0, keyPRF, 0, key.length / 3);

        // Key for the online cipher

        byte[] keyOCHash = new byte[key.length / 3];
        System.arraycopy(key, key.length / 3, keyOCHash, 0, key.length / 3);

        byte[] keyOCEnc = new byte[key.length / 3];
        System.arraycopy(key, 2 * key.length / 3, keyOCEnc, 0, key.length / 3);

        // Second Step of Secure Set protocol
        for (String word : documentsComposition.get(identifier)) {

            // computation of the PRF based on CMAC-AES
            byte[] cmac = CryptoPrimitives.generateCmac(keyPRF, keyword + word);

            // computation of the Random oracle based H1 on HMAC-SHA256
            // computation of the Random oracle based H2 on HMAC-SHA256

            int position = 0;
            boolean mask;

            // False positive rate is the number of hash functions

            for (int i = 0; i < falsePosRate; i++) {
                byte[] hmac = CryptoPrimitives.generateHmac(keyHMAC,
                        i + CryptoPrimitives.booleanToString(CryptoPrimitives.bytesToBoolean(cmac)));

                // We truncate the needed bits from the output of the HMAC
                // to get the bit 1 to counter

                position = CryptoPrimitives.getIntFromByte(hmac, maxLengthOfMask);
                if (!state.contains(position)) {
                    // Transform the position into an array of boolean []
                    boolean[] messageBol = CryptoPrimitives.intToBoolean(position, maxLengthOfMask);

                    boolean[][] results = CryptoPrimitives.onlineCipher(keyOCHash, keyOCEnc, messageBol);

                    // Printer.debugln("Time of the OCs "+
                    // messageBol.length+ " "+(endTime-startTime)+ "
                    // "+(endTime1-startTime1));

                    boolean[] positionFinal = new boolean[counter * blockSize];

                    for (int s = 0; s < counter; s++) {
                        System.arraycopy(results[s], 0, positionFinal, s * blockSize, blockSize);
                    }

                    byte[] hmac2 = CryptoPrimitives.generateHmac(keyHMAC,
                            identifierCounter + CryptoPrimitives.booleanToString(positionFinal));

                    // We truncate the needed bits from the output of the
                    // HMAC to get the bit 1 to counter
                    mask = (CryptoPrimitives.getBit(hmac2, 0) != 0);

                    int pos = CryptoPrimitives.getIntFromByte(hmac, counter);
                    bloomFilter[pos] = true ^ mask;
                    state.add(pos);
                }

            }
        }

        for (int j = 0; j < bloomFilter.length; j++) {

            if (!state.contains(j)) {
                boolean[] messageBol = CryptoPrimitives.intToBoolean(j, maxLengthOfMask);
                boolean[][] results = CryptoPrimitives.onlineCipher(keyOCHash, keyOCEnc, messageBol);
                boolean[] positionFinal = new boolean[counter * blockSize];
                for (int s = 0; s < counter; s++) {
                    System.arraycopy(results[s], 0, positionFinal, s * blockSize, blockSize);
                }

                byte[] hmac3 = CryptoPrimitives.generateHmac(keyHMAC,
                        identifierCounter + CryptoPrimitives.booleanToString(positionFinal));

                bloomFilter[j] = false ^ (CryptoPrimitives.getBit(hmac3, 0) != 0);

            }
        }

        listOfBloomFilter.add(bloomFilter);

        identifierCounter++;

    }

    return listOfBloomFilter;
}

From source file:eu.numberfour.n4js.xpect.ui.xpectmethods.NoerrorsXpectMethod.java

/**
 * Tests that NO error is issued at given position. Parameters are similar to error test.
 *//*  w  w w.  j a  v a  2 s. c  o  m*/
@Xpect
public void noerrors(@LinesExpectation ILinesExpectation expectation, @ThisResource XtextResource resource,
        @IssuesByLine Multimap<Integer, Issue> line2issue, @ThisOffset int offset) {
    List<String> issues = format(resource, line2issue.get(offset), Severity.ERROR);
    NoerrorsExpectationDelegate noerrorsExpectationDelegate = new NoerrorsExpectationDelegate(
            (LinesExpectationImpl) expectation);
    noerrorsExpectationDelegate.assertEquals(issues);
    // expectation.assertEquals(issues);
}

From source file:eu.numberfour.n4js.xpect.ui.xpectmethods.NoerrorsXpectMethod.java

/**
 * Tests that NO warnings is issued at given position. Parameters are similar to error test.
 *///  ww  w .  j a v a 2  s .co m
@Xpect
public void nowarnings(@LinesExpectation ILinesExpectation expectation, @ThisResource XtextResource resource,
        @IssuesByLine Multimap<Integer, Issue> line2issue, @ThisOffset int offset) {
    List<String> issues = format(resource, line2issue.get(offset), Severity.WARNING);
    NoerrorsExpectationDelegate noerrorsExpectationDelegate = new NoerrorsExpectationDelegate(
            (LinesExpectationImpl) expectation);
    noerrorsExpectationDelegate.assertEquals(issues);
    // expectation.assertEquals(issues);
}

From source file:foo.domaintest.http.HttpApiModule.java

@Provides
@Param("delcookie")
List<String> provideDelCookie(Multimap<String, String> params) {
    return ImmutableList.copyOf(params.get("delcookie"));
}

From source file:org.jclouds.cloudstack.filters.ReEncodeQueryWithDefaultURLEncoder.java

@Override
public HttpRequest filter(HttpRequest request) throws HttpException {
    UriBuilder builder = builders.get();
    builder.uri(request.getEndpoint());/* w  ww .  ja v  a  2  s .  co  m*/
    Multimap<String, String> map = Queries.parseQueryToMap(request.getEndpoint().getRawQuery());
    builder.replaceQuery("");
    for (String key : map.keySet())
        builder.queryParam(key, getOnlyElement(map.get(key)));
    return request.toBuilder().endpoint(builder.build()).build();
}

From source file:org.jclouds.deltacloud.compute.strategy.DeltacloudComputeServiceAdapter.java

Iterable<Transition> findChainTo(Instance.State desired, Instance.State currentState,
        Multimap<Instance.State, ? extends Transition> states) {
    for (Transition transition : states.get(currentState)) {
        if (currentState.ordinal() >= transition.getTo().ordinal())
            continue;
        if (transition.getTo() == desired)
            return ImmutableSet.<Transition>of(transition);
        Iterable<Transition> transitions = findChainTo(desired, transition.getTo(), states);
        if (Iterables.size(transitions) > 0)
            return Iterables.concat(ImmutableSet.of(transition), transitions);
    }//from   w  w  w .  ja  va2s. c  o m
    return ImmutableSet.<Transition>of();
}

From source file:foo.domaintest.http.HttpApiModule.java

@Provides
@Param("sleep")/*from   w  ww . ja v a 2 s . c  o  m*/
Integer provideSleep(Multimap<String, String> params) {
    String sleepString = getFirst(params.get("sleep"), null);
    return sleepString == null ? null : parseInt(sleepString);
}

From source file:org.calrissian.accumulorecipes.thirdparty.pig.loader.EventLoader.java

private String getProp(Multimap<String, String> queryParams, String propKey) {
    Collection<String> props = queryParams.get(propKey);
    if (props.size() > 0)
        return props.iterator().next();
    return null;/*from   w  w w .jav a  2s .co  m*/
}

From source file:com.cinchapi.concourse.importer.JsonImporter.java

/**
 * Given a string of JSON data, upsert it into Concourse.
 * /*from  www  .j  av  a 2 s  .co  m*/
 * @param json
 * @return the records that were affected by the import
 */
protected Set<Long> upsertJsonString(String json) {
    // TODO call concourse.upsert(json) when method is ready
    // NOTE: The following implementation is very inefficient, but will
    // suffice until the upsert functionality is available
    Set<Long> records = Sets.newHashSet();
    for (Multimap<String, Object> data : Convert.anyJsonToJava(json)) {
        Long record = MoreObjects.firstNonNull(
                (Long) Iterables.getOnlyElement(data.get(Constants.JSON_RESERVED_IDENTIFIER_NAME), null),
                Time.now());
        data.removeAll(Constants.JSON_RESERVED_IDENTIFIER_NAME);
        for (String key : data.keySet()) {
            for (Object value : data.get(key)) {
                concourse.add(key, value, record);
            }
        }
        records.add(record);
    }
    return records;
}