Java Code Examples for com.google.common.collect.LinkedListMultimap#get()

The following examples show how to use com.google.common.collect.LinkedListMultimap#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpUtils.java    From galaxy-sdk-java with Apache License 2.0 5 votes vote down vote up
public static String getSingleHeader(String header,
    LinkedListMultimap<String, String> headers) {
  List<String> values = headers.get(header);
  if (values == null) {
    values = headers.get(header.toLowerCase());
  }

  if (values != null && !values.isEmpty()) {
    return values.get(0);
  }
  return null;
}
 
Example 2
Source File: HttpUtils.java    From galaxy-sdk-java with Apache License 2.0 5 votes vote down vote up
public static String getSingleParam(String name, URI uri) {
  LinkedListMultimap<String, String> params = parseUriParameters(uri);
  if (params != null && !params.isEmpty()) {
    List<String> values = params.get(name);
    if (values == null) {
      values = params.get(name.toLowerCase());
    }

    if (values != null & !values.isEmpty()) {
      return values.get(0);
    }
  }
  return null;
}
 
Example 3
Source File: Signer.java    From galaxy-sdk-java with Apache License 2.0 5 votes vote down vote up
static String canonicalizeXiaomiHeaders(
    LinkedListMultimap<String, String> headers) {
  if (headers == null) {
    return "";
  }

  // 1. Sort the header and merge the values
  Map<String, String> sortedHeaders = new TreeMap<String, String>();
  for (String key : headers.keySet()) {
    if (!key.toLowerCase().startsWith(HttpKeys.XIAOMI_HEADER_PREFIX)) {
      continue;
    }

    StringBuilder builder = new StringBuilder();
    int index = 0;
    for (String value : headers.get(key)) {
      if (index != 0) {
        builder.append(",");
      }
      builder.append(value);
      index++;
    }
    sortedHeaders.put(key, builder.toString());
  }

  // 3. Generate the canonicalized result
  StringBuilder result = new StringBuilder();
  for (Entry<String, String> entry : sortedHeaders.entrySet()) {
    result.append(entry.getKey()).append(":")
        .append(entry.getValue()).append("\n");
  }
  return result.toString();
}
 
Example 4
Source File: Signer.java    From galaxy-sdk-java with Apache License 2.0 5 votes vote down vote up
static String canonicalizeResource(URI uri) {
  StringBuilder result = new StringBuilder();
  result.append(uri.getPath());

  // 1. Parse and sort subresources
  TreeMap<String, String> sortedParams = new TreeMap<String, String>();
  LinkedListMultimap<String, String> params = parseUriParameters(uri);
  for (String key : params.keySet()) {
    for (String value : params.get(key)) {
      if (SUB_RESOURCE_SET.contains(key)) {
        sortedParams.put(key, value);
      }
    }
  }

  // 2. Generate the canonicalized result
  if (!sortedParams.isEmpty()) {
    result.append("?");
    boolean isFirst = true;
    for (Entry<String, String> entry : sortedParams.entrySet()) {
      if (isFirst) {
        isFirst = false;
        result.append(entry.getKey());
      } else {
        result.append("&").append(entry.getKey());
      }

      if (!entry.getValue().isEmpty()) {
        result.append("=").append(entry.getValue());
      }
    }
  }
  return result.toString();
}
 
Example 5
Source File: Signer.java    From galaxy-sdk-java with Apache License 2.0 5 votes vote down vote up
static List<String> checkAndGet(LinkedListMultimap<String, String> headers,
    String header) {
  List<String> result = new LinkedList<String>();
  if (headers == null) {
    result.add("");
    return result;
  }

  List<String> values = headers.get(header);
  if (values == null || values.isEmpty()) {
    result.add("");
    return result;
  }
  return values;
}
 
Example 6
Source File: Signer.java    From galaxy-sdk-java with Apache License 2.0 5 votes vote down vote up
static long getExpires(URI uri) {
  LinkedListMultimap<String, String> params = parseUriParameters(uri);
  List<String> expires = params.get(HttpKeys.EXPIRES);
  if (expires != null && !expires.isEmpty()) {
    return Long.parseLong(expires.get(0));
  }
  return 0;
}
 
Example 7
Source File: SignatureUtil.java    From galaxy-sdk-java with Apache License 2.0 5 votes vote down vote up
public static String getAccessKeyId(URI uri) {
  Preconditions.checkNotNull(uri);
  String query = uri.getQuery();
  if (query != null) {
    LinkedListMultimap<String, String> params =
        HttpUtils.parseUriParameters(uri);
    List<String> keyIds = params.get(HttpKeys.GALAXY_ACCESS_KEY_ID);
    if (!keyIds.isEmpty()) {
      return params.get(HttpKeys.GALAXY_ACCESS_KEY_ID).get(0);
    }
  }
  return null;
}
 
