List of usage examples for java.lang Long MIN_VALUE
long MIN_VALUE
To view the source code for java.lang Long MIN_VALUE.
Click Source Link
From source file:com.google.uzaygezen.core.BitVectorTest.java
@Test public void equalsAndHashCode() { final int size = 10; for (long i = 1 << size; --i >= 0;) { checkEqualsAndHashCode(size, i); }//from w w w . j av a 2 s. c o m for (long i = Long.MIN_VALUE; --i >= Long.MAX_VALUE - 1024;) { checkEqualsAndHashCode(64, i); } for (long i = Long.MIN_VALUE; ++i <= Long.MIN_VALUE + 1024;) { checkEqualsAndHashCode(64, i); } final int bigSize = 1000; BitVector[] equals = new BitVector[4]; equals[0] = new BitSetBackedBitVector(bigSize); equals[1] = new BitSetBackedBitVector(bigSize); equals[2] = new LongArrayBitVector(bigSize); equals[3] = new LongArrayBitVector(bigSize); for (int i = 0; i < 1000; ++i) { for (int j = 0; j < bigSize; ++j) { boolean value = random.nextBoolean(); for (int k = 0; k < equals.length; ++k) { equals[k].set(j, value); } } for (int j = 0; j < equals.length; ++j) { for (int k = 0; k < equals.length; ++k) { MoreAsserts.checkEqualsAndHashCodeMethods(equals[j], equals[k], true); } } } }
From source file:com.projity.pm.criticalpath.TaskSchedule.java
/** * During the forward pass, begin is early dates, during backward pass, it is late dates. * When reverse scheduling, the backward pass is executed first, then the forward. * The late schedule uses a trick: dates are returned as negative values. This lets me to use the same min/max code. Also * the calendar code knows to reverse durations when the date is negative. * @param boundary // ww w . j av a2 s .c o m * @param honorRequiredDates * @param early * @return */ private void calcStartAndFinish(CalculationContext context) { long begin = getBeginDependency(); Task parent = task.getWbsParentTask(); //boolean useSooner = (forward != task.hasDuration()); // shortcut: if forward and is milestone, use sooner, otherwise later. And conversely, if reverse and isn't milestone, use sooner, othewise later boolean useSooner = !task.hasDuration(); if (parent != null) { TaskSchedule parentSchedule = parent.getSchedule(type); long parentDependency = parentSchedule.getBeginDependency(); long parentWindow = parentSchedule.getWindowBegin(); if (parentDependency == 0 || (parentWindow != 0 && parentWindow > parentDependency)) parentDependency = parentWindow; // in case where parent determines start time, make sure that this // task starts either at day end if milesetone, or at next working // day otherwise if parent is at day end if (parentDependency != 0 && (begin == 0 || parentDependency > begin)) { begin = task.getEffectiveWorkCalendar().add(parentDependency, 0, useSooner); } } if (task.isInSubproject()) begin = Math.max(begin, context.forward ? task.getOwningProject().getStartConstraint() : -task.getOwningProject().getEnd()); // Soft constraints long windowBegin = getWindowBegin(); // Make sure the task starts after its early start window date. This // is a soft constraint during forward pass. // For SNET if (windowBegin != 0) { if (begin == 0) begin = windowBegin; else if (windowBegin < begin) { if (task.startsBeforeProject()) // case of task starting before project start but has SNET constraint begin = windowBegin; } else begin = windowBegin; } // For FNET long windowEnd = getWindowEnd(); if (windowEnd != 0) { if (begin == 0) begin = Long.MIN_VALUE; begin = Math.max(begin, task.calcOffsetFrom(windowEnd, windowEnd, false, false, useSooner)); // System.out.println("Applying FNET " + task + " " + d(windowEnd) + " begin is now " + d(begin)); } // Hard constraints if (context.honorRequiredDates) { // If honoring required dates, check the hard constraint that the // task is finished by its late finish date. // Note that currently late finish has priority over early start. long oppositeEnd = -getOppositeSchedule().getWindowBegin(); // For FNLT if (oppositeEnd != 0) { if (begin == 0) begin = Long.MAX_VALUE; begin = Math.min(begin, task.calcOffsetFrom(oppositeEnd, dependencyDate, false, false, useSooner)); // System.out.println("Applying FNLT " + task + " " + d(oppositeEnd) + " begin is now " + d(begin)); } // For SNLT long oppositeBegin = -getOppositeSchedule().getWindowEnd(); if (oppositeBegin != 0) { if (begin == 0) begin = Long.MAX_VALUE; begin = Math.min(begin, oppositeBegin); // System.out.println("Applying SNLT " + task + " " + d(oppositeBegin) + " begin is now " + d(begin)); } } if (begin == 0) { if (!task.isWbsParent()) // if no constraints at all begin = context.boundary; } if (task.isSubproject()) {// subprojects can't start before their project start SubProj subProj = (SubProj) task; if (!subProj.isValidAndOpen()) return; if (task.getPredecessorList().size() == 0 && task.getConstraintDate() == 0) return; begin = Math.max(begin, context.forward ? subProj.getSubproject().getStartConstraint() : -subProj.getSubproject().getEnd()); } long levelingDelay = task.getLevelingDelay(); if (Duration.millis(levelingDelay) != 0) begin = task.getEffectiveWorkCalendar().add(begin, levelingDelay, useSooner); long remainingBegin = begin; if (forward == context.forward) setRemainingDependencyDate(remainingBegin); // the date which predecessors push the task to start at. Actuals can override this if (context.forward) { long actualStart = task.getActualStart(); if (actualStart != 0) begin = actualStart; } setBegin(begin); long end = ((Task) task).calcOffsetFrom(begin, remainingBegin, true, true, true); setEnd(end); }
From source file:com.rareventure.gps2.reviewer.map.OsmMapGpsTrailerReviewerMapActivity.java
private void initSasPanel() { ListView sasPanelList = (ListView) findViewById(R.id.sas_grid); sasPanelList.setOnItemClickListener(new OnItemClickListener() { private static final int MIN_TR_TIMESPAN_SEC = Util.SECONDS_IN_DAY; private static final int TR_TIMESPAN_MULTIPLIER = 3; @Override//from w w w . ja va2 s . com public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //note that getTimeRange reuses the same tr instance, so we have to be careful // when we call it twice TimeRange tr = gpsTrailerOverlay.sas.getTimeRange(position - 1); int currStartSec = tr.startTimeSec; int currEndSec = tr.endTimeSec; //co: we just want the time inside the box // int timeSpan; // // if(tr.fullRangeEndSec - tr.fullRangeStartSec < MIN_TR_TIMESPAN_SEC / TR_TIMESPAN_MULTIPLIER) // { // timeSpan = MIN_TR_TIMESPAN_SEC; // } // else // { // timeSpan = (tr.fullRangeEndSec - tr.fullRangeStartSec) * TR_TIMESPAN_MULTIPLIER; // } // // int currStartSec = (int) Math.max(- timeSpan /2 + (tr.endTimeSec/2 + tr.startTimeSec/2), getStartTimeMs()/1000); // int currEndSec = (int) Math.min(timeSpan /2 + (tr.endTimeSec/2 + tr.startTimeSec/2), getEndTimeMs()/1000); // // if(position > 0) // { // TimeRange prevTr = gpsTrailerOverlay.sas.getTimeRange(position-1); // currStartSec = Math.max(prevTr.endTimeSec, currStartSec); // } // // if(position < gpsTrailerOverlay.sas.getTimeRangeCount() - 1) // { // TimeRange nextTr = gpsTrailerOverlay.sas.getTimeRange(position+1); // currEndSec = Math.min(nextTr.startTimeSec, currEndSec); // } // if (currEndSec - currStartSec < timeView.getMinSelectableTimeSec()) { currEndSec = currStartSec + timeView.getMinSelectableTimeSec(); } setStartAndEndTimeSec(currStartSec, currEndSec); updateTimeViewTime(); } }); sasPanelList.setAdapter(new ListAdapter() { @Override public void unregisterDataSetObserver(DataSetObserver observer) { gpsTrailerOverlay.sas.unregisterDataSetObserver(observer); } @Override public void registerDataSetObserver(DataSetObserver observer) { gpsTrailerOverlay.sas.registerDataSetObserver(observer); } @Override public boolean isEmpty() { return gpsTrailerOverlay.sas.isEmpty(); } @Override public boolean hasStableIds() { return false; //because we might merge timeviews } @Override public int getViewTypeCount() { return 2; } public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { // Log.d(GTG.TAG,"SASPanel: Creating new view"); if (position == 0) convertView = getLayoutInflater().inflate(R.layout.selected_area_info_top_row, null); else convertView = getLayoutInflater().inflate(R.layout.selected_area_info_row, null); } // else // Log.d(GTG.TAG,"SASPanel: Reusing view"); if (position == 0) { ((TextView) convertView.findViewById(R.id.totalTime)) .setText(Util.convertMsToText(gpsTrailerOverlay.sas.getTotalTimeSecs() * 1000l)); ((TextView) convertView.findViewById(R.id.totalDist)).setText(MapScaleWidget .calcLabelForLength(gpsTrailerOverlay.sas.getTotalDistM(), GTG.prefs.useMetric)); ((TextView) convertView.findViewById(R.id.timesInArea)) .setText(String.valueOf(gpsTrailerOverlay.sas.getTimesInArea())); ((TextView) convertView.findViewById(R.id.timesInArea)) .setText(String.valueOf(gpsTrailerOverlay.sas.getTimesInArea())); TimeZone tz = gpsTrailerOverlay.sas.timeZone; if (tz == null || tz.hasSameRules(Util.getCurrTimeZone())) { convertView.findViewById(R.id.timeZoneTableRow).setVisibility(View.GONE); } else { convertView.findViewById(R.id.timeZoneTableRow).setVisibility(View.VISIBLE); ((TextView) convertView.findViewById(R.id.timezone)).setText(tz.getDisplayName()); } return convertView; } TimeRange tr = gpsTrailerOverlay.sas.getTimeRange(position - 1); timeAndDateSdf.setTimeZone(gpsTrailerOverlay.sas.timeZone); String startText = timeAndDateSdf.format(new Date(tr.startTimeSec * 1000l)); String endText = timeAndDateSdf.format(new Date(tr.endTimeSec * 1000l)); ((TextView) convertView.findViewById(R.id.startTime)).setText(startText); ((TextView) convertView.findViewById(R.id.endTime)).setText(endText); String distText; if (tr.dist == -1) distText = "--"; else { distText = MapScaleWidget.calcLabelForLength(tr.dist, GTG.prefs.useMetric); } ((TextView) convertView.findViewById(R.id.distance)).setText(distText); //this fixes a bug where sometimes if the last row is deleted and readded, it isn't //layedout again, causing the date/times to be cut off convertView.requestLayout(); // ((TextView)convertView.findViewById(R.id.timeLength)).setText("a certain amount of time"); return convertView; } @Override public int getItemViewType(int position) { if (position == 0) return 0; return 1; } @Override public long getItemId(int position) { if (position == 0) return Long.MIN_VALUE; TimeRange tr = gpsTrailerOverlay.sas.getTimeRange(position - 1); return tr.fullRangeStartSec; } @Override public Object getItem(int position) { if (position == 0) return null; return gpsTrailerOverlay.sas.getTimeRange(position - 1); } @Override public int getCount() { int count = gpsTrailerOverlay.sas.getTimeRangeCount(); // Log.d(GTG.TAG,"item count is "+count); if (count >= 1) return count + 1; return 0; } @Override public boolean isEnabled(int position) { if (position == 0) return false; return true; } @Override public boolean areAllItemsEnabled() { return false; } }); }
From source file:org.apache.hadoop.hbase.backup.impl.BackupAdminImpl.java
/** * Verifies that backup images are valid for merge. * * <ul>//from w w w .j a va 2 s. c o m * <li>All backups MUST be in the same destination * <li>No FULL backups are allowed - only INCREMENTAL * <li>All backups must be in COMPLETE state * <li>No holes in backup list are allowed * </ul> * <p> * @param backupIds list of backup ids * @param table backup system table * @throws IOException if the backup image is not valid for merge */ private void checkIfValidForMerge(String[] backupIds, BackupSystemTable table) throws IOException { String backupRoot = null; final Set<TableName> allTables = new HashSet<>(); final Set<String> allBackups = new HashSet<>(); long minTime = Long.MAX_VALUE, maxTime = Long.MIN_VALUE; for (String backupId : backupIds) { BackupInfo bInfo = table.readBackupInfo(backupId); if (bInfo == null) { String msg = "Backup session " + backupId + " not found"; throw new IOException(msg); } if (backupRoot == null) { backupRoot = bInfo.getBackupRootDir(); } else if (!bInfo.getBackupRootDir().equals(backupRoot)) { throw new IOException("Found different backup destinations in a list of a backup sessions " + "\n1. " + backupRoot + "\n" + "2. " + bInfo.getBackupRootDir()); } if (bInfo.getType() == BackupType.FULL) { throw new IOException("FULL backup image can not be merged for: \n" + bInfo); } if (bInfo.getState() != BackupState.COMPLETE) { throw new IOException("Backup image " + backupId + " can not be merged becuase of its state: " + bInfo.getState()); } allBackups.add(backupId); allTables.addAll(bInfo.getTableNames()); long time = bInfo.getStartTs(); if (time < minTime) { minTime = time; } if (time > maxTime) { maxTime = time; } } final long startRangeTime = minTime; final long endRangeTime = maxTime; final String backupDest = backupRoot; // Check we have no 'holes' in backup id list // Filter 1 : backupRoot // Filter 2 : time range filter // Filter 3 : table filter BackupInfo.Filter destinationFilter = info -> info.getBackupRootDir().equals(backupDest); BackupInfo.Filter timeRangeFilter = info -> { long time = info.getStartTs(); return time >= startRangeTime && time <= endRangeTime; }; BackupInfo.Filter tableFilter = info -> { List<TableName> tables = info.getTableNames(); return !Collections.disjoint(allTables, tables); }; BackupInfo.Filter typeFilter = info -> info.getType() == BackupType.INCREMENTAL; BackupInfo.Filter stateFilter = info -> info.getState() == BackupState.COMPLETE; List<BackupInfo> allInfos = table.getBackupHistory(-1, destinationFilter, timeRangeFilter, tableFilter, typeFilter, stateFilter); if (allInfos.size() != allBackups.size()) { // Yes we have at least one hole in backup image sequence List<String> missingIds = new ArrayList<>(); for (BackupInfo info : allInfos) { if (allBackups.contains(info.getBackupId())) { continue; } missingIds.add(info.getBackupId()); } String errMsg = "Sequence of backup ids has 'holes'. The following backup images must be added:" + org.apache.hadoop.util.StringUtils.join(",", missingIds); throw new IOException(errMsg); } }
From source file:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginView.java
/** * /*from w ww .ja va 2 s . c om*/ * @param path int of the path to get the Time Options for * @param storedTimePref Long of anytime during the specific day that we want to return times for * @return populates the "times" TreeSet (time longs truncated at the "the seconds" position) * which populates Time Combo box, the truncTimeToFullTimeMap which maps the truncated times * im times TreeSet to each times full Long value. The truncTimeToFullTimeMap chooses each time * up to the second and maps it to the greatest equivalent time up to the milliseconds. * */ protected void setTimeOptions(int path, Long storedTimePref) { try { timeSelectCombo.getItems().clear(); overrideTimestamp = null; Date startDate = null, finishDate = null; if (storedTimePref != null) { StampBdb stampDb = Bdb.getStampDb(); NidSet nidSet = new NidSet(); nidSet.add(path); NidSetBI stamps = null; if (!storedTimePref.equals(getDefaultTime())) { startDate = getStartOfDay(new Date(storedTimePref)); finishDate = getEndOfDay(new Date(storedTimePref)); stamps = stampDb.getSpecifiedStamps(nidSet, startDate.getTime(), finishDate.getTime()); } else { stamps = stampDb.getSpecifiedStamps(nidSet, Long.MIN_VALUE, Long.MAX_VALUE); } truncTimeToFullTimeMap.clear(); times.clear(); HashSet<Integer> stampSet = stamps.getAsSet(); Date d = new Date(storedTimePref); if (dateIsLocalDate(d)) { // Get stamps of day Date todayStartDate = getStartOfDay(new Date()); Date todayFinishDate = getEndOfDay(new Date()); NidSetBI todayStamps = stampDb.getSpecifiedStamps(nidSet, todayStartDate.getTime(), todayFinishDate.getTime()); // If have stamps, no action, if not, show Latest and set stamps to latest stamp we have in stampset if (todayStamps.size() == 0) { // timeSelectCombo.getItems().add(Long.MAX_VALUE); NidSetBI allStamps = stampDb.getSpecifiedStamps(nidSet, Long.MIN_VALUE, Long.MAX_VALUE); HashSet<Integer> allStampSet = allStamps.getAsSet(); SortedSet<Integer> s = new TreeSet<Integer>(allStampSet); if (!s.isEmpty()) { Integer stampToSet = s.last(); overrideTimestamp = stampDb.getPosition(stampToSet).getTime(); timeSelectCombo.getItems().add(Long.MAX_VALUE); timeSelectCombo.setValue(Long.MAX_VALUE); } } } this.pathDatesList.add(LocalDate.now()); if (overrideTimestamp == null) { if (!stampSet.isEmpty()) { enableTimeCombo(true); for (Integer thisStamp : stampSet) { Long fullTime = null; Date stampDate; LocalDate stampInstant = null; try { fullTime = stampDb.getPosition(thisStamp).getTime(); stampDate = new Date(fullTime); stampInstant = stampDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); } catch (Exception e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); cal.setTime(new Date(fullTime)); cal.set(Calendar.MILLISECOND, 0); //Strip milliseconds Long truncTime = cal.getTimeInMillis(); this.pathDatesList.add(stampInstant); //Build DatePicker times.add(truncTime); //This can probably go, we don't populate hashmap like this at initialization timeSelectCombo.getItems().add(truncTime); if (truncTimeToFullTimeMap.containsKey(truncTime)) { //Build Truncated Time to Full Time HashMap //If truncTimeToFullTimeMap has this key, is the value the newest time in milliseconds? if (new Date(truncTimeToFullTimeMap.get(truncTime)).before(new Date(fullTime))) { truncTimeToFullTimeMap.put(truncTime, fullTime); } } else { truncTimeToFullTimeMap.put(truncTime, fullTime); } } } else { // disableTimeCombo(true); // timeSelectCombo.getItems().add(Long.MAX_VALUE); timeSelectCombo.setValue(Long.MAX_VALUE); enableTimeCombo(true); // logger.error("Could not retreive any Stamps"); } } } } catch (Exception e) { logger.error("Error setting the default Time Dropdown"); e.printStackTrace(); } }
From source file:org.zenoss.zep.dao.impl.EventDaoHelper.java
@TransactionalReadOnly public EventBatch listBatch(SimpleJdbcOperations template, String tableName, RangePartitioner partitioner, EventBatchParams batchParams, long maxUpdateTime, int limit, EventSummaryRowMapper esrm) throws ZepException { if (partitioner == null) { List<EventSummary> events = listBatch(template, tableName, batchParams == null ? null : batchParams.nextUuid, maxUpdateTime, limit, esrm); if (events.isEmpty()) { return new EventBatch(events, Long.MIN_VALUE, null); } else {/*from w w w . j av a 2 s .c o m*/ return new EventBatch(events, Long.MIN_VALUE, Iterables.getLast(events).getUuid()); } } else { final Object maxUpdateTimeObject = databaseCompatibility.getTimestampConverter() .toDatabaseType(maxUpdateTime); List<EventSummary> events = new ArrayList<EventSummary>(limit); long nextLastSeen = (batchParams == null) ? Long.MAX_VALUE : batchParams.nextLastSeen; String nextUuid = (batchParams == null) ? null : batchParams.nextUuid; for (Partition p : Lists.reverse(partitioner.listPartitions())) { if (p.getRangeMinimum() != null) { long partitionMin = p.getRangeMinimum().getTime(); if (partitionMin > nextLastSeen) continue; else if (partitionMin < nextLastSeen) nextLastSeen = partitionMin; events.addAll(listBatchInPartition(template, tableName, p, nextUuid, maxUpdateTimeObject, limit - events.size(), esrm)); if (events.size() >= limit) { nextUuid = Iterables.getLast(events).getUuid(); break; } else { nextUuid = null; } } else { nextLastSeen = Long.MIN_VALUE; events.addAll(listBatchInPartition(template, tableName, p, nextUuid, maxUpdateTimeObject, limit - events.size(), esrm)); if (events.size() >= limit) { nextUuid = Iterables.getLast(events).getUuid(); break; } else { nextUuid = null; } } } return new EventBatch(events, nextLastSeen, nextUuid); } }
From source file:android.support.v7.widget.helper.ItemTouchHelper.java
/** * If user drags the view to the edge, trigger a scroll if necessary. *//*from w ww . j a va2s . c o m*/ private boolean scrollIfNecessary() { if (mSelected == null) { mDragScrollStartTimeInMs = Long.MIN_VALUE; return false; } final long now = System.currentTimeMillis(); final long scrollDuration = mDragScrollStartTimeInMs == Long.MIN_VALUE ? 0 : now - mDragScrollStartTimeInMs; RecyclerView.LayoutManager lm = mRecyclerView.getLayoutManager(); if (mTmpRect == null) { mTmpRect = new Rect(); } int scrollX = 0; int scrollY = 0; lm.calculateItemDecorationsForChild(mSelected.itemView, mTmpRect); if (lm.canScrollHorizontally()) { int curX = (int) (mSelectedStartX + mDx); final int leftDiff = curX - mTmpRect.left - mRecyclerView.getPaddingLeft(); if (mDx < 0 && leftDiff < 0) { scrollX = leftDiff; } else if (mDx > 0) { final int rightDiff = curX + mSelected.itemView.getWidth() + mTmpRect.right - (mRecyclerView.getWidth() - mRecyclerView.getPaddingRight()); if (rightDiff > 0) { scrollX = rightDiff; } } } if (lm.canScrollVertically()) { int curY = (int) (mSelectedStartY + mDy); final int topDiff = curY - mTmpRect.top - mRecyclerView.getPaddingTop(); if (mDy < 0 && topDiff < 0) { scrollY = topDiff; } else if (mDy > 0) { final int bottomDiff = curY + mSelected.itemView.getHeight() + mTmpRect.bottom - (mRecyclerView.getHeight() - mRecyclerView.getPaddingBottom()); if (bottomDiff > 0) { scrollY = bottomDiff; } } } if (scrollX != 0) { scrollX = mCallback.interpolateOutOfBoundsScroll(mRecyclerView, mSelected.itemView.getWidth(), scrollX, mRecyclerView.getWidth(), scrollDuration); } if (scrollY != 0) { scrollY = mCallback.interpolateOutOfBoundsScroll(mRecyclerView, mSelected.itemView.getHeight(), scrollY, mRecyclerView.getHeight(), scrollDuration); } if (scrollX != 0 || scrollY != 0) { if (mDragScrollStartTimeInMs == Long.MIN_VALUE) { mDragScrollStartTimeInMs = now; } mRecyclerView.scrollBy(scrollX, scrollY); return true; } mDragScrollStartTimeInMs = Long.MIN_VALUE; return false; }
From source file:edu.cornell.med.icb.goby.alignments.AlignmentReaderImpl.java
/** * Calculate the offset (in bytes) in the compact entries file for a specific targetIndex and position. * Entries that can be read after this position are guaranteed to have targetIndex larger or equal to targetIndex * and positions larger or equal to position. * The parameter chunkOffset can be used to iterate through successive protocol buffer compressed chunks. * A typical usage is to call getByteOffset with startReference and startPosition. A second call to getByteOffset * with endReference and endPosition with chunkOffset=0 will return an end position. If the end and start positions * are the same, both start and end locations are in the same chunk. In this case, it is necessary to extend the end * byte position to include the entire chunk. This can be achieved by calling getByteOffset with endReference and endPosition * and a chunkOffset of 1. Because it is possible that the next chunk also contains only entries with the same position, * one must//w w w . j a va2 s . c o m * use 0, 1,2, etc until the returned offset differs allows to make sure the indexed position is at the start of a new chunk. * * @param targetIndex Index of a reference sequence. * @param position Position along the reference sequence. * @param chunkOffset Offset used to iterate through successive PB chunks. * @return the largest position in byte in the entries file that occur before the location (targetIndex, position) or * Long.MIN_VALUE if the offset cannot be determined (e.g., alignment is empty). */ protected long getByteOffset(final int targetIndex, final int position, final int chunkOffset) { if (targetIndex >= targetPositionOffsets.length) return Long.MAX_VALUE; final long absolutePosition = recodePosition(targetIndex, position); int offsetIndex = Arrays.binarySearch(indexAbsolutePositions.elements(), absolutePosition); offsetIndex = offsetIndex < 0 ? -1 - offsetIndex : offsetIndex; offsetIndex = offsetIndex >= indexOffsets.size() ? indexOffsets.size() - 1 : offsetIndex - 1; if (offsetIndex + chunkOffset < 0) { // empty alignment. return Long.MIN_VALUE; } if (offsetIndex + chunkOffset < indexOffsets.size()) { final long byteOffset = indexOffsets.getLong(offsetIndex + chunkOffset); return byteOffset; } else { // return an end-offset past the beginning of the last chunk: return indexOffsets.getLong(offsetIndex) + 10; } }
From source file:com.android.messaging.datamodel.BugleNotifications.java
private static void updateBuilderAudioVibrate(final NotificationState state, final NotificationCompat.Builder notifBuilder, final boolean silent, final Uri ringtoneUri, final String conversationId) { int defaults = Notification.DEFAULT_LIGHTS; if (!silent) { final BuglePrefs prefs = Factory.get().getApplicationPrefs(); final long latestNotificationTimestamp = prefs .getLong(BuglePrefsKeys.LATEST_NOTIFICATION_MESSAGE_TIMESTAMP, Long.MIN_VALUE); final long latestReceivedTimestamp = state.getLatestReceivedTimestamp(); prefs.putLong(BuglePrefsKeys.LATEST_NOTIFICATION_MESSAGE_TIMESTAMP, Math.max(latestNotificationTimestamp, latestReceivedTimestamp)); if (latestReceivedTimestamp > latestNotificationTimestamp) { synchronized (mLock) { // Find out the last time we dinged for this conversation Long lastTime = sLastMessageDingTime.get(conversationId); if (sTimeBetweenDingsMs == 0) { sTimeBetweenDingsMs = BugleGservices.get().getInt( BugleGservicesKeys.NOTIFICATION_TIME_BETWEEN_RINGS_SECONDS, BugleGservicesKeys.NOTIFICATION_TIME_BETWEEN_RINGS_SECONDS_DEFAULT) * 1000; }//from ww w .j a va2 s . c o m if (lastTime == null || SystemClock.elapsedRealtime() - lastTime > sTimeBetweenDingsMs) { sLastMessageDingTime.put(conversationId, SystemClock.elapsedRealtime()); notifBuilder.setSound(ringtoneUri); if (shouldVibrate(state)) { defaults |= Notification.DEFAULT_VIBRATE; } } } } } notifBuilder.setDefaults(defaults); }
From source file:com.ferdi2005.secondgram.support.widget.helper.ItemTouchHelper.java
/** * If user drags the view to the edge, trigger a scroll if necessary. *//*from w w w . j a v a 2 s.co m*/ boolean scrollIfNecessary() { if (mSelected == null) { mDragScrollStartTimeInMs = Long.MIN_VALUE; return false; } final long now = System.currentTimeMillis(); final long scrollDuration = mDragScrollStartTimeInMs == Long.MIN_VALUE ? 0 : now - mDragScrollStartTimeInMs; RecyclerView.LayoutManager lm = mRecyclerView.getLayoutManager(); if (mTmpRect == null) { mTmpRect = new Rect(); } int scrollX = 0; int scrollY = 0; lm.calculateItemDecorationsForChild(mSelected.itemView, mTmpRect); if (lm.canScrollHorizontally()) { int curX = (int) (mSelectedStartX + mDx); final int leftDiff = curX - mTmpRect.left - mRecyclerView.getPaddingLeft(); if (mDx < 0 && leftDiff < 0) { scrollX = leftDiff; } else if (mDx > 0) { final int rightDiff = curX + mSelected.itemView.getWidth() + mTmpRect.right - (mRecyclerView.getWidth() - mRecyclerView.getPaddingRight()); if (rightDiff > 0) { scrollX = rightDiff; } } } if (lm.canScrollVertically()) { int curY = (int) (mSelectedStartY + mDy); final int topDiff = curY - mTmpRect.top - mRecyclerView.getPaddingTop(); if (mDy < 0 && topDiff < 0) { scrollY = topDiff; } else if (mDy > 0) { final int bottomDiff = curY + mSelected.itemView.getHeight() + mTmpRect.bottom - (mRecyclerView.getHeight() - mRecyclerView.getPaddingBottom()); if (bottomDiff > 0) { scrollY = bottomDiff; } } } if (scrollX != 0) { scrollX = mCallback.interpolateOutOfBoundsScroll(mRecyclerView, mSelected.itemView.getWidth(), scrollX, mRecyclerView.getWidth(), scrollDuration); } if (scrollY != 0) { scrollY = mCallback.interpolateOutOfBoundsScroll(mRecyclerView, mSelected.itemView.getHeight(), scrollY, mRecyclerView.getHeight(), scrollDuration); } if (scrollX != 0 || scrollY != 0) { if (mDragScrollStartTimeInMs == Long.MIN_VALUE) { mDragScrollStartTimeInMs = now; } mRecyclerView.scrollBy(scrollX, scrollY); return true; } mDragScrollStartTimeInMs = Long.MIN_VALUE; return false; }