public static StructureOfIndices getEmpty() { if (EMPTY == null) EMPTY = new StructureOfIndices(); return EMPTY; }
/** * Creates structure of indices, which contains indices only of specified metric type. * * @param type index type * @param count number of indices * @throws IllegalArgumentException if type is non metric */ public static StructureOfIndices create(byte type, int count) { if (count == 0) return getEmpty(); return new StructureOfIndices(type, count); }
/** * Creates structure of indices, which contains indices only of specified type. * * @param type index type * @param count number of indices * @param states indices states */ public static StructureOfIndices create(byte type, int count, boolean... states) { if (count != states.length) throw new IllegalArgumentException(); if (count == 0) return getEmpty(); return new StructureOfIndices(type, count, states); }
/** * Creates structure of indices from specified data about metric indices. * * @param types array of types * @param count array of sizes of indices of specified types * @throws IllegalArgumentException if any type in type is non metric */ public static StructureOfIndices create(final byte[] types, int[] count) { int total = 0; for (int i = 0; i < count.length; ++i) total += count[i]; if (total == 0) return getEmpty(); return new StructureOfIndices(types, count); }
/** * Returns the 'sum' of this and other structures * * @param oth other structure * @return 'sum' of this and other structures */ public StructureOfIndices append(StructureOfIndices oth) { if (size == 0) return oth; if (oth.size == 0) return this; int size = this.size + oth.size; StructureOfIndices r = new StructureOfIndices(size); for (int i = 0; i < IndexType.TYPES_COUNT; ++i) { r.typesCounts[i] = typesCounts[i] + oth.typesCounts[i]; if (states[i] == null) continue; r.states[i] = states[i].append(oth.states[i]); } return r; }
/** * Returns the structure of specified simple indices. * * @param indices simple indices */ public static StructureOfIndices create(SimpleIndices indices) { if (indices.size() == 0) return getEmpty(); return new StructureOfIndices(indices); }
/** * Return the new {@code Structure of Indices } with inverted states of indices * * @return new {@code Structure of Indices } with inverted states of indices */ public StructureOfIndices getInverted() { if (size == 0) return this; StructureOfIndices r = new StructureOfIndices(size); System.arraycopy(typesCounts, 0, r.typesCounts, 0, typesCounts.length); for (int i = r.states.length - 1; i >= 0; --i) { if (states[i] == null) continue; if (states[i] == BitArray.EMPTY) r.states[i] = BitArray.EMPTY; r.states[i] = states[i].clone(); r.states[i].not(); } return r; }
/** * Creates structure of indices from specified data. * * @param allCount array of sizes of indices of all types * @param allStates array of states of indices of all types * @throws IllegalArgumentException {@code allCount.length() != allStates.length()} * @throws IllegalArgumentException if length of {@code allCount} not equal the total number of available types of * inddices. */ public static StructureOfIndices create(int[] allCount, BitArray[] allStates) { int total = 0; for (int i = 0; i < allCount.length; ++i) { if (allStates[i] != null && allCount[i] != allStates[i].size()) throw new IllegalArgumentException("Count differs from states size."); total += allCount[i]; } if (total == 0) return getEmpty(); return new StructureOfIndices(allCount, allStates); }
/** * Returns the 'sum' of N-copies of this * * @param N exponent * @return 'sum' of N-copies of this */ public StructureOfIndices pow(int N) { if (size == 0 || N == 0) return getEmpty(); if (N == 1) return this; int size = N * this.size; StructureOfIndices r = new StructureOfIndices(size); for (int i = 0; i < IndexType.TYPES_COUNT; ++i) { r.typesCounts[i] = N * typesCounts[i]; if (states[i] == null) continue; r.states[i] = states[i].times(N); } return r; }
/** * Subtracts some structure of indices from the right side of current structure. <p/> <p>This operation may fail if * states of other structure differs from current.</p> * * @param other other structure * @return result of subtraction * @throws IllegalArgumentException nonmetric states are different */ public StructureOfIndices subtract(StructureOfIndices other) { int size = this.size - other.size; if (size < 0) throw new IllegalArgumentException(); if (other.size == 0) return this; StructureOfIndices r = new StructureOfIndices(size); for (int i = 0; i < IndexType.TYPES_COUNT; ++i) { if ((r.typesCounts[i] = typesCounts[i] - other.typesCounts[i]) < 0) throw new IllegalArgumentException("Other is larger then this."); if (states[i] == null) continue; if (other.states[i] == null) throw new IllegalArgumentException("Inconsistent structures: " + this + " and " + other); if (!states[i].copyOfRange(states[i].size() - other.states[i].size()).equals(other.states[i])) throw new IllegalArgumentException("Nonmetric states are different"); r.states[i] = states[i].copyOfRange(0, states[i].size() - other.states[i].size()); } if (size == 0) return getEmpty(); return r; }
IndicesSymmetries.create(new StructureOfIndices(data), resultingSymmetries), data);