Example usage for org.apache.commons.collections CollectionUtils reverseArray

List of usage examples for org.apache.commons.collections CollectionUtils reverseArray

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils reverseArray.

Prototype

public static void reverseArray(Object[] array) 

Source Link

Document

Reverses the order of the given array.

Usage

From source file:be.selckin.ws.util.java2php.NameManager.java

public String getPhpNamespace(QName qname) {
    String nsprefix = nsPrefixMap.get(qname.getNamespaceURI());
    // nsprefix will be null if there is no prefix.
    if (nsprefix == null) {
        nsprefix = defineFallbackPrefix(qname.getNamespaceURI());
    }// w  w  w.java  2s.  c  o  m

    String[] separated = nsprefix.split("\\\\");
    CollectionUtils.reverseArray(separated);
    return StringUtils.join(separated, "\\");
}

From source file:com.xpn.xwiki.stats.impl.xwiki.XWikiStatsReader.java

/**
 * Return the statistics action stored.//from w ww  .ja  v a2 s . c o m
 * 
 * @param action the action.
 * @param size the maximum size of the list to return.
 * @param context the XWiki context.
 * @return the list of recent statistics action stored.
 */
public Collection<Object> getRecentActions(String action, int size, XWikiContext context) {
    List<Object> list = new ArrayList<Object>();

    if ((action.equals(ViewAction.VIEW_ACTION) || (action.equals(SaveAction.ACTION_NAME)))) {
        Collection<?> actions = StatsUtil.getRecentActionFromSessions(context, action);

        if (actions != null) {
            Object[] actionsarray = actions.toArray();
            CollectionUtils.reverseArray(actionsarray);
            int nb = Math.min(actions.size(), size);
            for (int i = 0; i < nb; i++) {
                list.add(actionsarray[i]);
            }
        }
    }

    return list;
}

From source file:br.com.fabiopereira.quebrazip.JavaZipSplitter.java

private static void invertArrayBytes(byte[] bytes) {
    Object[] objs = new Object[bytes.length];
    for (int i = 0; i < bytes.length; i++) {
        objs[i] = Byte.valueOf(bytes[i]);
    }/*from  w  ww .  jav a  2  s .c o  m*/
    CollectionUtils.reverseArray(objs);
    for (int i = 0; i < bytes.length; i++) {
        bytes[i] = (Byte) objs[i];
    }
}

From source file:com.mac.holdempoker.app.impl.util.HandMatrix.java

/**
 * FLUSH/*from w  ww. jav a 2s .c  o m*/
 *
 * @return
 */
private HandRank eHandRank() {
    Entry<Suit, Rank[]> flush = getFlushEntry();
    if (Objects.isNull(flush)) {
        return null;
    }
    Rank[] ranks = flush.getValue();
    Arrays.sort(ranks, rc);
    CollectionUtils.reverseArray(ranks);

    List<Card> cards = new ArrayList();
    for (int i = 0; i < 13; i++) {
        Rank r = ranks[i];
        if (Objects.nonNull(r) && cards.size() < 5) {
            cards.add(makeCard(flush.getKey(), r));
        }
    }
    Collections.sort(cards, this);
    return new SimpleHandRank(HandType.FLUSH, cards.toArray(new Card[5]));
}

From source file:org.apache.geode.geospatial.client.Roads.java

/**
 * Load the roads from a file.  The roads loaded will be added to the set of roads.
 *
 * The loaded will add in a bi-directional path.
 *
 * Assumes the roads will be defined in a KMZ file.
 *
 * @param roadsFileName//w w w  . j  a  v  a 2  s  .  co m
 * @throws IOException
 * @throws ParserConfigurationException
 * @throws SAXException
 */
public void setRoads(String roadsFileName) throws IOException, ParserConfigurationException, SAXException {

    SimpleFeature featureSet = null;
    try (ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(new File(roadsFileName)))) {
        for (ZipEntry zipEntry = zipInputStream.getNextEntry(); zipEntry != null; zipEntry = zipInputStream
                .getNextEntry()) {
            if (zipEntry.getName().toLowerCase().endsWith(".kml")) {
                KMLConfiguration kmlConfiguration = new KMLConfiguration();
                Parser parser = new Parser(kmlConfiguration);
                featureSet = (SimpleFeature) parser.parse(zipInputStream);
                //just one KML feature and we punch out.
                break;
            }
        }
    }
    notNull(featureSet, "Didn't find any features in " + roadsFileName);
    ArrayList<Geometry> geometries = new ArrayList<>();
    findAllGeometries(geometries, featureSet);

    addRoads(geometries);

    ArrayList<Geometry> reverse = new ArrayList<>();

    for (Geometry curr : geometries) {
        Coordinate[] toReverse = Arrays.copyOf(curr.getCoordinates(), curr.getCoordinates().length);
        CollectionUtils.reverseArray(toReverse);
        reverse.add(geometryFactory.createLineString(toReverse));
    }
    addRoads(reverse);

}

