List of usage examples for com.google.common.primitives Longs toArray
public static long[] toArray(Collection<? extends Number> collection)
From source file:com.android.contacts.group.GroupMembersFragment.java
private void sendToGroup(long[] ids, String sendScheme, String title) { if (ids == null || ids.length == 0) return;//w w w . j a v a 2s .com // Get emails or phone numbers // contactMap <contact_id, contact_data> final Map<String, ContactDataHelperClass> contactMap = new HashMap<>(); // itemList <item_data> final List<String> itemList = new ArrayList<>(); final String sIds = GroupUtil.convertArrayToString(ids); final String select = (ContactsUtils.SCHEME_MAILTO.equals(sendScheme) ? Query.EMAIL_SELECTION : Query.PHONE_SELECTION) + " AND " + ContactsContract.Data.CONTACT_ID + " IN (" + sIds + ")"; final ContentResolver contentResolver = getContext().getContentResolver(); final Cursor cursor = contentResolver.query(ContactsContract.Data.CONTENT_URI, ContactsUtils.SCHEME_MAILTO.equals(sendScheme) ? Query.EMAIL_PROJECTION : Query.PHONE_PROJECTION, select, null, null); if (cursor == null) { return; } try { cursor.moveToPosition(-1); while (cursor.moveToNext()) { final String contactId = cursor.getString(Query.CONTACT_ID); final String itemId = cursor.getString(Query.ITEM_ID); final boolean isPrimary = cursor.getInt(Query.PRIMARY) != 0; final int timesUsed = cursor.getInt(Query.TIMES_USED); final String data = cursor.getString(Query.DATA1); if (!TextUtils.isEmpty(data)) { final ContactDataHelperClass contact; if (!contactMap.containsKey(contactId)) { contact = new ContactDataHelperClass(); contactMap.put(contactId, contact); } else { contact = contactMap.get(contactId); } contact.addItem(itemId, timesUsed, isPrimary); itemList.add(data); } } } finally { cursor.close(); } // Start picker if a contact does not have a default for (ContactDataHelperClass i : contactMap.values()) { if (!i.hasDefaultItem()) { // Build list of default selected item ids final List<Long> defaultSelection = new ArrayList<>(); for (ContactDataHelperClass j : contactMap.values()) { final String selectionItemId = j.getDefaultSelectionItemId(); if (selectionItemId != null) { defaultSelection.add(Long.parseLong(selectionItemId)); } } final long[] defaultSelectionArray = Longs.toArray(defaultSelection); startSendToSelectionPickerActivity(ids, defaultSelectionArray, sendScheme, title); return; } } if (itemList.size() == 0 || contactMap.size() < ids.length) { Toast.makeText(getContext(), ContactsUtils.SCHEME_MAILTO.equals(sendScheme) ? getString(R.string.groupSomeContactsNoEmailsToast) : getString(R.string.groupSomeContactsNoPhonesToast), Toast.LENGTH_LONG).show(); } if (itemList.size() == 0) { return; } final String itemsString = TextUtils.join(",", itemList); GroupUtil.startSendToSelectionActivity(this, itemsString, sendScheme, title); }
From source file:org.mrgeo.hdfs.tile.HdfsMrsTileReader.java
private void initPartitions(final Path splitsFilePath) { final List<Long> splitsA = new ArrayList<Long>(); partitions = new ArrayList<String>(); sf.readSplits(splitsFilePath.toString(), splitsA, partitions); // because of the way splits work, there should be 1 more partition name than splits if (splitsA.size() > 0 && partitions.size() != splitsA.size() + 1) { // This is kinda hacky, but if this is an old style splits file, we need to upgrade it. // This _should_ be the only place it is necessary. try {/* w w w. j av a2 s. co m*/ final Path tmp = new Path(HadoopFileUtils.getTempDir(conf), HadoopUtils.createRandomString(4) + "_splits"); FileUtil.copy(HadoopFileUtils.getFileSystem(conf, splitsFilePath), splitsFilePath, HadoopFileUtils.getFileSystem(conf, tmp), tmp, false, true, conf); sf.copySplitFile(tmp.toString(), splitsFilePath.getParent().toString(), true); sf.readSplits(splitsFilePath.toString(), splitsA, partitions); } catch (final IOException e) { e.printStackTrace(); } } // if we have no partitions, it probably means no splits file, look for mapfiles... if (partitions.size() == 0) { try { // get a Hadoop file system handle final FileSystem fs = splitsFilePath.getFileSystem(conf); // get the list of paths of the subdirectories of the parent final Path[] paths = FileUtil.stat2Paths(fs.listStatus(splitsFilePath.getParent())); Arrays.sort(paths); // look inside each subdirectory for a data dir and keep track for (final Path p : paths) { boolean isMapFileDir = false; final FileStatus[] dirFiles = fs.listStatus(p); for (final FileStatus dirFile : dirFiles) { if (dirFile.getPath().getName().equals("data")) { isMapFileDir = true; break; } } if (isMapFileDir) { final String name = p.toString(); partitions.add(name); } } if (partitions.size() == 1) { splitsA.clear(); splitsA.add(Long.MAX_VALUE); } } catch (final IOException e) { } } splits = Longs.toArray(splitsA); }
From source file:com.replaymod.replaystudio.launcher.Launcher.java
public void parseConfig(Studio studio, String line, String[] args) { String ios = line.substring(1, line.indexOf(')')); String instructions = line.substring(line.indexOf(')') + 2, line.length() - 1); int arg = 0;/*from w w w .ja v a 2s . c o m*/ try { for (String ioi : ios.split(",")) { String io = ioi.substring(1); if (ioi.charAt(0) == '<') { inputs.put(io, args[arg++]); } else if (ioi.charAt(0) == '>') { outputs.put(io, args[arg++]); } else if (ioi.charAt(0) == '-') { pipes.add(io); } else { throw new IllegalArgumentException("Config input/output is invalid: " + ioi); } } } catch (IndexOutOfBoundsException e) { System.out.println("Insufficient input/output files. Need at least " + arg); throw new CriticalException(7); } for (String instructionStr : instructions.split(Pattern.quote(")("))) { String ins = instructionStr; List<String> inputs = new ArrayList<>(); List<String> outputs = new ArrayList<>(); // Read inputs OUTER: while (true) { for (int i = 0; i < ins.length(); i++) { char c = ins.charAt(i); if (!Character.isAlphabetic(c)) { inputs.add(ins.substring(0, i)); if (c == ',') { ins = ins.substring(i + 1); continue OUTER; } else { ins = ins.substring(i); break OUTER; } } } throw new IllegalArgumentException("Config input/output is invalid: " + instructionStr); } // Read outputs OUTER: while (true) { for (int i = ins.length() - 1; i >= 0; i--) { char c = ins.charAt(i); if (!Character.isAlphabetic(c)) { outputs.add(ins.substring(i + 1)); if (c == ',') { ins = ins.substring(0, i); continue OUTER; } else { ins = ins.substring(0, i + 1); break OUTER; } } } throw new IllegalArgumentException("Config instruction input/output is invalid: " + instructionStr); } Collections.reverse(outputs); String options = ins.length() > 1 ? ins.substring(1, ins.length() - 1) : ""; Instruction instruction; switch (ins.charAt(0)) { case '|': // split Collection<Long> splitAt = Collections2.transform(Arrays.asList(options.split(",")), this::timeStampToMillis); instruction = new SplitInstruction(Longs.toArray(splitAt)); break; case '&': // append instruction = new AppendInstruction(); break; case '[': // squash instruction = new SquashInstruction(studio); break; case ':': // copy instruction = new CopyInstruction(); break; case '>': // filter String filterName; JsonObject filterOptions; if (options.contains(",")) { String[] parts = options.split(",", 2); filterName = parts[0]; filterOptions = new JsonParser().parse(parts[1]).getAsJsonObject(); } else { filterName = options; filterOptions = new JsonObject(); } Filter filter = studio.loadFilter(filterName); if (filter == null) { throw new IllegalStateException("Filter not found: " + filterName); } instruction = new FilterInstruction(studio, filter, filterOptions); break; default: throw new IllegalArgumentException("Config instruction is unknown: " + instructionStr); } instruction.getInputs().addAll(inputs); instruction.getOutputs().addAll(outputs); this.instructions.add(instruction); } }
From source file:org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5FormulaCreator.java
@Override public Long callFunctionImpl(FunctionDeclarationImpl<?, Long> declaration, List<Long> args) { return msat_make_term(environment, declaration.getSolverDeclaration(), Longs.toArray(args)); }
From source file:org.voltcore.agreement.MeshArbiter.java
/** * Collect the failure site update messages from all sites This site sent * its own mailbox the above broadcast the maximum is local to this site. * This also ensures at least one response. * * Concurrent failures can be detected by additional reports from the FaultDistributor * or a mismatch in the set of failed hosts reported in a message from another site *//*w w w. jav a2s . com*/ private boolean discoverGlobalFaultData_rcv(Set<Long> hsIds) { long blockedOnReceiveStart = System.currentTimeMillis(); long lastReportTime = 0; boolean haveEnough = false; int[] forwardStallCount = new int[] { FORWARD_STALL_COUNT }; do { VoltMessage m = m_mailbox.recvBlocking(receiveSubjects, 5); /* * If fault resolution takes longer then 10 seconds start logging */ final long now = System.currentTimeMillis(); if (now - blockedOnReceiveStart > 10000) { if (now - lastReportTime > 60000) { lastReportTime = System.currentTimeMillis(); haveNecessaryFaultInfo(m_seeker.getSurvivors(), true); } } if (m == null) { // Send a heartbeat to keep the dead host timeout active. Needed because IV2 doesn't // generate its own heartbeats to keep this running. m_meshAide.sendHeartbeats(m_seeker.getSurvivors()); } else if (m.getSubject() == Subject.SITE_FAILURE_UPDATE.getId()) { SiteFailureMessage sfm = (SiteFailureMessage) m; if (!m_seeker.getSurvivors().contains(m.m_sourceHSId) || m_failedSites.contains(m.m_sourceHSId) || m_failedSites.containsAll(sfm.getFailedSites())) continue; updateFailedSitesLedger(hsIds, sfm); m_seeker.add(sfm); addForwardCandidate(new SiteFailureForwardMessage(sfm)); m_recoveryLog.info("Agreement, Received " + sfm); } else if (m.getSubject() == Subject.SITE_FAILURE_FORWARD.getId()) { SiteFailureForwardMessage fsfm = (SiteFailureForwardMessage) m; addForwardCandidate(fsfm); if (!hsIds.contains(fsfm.m_sourceHSId) || m_seeker.getSurvivors().contains(fsfm.m_reportingHSId) || m_failedSites.contains(fsfm.m_reportingHSId) || m_failedSites.containsAll(fsfm.getFailedSites())) continue; m_seeker.add(fsfm); m_recoveryLog.info("Agreement, Received forward " + fsfm); forwardStallCount[0] = FORWARD_STALL_COUNT; } else if (m.getSubject() == Subject.FAILURE.getId()) { /* * If the fault distributor reports a new fault, ignore it if it is known , otherwise * re-deliver the message to ourself and then abort so that the process can restart. */ FaultMessage fm = (FaultMessage) m; Discard ignoreIt = mayIgnore(hsIds, fm); if (Discard.DoNot == ignoreIt) { m_mailbox.deliverFront(m); m_recoveryLog .info("Agreement, Detected a concurrent failure from FaultDistributor, new failed site " + CoreUtils.hsIdToString(fm.failedSite)); return false; } else { if (m_recoveryLog.isDebugEnabled()) { ignoreIt.log(fm); } } } haveEnough = haveEnough || haveNecessaryFaultInfo(m_seeker.getSurvivors(), false); if (haveEnough) { Iterator<Map.Entry<Long, SiteFailureForwardMessage>> itr = m_forwardCandidates.entrySet() .iterator(); while (itr.hasNext()) { Map.Entry<Long, SiteFailureForwardMessage> e = itr.next(); Set<Long> unseenBy = m_seeker.forWhomSiteIsDead(e.getKey()); if (unseenBy.size() > 0) { m_mailbox.send(Longs.toArray(unseenBy), e.getValue()); m_recoveryLog.info("Agreement, fowarding to " + CoreUtils.hsIdCollectionToString(unseenBy) + " " + e.getValue()); } itr.remove(); } } } while (!haveEnough || m_seeker.needForward(forwardStallCount)); return true; }
From source file:com.replaymod.replaystudio.launcher.Launcher.java
public void parseConfig(Studio studio, JsonObject root) { JsonArray instructions = root.getAsJsonArray("Instructions"); for (JsonElement e : instructions) { JsonObject o = e.getAsJsonObject(); Instruction instruction;//from ww w. j a v a2 s. c o m switch (o.get("Name").getAsString().toLowerCase()) { case "split": if (o.get("at").isJsonArray()) { List<Long> at = new ArrayList<>(); Iterables.addAll(at, Iterables.transform(o.getAsJsonArray("at"), (e1) -> timeStampToMillis(e1.toString()))); instruction = new SplitInstruction(Longs.toArray(at)); } else { instruction = new SplitInstruction(timeStampToMillis(o.get("at").toString())); } break; case "append": instruction = new AppendInstruction(); break; case "squash": instruction = new SquashInstruction(studio); break; case "copy": instruction = new CopyInstruction(); break; case "filter": Filter filter = studio.loadFilter(o.get("Filter").toString()); instruction = new FilterInstruction(studio, filter, o.getAsJsonObject("Config")); break; default: System.out.println("Warning: Unrecognized instruction in json config: " + o.get("Name")); continue; } JsonElement inputs = o.get("Inputs"); if (inputs.isJsonArray()) { for (JsonElement e1 : inputs.getAsJsonArray()) { instruction.getInputs().add(e1.getAsString()); } } else { instruction.getInputs().add(inputs.getAsString()); } JsonElement outputs = o.get("Outputs"); if (outputs.isJsonArray()) { for (JsonElement e1 : outputs.getAsJsonArray()) { instruction.getOutputs().add(e1.getAsString()); } } else { instruction.getOutputs().add(outputs.getAsString()); } this.instructions.add(instruction); } // Get all inputs JsonObject inputs = root.getAsJsonObject("Inputs"); for (Map.Entry<String, JsonElement> e : inputs.entrySet()) { this.inputs.put(e.getKey(), e.getValue().getAsString()); } // Get all outputs JsonObject outputs = root.getAsJsonObject("Outputs"); for (Map.Entry<String, JsonElement> e : outputs.entrySet()) { this.outputs.put(e.getKey(), e.getValue().getAsString()); } // Calculate all pipes for (Instruction instruction : this.instructions) { pipes.addAll(instruction.getInputs()); pipes.addAll(instruction.getOutputs()); } pipes.removeAll(this.inputs.keySet()); pipes.removeAll(this.outputs.keySet()); }
From source file:co.cask.cdap.api.dataset.lib.IndexedTable.java
/** * Increments (atomically) the specified row and columns by the specified amounts, and returns the new values. * Note that performing this operation on an indexed column will generally have a negative impact on performance, * since up to three writes will need to be performed for every increment (one removing the index for the previous, * pre-increment value, one adding the index for the incremented value, and one for the increment itself). * * @see Table#incrementAndGet(Increment) *//* w ww. ja v a 2 s . com*/ @Override public Row incrementAndGet(Increment increment) { Map<byte[], Long> incrementValues = increment.getValues(); return incrementAndGet(increment.getRow(), incrementValues.keySet().toArray(new byte[incrementValues.size()][]), Longs.toArray(incrementValues.values())); }
From source file:com.android.incallui.CallerInfoAsyncQuery.java
private static long[] getDirectoryIds(Context context) { ArrayList<Long> results = new ArrayList<>(); Uri uri = Directory.CONTENT_URI; if (ContactsUtils.FLAG_N_FEATURE) { uri = Uri.withAppendedPath(ContactsContract.AUTHORITY_URI, "directories_enterprise"); }// w ww .ja va 2 s . com ContentResolver cr = context.getContentResolver(); Cursor cursor = cr.query(uri, DIRECTORY_PROJECTION, null, null, null); addDirectoryIdsFromCursor(cursor, results); return Longs.toArray(results); }
From source file:org.sosy_lab.java_smt.solvers.z3.Z3FormulaCreator.java
@Override public Long callFunctionImpl(FunctionDeclarationImpl<?, Long> declaration, List<Long> args) { return Native.mkApp(environment, declaration.getSolverDeclaration(), args.size(), Longs.toArray(args)); }
From source file:com.flexive.shared.value.FxValue.java
/** * Get all languages for which translations exist * * @return languages for which translations exist *///from w ww.j av a 2s .co m public long[] getTranslatedLanguages() { if (isMultiLanguage()) { final List<Long> languages = Lists.newArrayListWithCapacity(translations.size()); for (Entry<Long, T> entry : translations.entrySet()) { if (!valueEmpty(entry.getValue())) { languages.add(entry.getKey()); } } return Longs.toArray(languages); } else { return SYSTEM_LANG_ARRAY.clone(); } }