001    /*
002     * Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
003     *
004     * This software is the confidential and proprietary information of
005     * ChemAxon. You shall not disclose such Confidential Information
006     * and shall use it only in accordance with the terms of the agreements
007     * you entered into with ChemAxon.
008     *
009     */
010    
011    package com.chemaxon.overlap.unguarded;
012    
013    import com.chemaxon.descriptors.common.BinaryVectorDescriptor;
014    import com.google.common.base.Function;
015    import java.io.Serializable;
016    
017    /**
018     * Extract <code>long []</code> fp from a {@link BinaryVectorDescriptor}.
019     *
020     * <p>Note that this implementation might return the internal representation of the descriptor!</p>
021     *
022     * <p>Mapping between <code>int</code> and <code>long</code> representations: First 32 bit int is mapped to the
023     * upper 32 bits of the 64 bit long; while second 32 bit int to the lower part of the 64 bit long.</p>
024     *
025     * @author Gabor Imre
026     */
027    public class ExtractLongFp implements Function<BinaryVectorDescriptor, long[]>, Serializable {
028    
029        /**
030         * Serial version.
031         */
032        private static final long serialVersionUID = 0;
033    
034        @Override
035        public long[] apply(BinaryVectorDescriptor input) {
036            final int [] ifp = input.getFP();
037            if (ifp.length % 2 != 0) {
038                throw new IllegalArgumentException("Invalid fp length " + ifp.length);
039            }
040            final long [] ret = new long[ifp.length / 2];
041            for (int i = 0; i < ret.length; i++) {
042                ret[i] = ((long) ifp[2 * i] << Integer.SIZE) | ((long) ifp[2 * i + 1] & 0xFFFFFFFFL);
043            }
044            return ret;
045        }
046    
047        @Override
048        public String toString() {
049            return "Extract long [] fingerprint representation from BinaryVectorDescriptor";
050        }
051    
052    }