From source file:org.broadleafcommerce.common.util.BroadleafMergeResourceBundleMessageSource.java

/**
 * The super implementation ensures the basenames defined at the beginning take precedence. We require the opposite in
 * order to be in line with previous assumptions about the applicationContext merge process (meaning, beans defined in
 * later applicationContexts take precedence). Thus, this reverses <b>basenames</b> before passing it up to the super
 * implementation./*from   www.j av a2 s .c  om*/
 * 
 * @param basenames
 * @param resourceBundleExtensionPoint
 * @see {@link ReloadableResourceBundleMessageSource#setBasenames(String...)}
 */
@Override
public void setBasenames(String... basenames) {
    CollectionUtils.reverseArray(basenames);
    super.setBasenames(basenames);
}

From source file:org.jumpmind.symmetric.io.data.writer.TransformWriter.java

public void write(CsvData data) {
    DataEventType eventType = data.getDataEventType();
    if (activeTransforms != null && activeTransforms.size() > 0 && isTransformable(eventType)) {
        if (data.requiresTable() && sourceTable == null && context.getLastParsedTable() != null) {
            // if we cross batches and the table isn't specified, then
            // use the last table we used
            start(context.getLastParsedTable());
        }/* ww w  . j a va 2 s.c om*/

        long ts = System.currentTimeMillis();
        Map<String, String> sourceValues = data.toColumnNameValuePairs(this.sourceTable.getColumnNames(),
                CsvData.ROW_DATA);

        Map<String, String> oldSourceValues = null;
        if (data.contains(CsvData.OLD_DATA)) {
            oldSourceValues = data.toColumnNameValuePairs(this.sourceTable.getColumnNames(), CsvData.OLD_DATA);
        }

        Map<String, String> sourceKeyValues = null;
        if (data.contains(CsvData.PK_DATA)) {
            sourceKeyValues = data.toKeyColumnValuePairs(this.sourceTable);
        }

        if (eventType == DataEventType.DELETE) {
            sourceValues = oldSourceValues;

            if (sourceValues == null || sourceValues.size() == 0) {
                sourceValues = sourceKeyValues;
            }
        }

        if (log.isDebugEnabled()) {
            log.debug("{} transformation(s) started because of {} on {}.  The original row data was: {}",
                    new Object[] { activeTransforms.size(), eventType.toString(),
                            this.sourceTable.getFullyQualifiedTableName(), sourceValues });
        }

        List<TransformedData> dataThatHasBeenTransformed = new ArrayList<TransformedData>();
        TransformTable[] transformTables = activeTransforms
                .toArray(new TransformTable[activeTransforms.size()]);
        if (eventType == DataEventType.DELETE) {
            CollectionUtils.reverseArray(transformTables);
        }

        for (TransformTable transformation : transformTables) {
            transformation = transformation.enhanceWithImpliedColumns(
                    this.sourceTable.getPrimaryKeyColumnNames(), this.sourceTable.getColumnNames());
            if (eventType == DataEventType.INSERT && transformation.isUpdateFirst()) {
                eventType = DataEventType.UPDATE;
            }
            dataThatHasBeenTransformed.addAll(transform(eventType, context, transformation, sourceKeyValues,
                    oldSourceValues, sourceValues));
        }

        for (TransformedData transformedData : dataThatHasBeenTransformed) {
            Table transformedTable = transformedData.buildTargetTable();
            CsvData csvData = transformedData.buildTargetCsvData();
            long transformTimeInMs = System.currentTimeMillis() - ts;
            boolean processData = true;
            if (lastTransformedTable == null || !lastTransformedTable.equals(transformedTable)) {
                if (lastTransformedTable != null) {
                    this.nestedWriter.end(lastTransformedTable);
                }
                processData = this.nestedWriter.start(transformedTable);
                if (!processData) {
                    lastTransformedTable = null;
                } else {
                    lastTransformedTable = transformedTable;
                }
            }
            if (processData || !csvData.requiresTable()) {
                this.nestedWriter.write(csvData);
            }
            Statistics stats = this.nestedWriter.getStatistics().get(batch);
            if (stats != null) {
                stats.increment(DataWriterStatisticConstants.TRANSFORMMILLIS, transformTimeInMs);
            }
            ts = System.currentTimeMillis();
        }

    } else {
        if (sourceTable != null) {
            super.start(sourceTable);
        }
        super.write(data);
        if (sourceTable != null) {
            super.end(sourceTable);
        }
    }

}

From source file:org.nebularis.defproxy.configuration.ProxyConfigurationBuilder.java

private boolean areParameterTypesCompatible(final MethodSignature interfaceMethod,
        final MethodSignature delegateMethod) {
    if (targetSiteWrappers.containsKey(delegateMethod)) {
        final AdditionalArguments slot = targetSiteWrappers.get(delegateMethod);
        if (slot.insertion.equals(Insertion.Prefix)) {
            if (slot.params.length < delegateMethod.getParameterTypes().length) {
                final Class[] inputTypes = new Class[slot.params.length];
                final List<Class> inputClassList = asList(delegateMethod.getParameterTypes());
                inputClassList.subList(0, inputTypes.length).toArray(inputTypes);
                return isAssignable(inputTypes, ClassUtils.toClass(slot.params));
            }// w  w w.ja v a 2  s.  co m
            return isAssignable(delegateMethod.getParameterTypes(), ClassUtils.toClass(slot.params));
        } else {
            assert (slot.insertion.equals(Insertion.Suffix));
            final Class[] inputTypes = new Class[delegateMethod.getParameterTypes().length];
            final List<Class> inputClassList = asList(delegateMethod.getParameterTypes());
            inputClassList.toArray(inputTypes);
            CollectionUtils.reverseArray(inputTypes);

            final Class[] slotTypes = new Class[slot.params.length];
            final List<Class> slotClassList = asList(ClassUtils.toClass(slot.params));
            slotClassList.toArray(slotTypes);
            CollectionUtils.reverseArray(slotTypes);
            return isAssignable(inputTypes, slotTypes);
        }
    }
    return isAssignable(interfaceMethod.getParameterTypes(), delegateMethod.getParameterTypes());
}

From source file:org.ptg.cep.SQLParserGenerator.java

public String getJoinFireFunction(String s) {
    String temp = "{";
    String joincol = "";
    temp += getTableDependencyTypeCast();
    if (s == null || s.length() < 1) {
        s = "true";
    }//  w w w . ja  v  a  2 s  .  c o m
    temp += "{";
    temp += "prepareForJoin();\n";
    temp += addItemToCollection();
    boolean first = true;
    for (String key : frms.keySet()) {
        ZFromItem f = frms.get(key);
        temp += " java.util.Collection col" + f.getTable() + " = new java.util.ArrayList();\n";
        if (first) {
            first = false;
        } else {
        }
    }
    List<String> keys = new ArrayList<String>();
    keys.addAll(frms.keySet());
    String[] keyarr = keys.toArray(new String[0]);
    CollectionUtils.reverseArray(keys.toArray(keyarr));
    first = true;
    for (String key : keyarr) {
        ZFromItem f = frms.get(key);
        if (first) {
            joincol += "col" + f.getTable();
            first = false;
        } else {
            joincol += "," + "col" + f.getTable();
        }
    }
    temp += getJoinDepTypeCast();
    temp += "fullCartesian(new java.util.Collection[]{" + joincol + "});";
    temp += "}";

    temp += "}";
    return temp;
}

From source file:org.ptg.cep.SQLParserGenerator.java

public String getDeltaJoinFireFunction(String s) {
    String temp = "{";
    String joincol = "";
    temp += getTableDependencyTypeCast();
    if (s == null || s.length() < 1) {
        s = "true";
    }//from ww  w. j ava 2  s.  c om
    temp += "{";
    temp += "prepareForJoin();\n";
    temp += addItemToCollection();
    boolean first = true;
    for (String key : frms.keySet()) {
        ZFromItem f = frms.get(key);
        temp += " java.util.Collection col" + f.getTable() + " = new java.util.ArrayList();\n";
        if (first) {
            first = false;
        } else {
        }
    }
    List<String> keys = new ArrayList<String>();
    keys.addAll(frms.keySet());
    String[] keyarr = keys.toArray(new String[0]);
    CollectionUtils.reverseArray(keys.toArray(keyarr));
    first = true;
    for (String key : keyarr) {
        ZFromItem f = frms.get(key);
        if (first) {
            joincol += "col" + f.getTable();
            first = false;
        } else {
            joincol += "," + "col" + f.getTable();
        }
    }
    temp += getJoinDepTypeCast();
    temp += "deltaCartesian(new java.util.Collection[]{" + joincol + "});";
    temp += "}";

    temp += "}";
    return temp;
}