List of usage examples for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair
public ImmutablePair(final L left, final R right)
From source file:org.amanzi.awe.distribution.engine.impl.internal.AbstractDistributionEngine.java
private List<Pair<IRange, IDistributionBar>> createDistributionBars(final IDistributionModel distributionModel, final IDistributionType<?> type) throws ModelException { final List<Pair<IRange, IDistributionBar>> result = new ArrayList<Pair<IRange, IDistributionBar>>(); for (final IRange range : type.getRanges()) { result.add(new ImmutablePair<IRange, IDistributionBar>(range, distributionModel.createDistributionBar(range))); }//from w ww.j a v a 2 s .c o m return result; }
From source file:org.amanzi.awe.render.core.utils.RenderMenuUtils.java
public static Pair<IRenderableModel, Iterable<IDataElement>> getLocationElements( final IStructuredSelection selection) { IRenderableModel renderableModel = null; boolean incorrect = false; Iterable<IDataElement> elementsIterable = Iterables.emptyIterable(); for (final Object element : selection.toArray()) { if (element instanceof IUIItem) { final IUIItem item = (IUIItem) element; final IRenderableModel itemModel = getRenderableModel(item); // check UI Item is correct if (itemModel == null) { incorrect = true;//from w w w . j a v a 2 s . c om break; } // check model is same for all elements if (renderableModel == null) { renderableModel = itemModel; } else if (!itemModel.equals(renderableModel)) { incorrect = true; break; } // check internal elements final Iterable<IDataElement> subIterable = collectDataElements(item, renderableModel); if (subIterable != null) { elementsIterable = Iterables.concat(elementsIterable, subIterable); } } } // check element locations if (!incorrect && !Iterables.isEmpty(elementsIterable)) { incorrect = Iterables.isEmpty(renderableModel.getElementsLocations(elementsIterable)); } if (!incorrect) { return new ImmutablePair<IRenderableModel, Iterable<IDataElement>>(renderableModel, elementsIterable); } return null; }
From source file:org.amanzi.awe.render.network.NetworkRenderer.java
/** * Get azimuth and beamwidth//from ww w. ja v a 2 s . c om * * @param site * @param sector * @param i * @return */ private Pair<Double, Double> getSectorParameters(final ISectorElement sector, final int i, final int sectorCount) { Double azimuth = sector.getAzimuth(); Double beamwidth = sector.getBeamwidth(); if ((azimuth == null) || (beamwidth == null) || (beamwidth == 0)) { beamwidth = FULL_CIRCLE / (sectorCount == 0 ? 1 : sectorCount); azimuth = beamwidth * i; beamwidth = beamwidth.doubleValue() * 0.8; } return new ImmutablePair<Double, Double>(azimuth, beamwidth); }
From source file:org.amanzi.awe.statistics.engine.StatisticsEngine.java
/** * @param currentStatisticsRow//from ww w . jav a 2 s . c om * @param column * @param previousStatisticsCell * @return */ private IAggregationFunction calculateValue(final IStatisticsRow currentStatisticsRow, final ITemplateColumn column, final IStatisticsCell previousStatisticsCell) { final Pair<IStatisticsRow, ITemplateColumn> key = new ImmutablePair<IStatisticsRow, ITemplateColumn>( currentStatisticsRow, column); IAggregationFunction function = functionCache.get(key); if (function == null) { function = column.getFunction(); functionCache.put(key, function); } if (function instanceof Average) { return ((Average) function).update(previousStatisticsCell.getTotalValue(), previousStatisticsCell.getSize()); } return function.update(previousStatisticsCell.getValue()); }
From source file:org.amanzi.awe.statistics.engine.StatisticsEngine.java
private IAggregationFunction calculateValue(final IStatisticsRow statisticsRow, final ITemplateColumn templateColumn, final Number value) { final Pair<IStatisticsRow, ITemplateColumn> key = new ImmutablePair<IStatisticsRow, ITemplateColumn>( statisticsRow, templateColumn); IAggregationFunction function = functionCache.get(key); if (function == null) { function = templateColumn.getFunction(); functionCache.put(key, function); }//from w w w . j a v a2s. c o m return function.update(value); }
From source file:org.amanzi.awe.statistics.model.impl.StatisticsModel.java
@Override public IStatisticsGroup getStatisticsGroup(final String period, final String propertyKey) throws ModelException { if (LOGGER.isDebugEnabled()) { LOGGER.debug(getStartLogStatement("getGroup", period, propertyKey)); }/*from w w w .j av a2 s.co m*/ // TODO: LN: 15.08.2012, validate input final Pair<String, String> groupKey = new ImmutablePair<String, String>(period, propertyKey); IStatisticsGroup result = statisticsGroupCache.get(groupKey); if (result == null) { result = getGroupFromDatabase(period, propertyKey); statisticsGroupCache.put(groupKey, result); } if (LOGGER.isDebugEnabled()) { LOGGER.debug(getFinishLogStatement("getGroup")); } return result; }
From source file:org.amanzi.awe.statistics.model.impl.StatisticsModel.java
@Override public IStatisticsRow getStatisticsRow(final IStatisticsGroup group, final IStatisticsRow sourceRow, final long startDate, final long endDate) throws ModelException { if (LOGGER.isDebugEnabled()) { LOGGER.debug(getStartLogStatement("getStatisticsRow", group, sourceRow, startDate, endDate)); }//from www . j ava 2 s . c om // TODO: LN: 15.08.2012, validate input final Pair<String, Long> key = new ImmutablePair<String, Long>(group.getName(), startDate); IStatisticsRow result = statisticsRowCache.get(key); if (result == null) { result = getStatisticsRowFromDatabase((StatisticsGroup) group, sourceRow, startDate, endDate); statisticsRowCache.put(key, result); } if (sourceRow != null) { try { statisticsService.addSourceNode(((StatisticsRow) result).getNode(), ((DataElement) sourceRow).getNode()); } catch (final ServiceException e) { processException("Can't add source to row " + sourceRow, e); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug(getFinishLogStatement("getStatisticsRow")); } return result; }
From source file:org.amanzi.awe.statistics.model.impl.StatisticsModel.java
protected Node findStatisticsCellNode(final StatisticsRow statisticsRow, final String name) throws ModelException { if (LOGGER.isDebugEnabled()) { LOGGER.debug(getStartLogStatement("getStatisticsCellNode", statisticsRow, name)); }//from ww w.j a v a2 s . c om final Pair<StatisticsRow, String> key = new ImmutablePair<StatisticsRow, String>(statisticsRow, name); Node result = statisticsCellNodeCache.get(key); if (result == null) { result = getStatisticsCellNodeFromDatabase(statisticsRow, name); } if (LOGGER.isDebugEnabled()) { LOGGER.debug(getFinishLogStatement("getStatisticsCellNode")); } return result; }
From source file:org.amanzi.awe.ui.tree.provider.AWETreeContentProvider.java
private Pair<ITreeWrapper, ITreeItem> convertObject(final Object element) { Pair<ITreeWrapper, ITreeItem> result = null; if (element instanceof ITreeItem) { final ITreeItem item = (ITreeItem) element; final ITreeWrapper wrapper = item.getWrapper(); result = new ImmutablePair<ITreeWrapper, ITreeItem>(wrapper, item); }/*from ww w . j av a2 s . co m*/ return result; }
From source file:org.amanzi.neo.loader.core.synonyms.SynonymsManager.java
protected Pair<INodeType, Synonyms> parseSynonyms(final Entry<Object, Object> propertyEntry) { // convert to string String keyPart = propertyEntry.getKey().toString(); String valuePart = propertyEntry.getValue().toString(); // get headers String[] headers = valuePart.split(HEADERS_SEPARATOR); // get subtype, property and class Matcher matcher = SYNONYM_KEY_PATTERN.matcher(keyPart); if (matcher.matches()) { String nodeTypeLine = matcher.group(NODETYPE_GROUP_INDEX); String propertyName = matcher.group(PROPERTY_GROUP_INDEX); String clazz = matcher.group(CLASS_GROUP_INDEX); String isMandatoryGroup = matcher.group(IS_MANDATORY_GROUP_INDEX); SynonymType synonymsType = clazz == null ? SynonymType.UNKOWN : SynonymType.findByClass(clazz); boolean isMandatory = !StringUtils.isEmpty(isMandatoryGroup); Synonyms synonyms = new Synonyms(propertyName, synonymsType, isMandatory, headers); try {/*from w w w . j a va 2 s .c o m*/ INodeType nodeType = NodeTypeManager.getInstance().getType(nodeTypeLine); return new ImmutablePair<INodeType, Synonyms>(nodeType, synonyms); } catch (Exception e) { LOGGER.error("Error on parsing node type", e); } } LOGGER.error("Synonyms key <" + keyPart + "> doesn't match pattern"); return null; }