List of usage examples for org.apache.commons.lang ArrayUtils toObject
public static Boolean[] toObject(boolean[] array)
Converts an array of primitive booleans to objects.
From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.sav.SAVFileReader.java
private String getUNF(Object[] varData, String[] dateFormats, int variableType, String unfVersionNumber, int variablePosition) throws NumberFormatException, UnfException, IOException, NoSuchAlgorithmException { String unfValue = null;//from w w w .j ava 2s. c om dbgLog.fine("variableType=" + variableType); dbgLog.finer("unfVersionNumber=" + unfVersionNumber); dbgLog.fine("variablePosition=" + variablePosition); dbgLog.fine("variableName=" + variableNameList.get(variablePosition)); dbgLog.fine("varData:\n" + Arrays.deepToString(varData)); switch (variableType) { case 0: // Integer case // note: due to DecimalFormat class is used to // remove an unnecessary decimal point and 0-padding // numeric (double) data are now String objects dbgLog.fine("Integer case"); // Convert array of Strings to array of Longs Long[] ldata = new Long[varData.length]; for (int i = 0; i < varData.length; i++) { if (varData[i] != null) { ldata[i] = new Long((String) varData[i]); } } unfValue = UNF5Util.calculateUNF(ldata); dbgLog.finer("integer:unfValue=" + unfValue); dbgLog.info("sumstat:long case=" + Arrays.deepToString(ArrayUtils.toObject(StatHelper.calculateSummaryStatistics(ldata)))); dbgLog.info("sumstat:long case=" + Arrays.deepToString(ArrayUtils.toObject(StatHelper.calculateSummaryStatistics(ldata)))); smd.getSummaryStatisticsTable().put(variablePosition, ArrayUtils.toObject(StatHelper.calculateSummaryStatistics(ldata))); Map<String, Integer> catStat = StatHelper.calculateCategoryStatistics(ldata); smd.getCategoryStatisticsTable().put(variableNameList.get(variablePosition), catStat); break; case 1: // type "double": // The actual Double values have been converted to strings with // DecimalFormat; so we'll need to convert them back to a // vector of Doubles for calculating the UNFs and the statistics: dbgLog.finer("double case"); Double[] ddata = new Double[varData.length]; for (int i = 0; i < varData.length; i++) { if (varData[i] != null) { ddata[i] = new Double((String) varData[i]); } } unfValue = UNF5Util.calculateUNF(ddata); dbgLog.finer("double:unfValue=" + unfValue); // Summary stats. // IMPORTANT: up until version 3.6 we used to automatically // assume that values of type Double were necessarily continuous, // and calculate Distribution Sample statistics for them. // However, it is entirely possible to have categorical data // with Double values (use case reported by Odum; support ticket // RT #160712, redmine #3175). So, depending on which one it is, // we are now calling either ContDistSample or SummaryStatistics/CategoryStatistics // from StatHelper. boolean isCategoricalVariable = false; if (smd.getValueLabelTable() .containsKey(smd.getValueLabelMappingTable().get(variableNameList.get(variablePosition)))) { isCategoricalVariable = true; } if (isCategoricalVariable) { // We calculate summary statistics on the values, the same // way we calculate it for integers: smd.getSummaryStatisticsTable().put(variablePosition, ArrayUtils.toObject(StatHelper.calculateSummaryStatistics(ddata))); // However, in order to calculate category statistics, we'll // use the values formatted as strings with DecimalFormat. // This is important - because that's how the defined category // values have been formatted. So we don't want a Double 1.0 // in the data vector to be counted as different from the // category value defined as "1"! String[] strdata = Arrays.asList(varData).toArray(new String[varData.length]); Map<String, Integer> doubleCatStat = StatHelper.calculateCategoryStatistics(strdata); smd.getCategoryStatisticsTable().put(variableNameList.get(variablePosition), doubleCatStat); // TODO: add .info logging. } else { smd.getSummaryStatisticsTable().put(variablePosition, ArrayUtils.toObject(StatHelper.calculateSummaryStatisticsContDistSample(ddata))); dbgLog.info("sumstat:long case=" + Arrays.deepToString( ArrayUtils.toObject(StatHelper.calculateSummaryStatisticsContDistSample(ddata)))); } break; case -1: // String case dbgLog.finer("string case"); String[] strdata = Arrays.asList(varData).toArray(new String[varData.length]); dbgLog.finer("string array passed to calculateUNF: " + Arrays.deepToString(strdata)); unfValue = UNF5Util.calculateUNF(strdata, dateFormats); dbgLog.finer("string:unfValue=" + unfValue); smd.getSummaryStatisticsTable().put(variablePosition, StatHelper.calculateSummaryStatistics(strdata)); Map<String, Integer> strCatStat = StatHelper.calculateCategoryStatistics(strdata); //out.println("catStat="+StrCatStat); smd.getCategoryStatisticsTable().put(variableNameList.get(variablePosition), strCatStat); break; default: dbgLog.fine("unknown variable type found"); String errorMessage = "unknow variable Type found at varData section"; throw new IllegalArgumentException(errorMessage); } // switch dbgLog.fine("unfvalue(last)=" + unfValue); dbgLog.info("[SAV] UNF = " + unfValue); return unfValue; }
From source file:nu.yona.server.analysis.service.ActivityServiceTest.java
@Test public void getUserDayActivityDetail_activityPresent_resultWithActivity() { ZonedDateTime today = getDayStartTime(ZonedDateTime.now(userAnonZone)); ZonedDateTime yesterday = today.minusDays(1); LocalTime activityStartTimeOnDay = LocalTime.parse("20:14:57"); LocalTime activityEndTimeOnDay = LocalTime.parse("20:21:00"); int hour = 20; int[] expectedSpread = getEmptySpread(); expectedSpread[hour * 4] = 1;/*from ww w. j ava 2 s .c o m*/ expectedSpread[hour * 4 + 1] = 6; // gambling goal was created 2 weeks ago, see above // mock some activity on yesterday DayActivity yesterdayRecordedActivity = DayActivity.createInstance(userAnonEntity, gamblingGoal, userAnonZone, yesterday.toLocalDate()); ZonedDateTime activityStartTime = yesterday.withHour(activityStartTimeOnDay.getHour()) .withMinute(activityStartTimeOnDay.getMinute()).withSecond(activityStartTimeOnDay.getSecond()); ZonedDateTime activityEndTime = yesterday.withHour(activityEndTimeOnDay.getHour()) .withMinute(activityEndTimeOnDay.getMinute()).withSecond(activityEndTimeOnDay.getSecond()); Activity recordedActivity = Activity.createInstance(userAnonZone, activityStartTime.toLocalDateTime(), activityEndTime.toLocalDateTime(), Optional.empty()); yesterdayRecordedActivity.addActivity(recordedActivity); when(mockDayActivityRepository.findOne(userAnonId, yesterday.toLocalDate(), gamblingGoal.getId())) .thenReturn(yesterdayRecordedActivity); DayActivityDto activityDay = service.getUserDayActivityDetail(userId, yesterday.toLocalDate(), gamblingGoal.getId()); verify(mockDayActivityRepository, times(1)).findOne(userAnonId, yesterday.toLocalDate(), gamblingGoal.getId()); assertThat(activityDay.getSpread(), equalTo(Arrays.asList(ArrayUtils.toObject((expectedSpread))))); }
From source file:org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior.java
@SuppressWarnings({ "unchecked", "rawtypes" }) protected void handleAssignments(TaskEntity task, ActivityExecution execution) { // to send SO notification we need to extract workflow context, get // users to send to.. Map<String, Object> workflowContext = ActivitiUtil.getRuntimeService().getVariables(execution.getId()); _log.debug("User task for companyId = " + (String) workflowContext.get("companyId")); long companyId = Long.valueOf((String) workflowContext.get("companyId")); if (taskDefinition.getAssigneeExpression() != null) { String userId = (String) taskDefinition.getAssigneeExpression().getValue(execution); task.setAssignee(userId);/*w w w. ja v a2s . c om*/ try { List<Long> receiverUserIds = new ArrayList<Long>(); receiverUserIds.add(Long.valueOf(userId)); sendPortalNotification(task, receiverUserIds, workflowContext, false); } catch (ChannelException e) { _log.error("Could not send portal notification to user", e); } } if (!taskDefinition.getCandidateGroupIdExpressions().isEmpty()) { List<User> users = new ArrayList<User>(); for (Expression groupIdExpr : taskDefinition.getCandidateGroupIdExpressions()) { Object value = groupIdExpr.getValue(execution); if (value instanceof String) { List<String> candiates = extractCandidates((String) value); task.addCandidateGroups(candiates); users.addAll(resolveUsersForGroups(companyId, candiates)); } else if (value instanceof Collection) { task.addCandidateGroups((Collection) value); users.addAll(resolveUsersForGroups(companyId, (Collection) value)); } else { throw new ActivitiIllegalArgumentException( "Expression did not resolve to a string or collection of strings"); } } try { long[] pooledActorsIds = WorkflowTaskManagerUtil.getPooledActorsIds(companyId, Long.valueOf(task.getId())); List<Long> receiverUserIds = null; if (pooledActorsIds == null || pooledActorsIds.length == 0) { //try to use users list receiverUserIds = new ArrayList<Long>(users.size()); for (User user : users) { receiverUserIds.add(Long.valueOf(user.getId())); } } else { receiverUserIds = new ArrayList<Long>(Arrays.asList(ArrayUtils.toObject(pooledActorsIds))); } try { sendPortalNotification(task, receiverUserIds, workflowContext, true); } catch (ChannelException e) { _log.error("Could not send portal notification to group", e); } } catch (Exception e) { _log.error("Could not send portal notification to group", e); } } if (!taskDefinition.getCandidateUserIdExpressions().isEmpty()) { for (Expression userIdExpr : taskDefinition.getCandidateUserIdExpressions()) { Object value = userIdExpr.getValue(execution); if (value instanceof String) { List<String> candiates = extractCandidates((String) value); task.addCandidateUsers(candiates); } else if (value instanceof Collection) { task.addCandidateUsers((Collection) value); } else { throw new ActivitiException("Expression did not resolve to a string or collection of strings"); } } } }
From source file:org.apache.ambari.server.testing.DeadlockWarningThread.java
@Override public void run() { while (true) { try {/* w w w .ja v a2s.c o m*/ Thread.sleep(3000); } catch (InterruptedException ex) { } long[] ids = mbean.findMonitorDeadlockedThreads(); StringBuilder errBuilder = new StringBuilder(); if (ids != null && ids.length > 0) { errBuilder.append(getThreadsStacktraces(Arrays.asList(ArrayUtils.toObject(ids)))); errorMessages.add(errBuilder.toString()); System.out.append(errBuilder.toString()); //Exit if deadlocks have been found deadlocked = true; break; } else { //Exit if all monitored threads were finished boolean hasLive = false; boolean hasRunning = false; for (Thread monTh : monitoredThreads) { State state = monTh.getState(); if (state != State.TERMINATED && state != State.NEW) { hasLive = true; } if (state == State.RUNNABLE || state == State.TIMED_WAITING) { hasRunning = true; break; } } if (!hasLive) { deadlocked = false; break; } else if (!hasRunning) { List<Long> tIds = new ArrayList<Long>(); for (Thread monitoredThread : monitoredThreads) { State state = monitoredThread.getState(); if (state == State.WAITING || state == State.BLOCKED) { tIds.add(monitoredThread.getId()); } } errBuilder.append(getThreadsStacktraces(tIds)); errorMessages.add(errBuilder.toString()); deadlocked = true; break; } } } }
From source file:org.apache.carbondata.core.reader.sortindex.CarbonDictionarySortIndexReaderImplTest.java
/** * Test to read the data from dictionary sort index file * * @throws Exception/*w ww . j ava2 s . com*/ */ @Test public void read() throws Exception { deleteStorePath(); CarbonTableIdentifier carbonTableIdentifier = new CarbonTableIdentifier("testSchema", "carbon", UUID.randomUUID().toString()); ColumnIdentifier columnIdentifier = new ColumnIdentifier("Name", null, null); CarbonDictionaryWriter dictionaryWriter = new CarbonDictionaryWriterImpl(storePath, carbonTableIdentifier, columnIdentifier); String metaFolderPath = storePath + File.separator + carbonTableIdentifier.getDatabaseName() + File.separator + carbonTableIdentifier.getTableName() + File.separator + "Metadata"; CarbonUtil.checkAndCreateFolder(metaFolderPath); CarbonDictionarySortIndexWriter dictionarySortIndexWriter = new CarbonDictionarySortIndexWriterImpl( carbonTableIdentifier, columnIdentifier, storePath); List<int[]> expectedData = prepareExpectedData(); int[] data = expectedData.get(0); for (int i = 0; i < data.length; i++) { dictionaryWriter.write(String.valueOf(data[i])); } dictionaryWriter.close(); dictionaryWriter.commit(); List<Integer> sortIndex = Arrays.asList(ArrayUtils.toObject(expectedData.get(0))); List<Integer> invertedSortIndex = Arrays.asList(ArrayUtils.toObject(expectedData.get(1))); dictionarySortIndexWriter.writeSortIndex(sortIndex); dictionarySortIndexWriter.writeInvertedSortIndex(invertedSortIndex); dictionarySortIndexWriter.close(); CarbonDictionarySortIndexReader dictionarySortIndexReader = new CarbonDictionarySortIndexReaderImpl( carbonTableIdentifier, columnIdentifier, storePath); List<Integer> actualSortIndex = dictionarySortIndexReader.readSortIndex(); List<Integer> actualInvertedSortIndex = dictionarySortIndexReader.readInvertedSortIndex(); for (int i = 0; i < actualSortIndex.size(); i++) { Assert.assertEquals(sortIndex.get(i), actualSortIndex.get(i)); Assert.assertEquals(invertedSortIndex.get(i), actualInvertedSortIndex.get(i)); } }
From source file:org.apache.carbondata.core.writer.sortindex.CarbonDictionarySortIndexWriterImplTest.java
/** * s/*from w w w.j ava 2 s.com*/ * Method to test the write of sortIndex file. * * @throws Exception */ @Test public void write() throws Exception { String metaFolderPath = storePath + File.separator + carbonTableIdentifier.getDatabaseName() + File.separator + carbonTableIdentifier.getTableName() + File.separator + "Metadata"; CarbonUtil.checkAndCreateFolder(metaFolderPath); List<int[]> indexList = prepareExpectedData(); int[] data = indexList.get(0); for (int i = 0; i < data.length; i++) { dictionaryWriter.write(String.valueOf(data[i])); } dictionaryWriter.close(); dictionaryWriter.commit(); List<Integer> sortIndex = Arrays.asList(ArrayUtils.toObject(indexList.get(0))); List<Integer> invertedSortIndex = Arrays.asList(ArrayUtils.toObject(indexList.get(1))); dictionarySortIndexWriter.writeSortIndex(sortIndex); dictionarySortIndexWriter.writeInvertedSortIndex(invertedSortIndex); dictionarySortIndexWriter.close(); List<Integer> actualSortIndex = carbonDictionarySortIndexReader.readSortIndex(); List<Integer> actualInvertedSortIndex = carbonDictionarySortIndexReader.readInvertedSortIndex(); for (int i = 0; i < actualSortIndex.size(); i++) { assertEquals(sortIndex.get(i), actualSortIndex.get(i)); assertEquals(invertedSortIndex.get(i), actualInvertedSortIndex.get(i)); } }
From source file:org.apache.carbondata.core.writer.sortindex.CarbonDictionarySortInfoPreparator.java
/** * The method converts the int[] to List<Integer> * * @param data/*from w ww . jav a 2 s .c o m*/ * @return */ private List<Integer> convertToList(int[] data) { Integer[] wrapperType = ArrayUtils.toObject(data); return Arrays.asList(wrapperType); }
From source file:org.apache.flink.graph.asm.dataset.ChecksumHashCodeTest.java
@Test public void testChecksumHashCode() throws Exception { List<Long> list = Arrays.asList(ArrayUtils.toObject(new long[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 })); DataSet<Long> dataset = env.fromCollection(list); Checksum checksum = new ChecksumHashCode<Long>().run(dataset).execute(); assertEquals(list.size(), checksum.getCount()); assertEquals(list.size() * (list.size() - 1) / 2, checksum.getChecksum()); }
From source file:org.apache.flink.graph.asm.dataset.CollectTest.java
@Test public void testCollect() throws Exception { List<Long> list = Arrays.asList(ArrayUtils.toObject(new long[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 })); DataSet<Long> dataset = env.fromCollection(list); List<Long> collected = new Collect<Long>().run(dataset).execute(); assertArrayEquals(list.toArray(), collected.toArray()); }
From source file:org.apache.flink.graph.asm.dataset.CountTest.java
@Test public void testCount() throws Exception { List<Long> list = Arrays.asList(ArrayUtils.toObject(new long[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 })); DataSet<Long> dataset = env.fromCollection(list); long count = new Count<Long>().run(dataset).execute(); assertEquals(list.size(), count);//from w w w . ja v a 2s . c o m }