Example 8
Source File: SignatureUtil.java    From galaxy-sdk-java with Apache License 2.0 5 votes vote down vote up
public static String getSignature(URI uri) {
  Preconditions.checkNotNull(uri);
  String query = uri.getQuery();
  if (query != null) {
    LinkedListMultimap<String, String> params =
        HttpUtils.parseUriParameters(uri);
    List<String> signatures = params.get(HttpKeys.SIGNATURE);
    if (!signatures.isEmpty()) {
      return params.get(HttpKeys.SIGNATURE).get(0);
    }
  }
  return null;
}
 
Example 9
Source File: SignatureUtil.java    From galaxy-sdk-java with Apache License 2.0 5 votes vote down vote up
public static long getDateTime(LinkedListMultimap<String, String> headers) {
  List<String> dateList = headers.get(HttpKeys.MI_DATE);
  if (dateList.isEmpty()) {
    dateList = headers.get(HttpKeys.DATE);
  }

  if (!dateList.isEmpty()) {
    String datetime = dateList.get(0);
    return HttpUtils.parseDateTimeToMilliseconds(datetime);
  }
  return 0;
}
 
Example 10
Source File: SignatureUtil.java    From galaxy-sdk-java with Apache License 2.0 5 votes vote down vote up
public static long getExpireTime(URI uri) {
  LinkedListMultimap<String, String> params = HttpUtils.parseUriParameters(uri);
  List<String> expireList = params.get(HttpKeys.EXPIRES);
  if (!expireList.isEmpty()) {
    return Long.parseLong(expireList.get(0));
  }
  return 0;
}
 
Example 11
Source File: KeyRangeIterable.java    From kite with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Iterator<MarkerRange> iterator() {
  // this should be part of PartitionStrategy
  final LinkedListMultimap<String, FieldPartitioner> partitioners =
      LinkedListMultimap.create();
  for (FieldPartitioner fp : Accessor.getDefault().getFieldPartitioners(strategy)) {
    partitioners.put(fp.getSourceName(), fp);
  }

  Iterator<MarkerRange.Builder> current = start(new MarkerRange.Builder(cmp));

  // primarily loop over sources because the logical constraints are there
  for (String source : partitioners.keySet()) {
    Predicate constraint = predicates.get(source);
    List<FieldPartitioner> fps = partitioners.get(source);
    FieldPartitioner first = fps.get(0);
    if (first instanceof CalendarFieldPartitioner) {
      current = TimeDomain.get(strategy, source)
          .addStackedIterator(constraint, current);
    } else if (constraint instanceof In) {
      current = add((In) constraint, fps, current);
    } else if (constraint instanceof Range) {
      current = add((Range) constraint, fps, current);
    }
  }

  return Iterators.transform(current, new ToMarkerRangeFunction());
}
 
Example 12
Source File: ExampleCoverage.java    From api-mining with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static Set<List<String>> getExampleAPICalls(final String project, final String projFQName)
		throws IOException, ClassNotFoundException {
	Set<List<String>> allCalls;

	// Read serialized example calls if they exist
	final File exampleCallsFile = new File(baseFolder + project + "/" + project + "_examplecalls.ser");
	if (exampleCallsFile.exists()) {
		final ObjectInputStream reader = new ObjectInputStream(new FileInputStream(exampleCallsFile));
		allCalls = (Set<List<String>>) reader.readObject();
		reader.close();
		return allCalls;
	} else { // otherwise create

		// Get all java files in source folder
		allCalls = new HashSet<>();
		final List<File> files = (List<File>) FileUtils.listFiles(new File(exampleFolder + project),
				new String[] { "java" }, true);
		Collections.sort(files);

		int count = 0;
		for (final File file : files) {
			System.out.println("\nFile: " + file);

			// Ignore empty files
			if (file.length() == 0)
				continue;

			if (count % 50 == 0)
				System.out.println("At file " + count + " of " + files.size());
			count++;

			final APICallVisitor acv = new APICallVisitor(ASTVisitors.getAST(file), namespaceFolder);
			acv.process();
			final LinkedListMultimap<String, String> fqAPICalls = acv.getAPINames(projFQName);
			for (final String fqCaller : fqAPICalls.keySet()) {
				final List<String> call = new ArrayList<>(fqAPICalls.get(fqCaller));
				if (call.size() > 1)
					allCalls.add(call);
			}
		}

		// Serialize calls
		final ObjectOutputStream writer = new ObjectOutputStream(new FileOutputStream(exampleCallsFile));
		writer.writeObject(allCalls);
		writer.close();

		return allCalls;
	}
}