Java tutorial
/*---------------- FILE HEADER KALYPSO ------------------------------------------ * * This file is part of kalypso. * Copyright (C) 2004 by: * * Technical University Hamburg-Harburg (TUHH) * Institute of River and coastal engineering * Denickestrae 22 * 21073 Hamburg, Germany * http://www.tuhh.de/wb * * and * * Bjoernsen Consulting Engineers (BCE) * Maria Trost 3 * 56070 Koblenz, Germany * http://www.bjoernsen.de * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact: * * E-Mail: * belger@bjoernsen.de * schlienger@bjoernsen.de * v.doemming@tuhh.de * * ---------------------------------------------------------------------------*/ package de.openali.odysseus.chart.factory.util; import java.util.ArrayList; import java.util.List; import jregex.Pattern; import jregex.RETokenizer; import org.apache.commons.lang3.StringUtils; import de.openali.odysseus.chart.framework.model.mapper.IAxis; import de.openali.odysseus.chart.framework.model.mapper.registry.IAxisRegistry; import de.openali.odysseus.chartconfig.x020.AxisDateRangeType; import de.openali.odysseus.chartconfig.x020.AxisDurationRangeType; import de.openali.odysseus.chartconfig.x020.AxisNumberRangeType; import de.openali.odysseus.chartconfig.x020.AxisStringRangeType; import de.openali.odysseus.chartconfig.x020.AxisType; import de.openali.odysseus.chartconfig.x020.ReferencingType; /** * @author Dirk Kuch */ public final class AxisUtils { private AxisUtils() { } /** * @return axis id from referencing type */ public static String getIdentifier(final ReferencingType type) { if (type == null) { return null; } final String ref = type.getRef(); if (StringUtils.isNotEmpty(ref)) return ref; final String url = type.getUrl(); final RETokenizer tokenizer = new RETokenizer(new Pattern(".*#"), url); //$NON-NLS-1$ return StringUtils.chomp(tokenizer.nextToken()); } /** * Searches all axes that are configured for autoscaling. */ public static IAxis[] findAutoscaleAxes(final AxisType[] axes, final IAxisRegistry mapperRegistry) { final List<IAxis> autoscaledAxes = new ArrayList<>(); for (final AxisType axisType : axes) { Object min = null; Object max = null; if (axisType.isSetDateRange()) { final AxisDateRangeType range = axisType.getDateRange(); min = range.getMinValue(); max = range.getMaxValue(); } else if (axisType.isSetDurationRange()) { final AxisDurationRangeType range = axisType.getDurationRange(); min = range.getMinValue(); max = range.getMaxValue(); } else if (axisType.isSetStringRange()) { final AxisStringRangeType range = axisType.getStringRange(); min = range.getMinValue(); max = range.getMaxValue(); } else if (axisType.isSetNumberRange()) { final AxisNumberRangeType range = axisType.getNumberRange(); min = range.getMinValue(); max = range.getMaxValue(); if (Double.isNaN((Double) min)) min = null; if (Double.isNaN((Double) max)) max = null; } if (min == null || max == null) autoscaledAxes.add(mapperRegistry.getAxis(axisType.getId())); } return autoscaledAxes.toArray(new IAxis[autoscaledAxes.size()]); } }