List of usage examples for org.apache.lucene.util.automaton Automaton getNumStates
public int getNumStates()
From source file:org.elasticsearch.xpack.core.security.authz.permission.FieldPermissions.java
License:Open Source License
/** Constructor that enables field-level security based on include/exclude rules. Exclude rules * have precedence over include rules. */ FieldPermissions(FieldPermissionsDefinition fieldPermissionsDefinition, Automaton permittedFieldsAutomaton) { if (permittedFieldsAutomaton.isDeterministic() == false && permittedFieldsAutomaton.getNumStates() > 1) { // we only accept deterministic automata so that the CharacterRunAutomaton constructor // directly wraps the provided automaton throw new IllegalArgumentException("Only accepts deterministic automata"); }/*ww w . ja v a 2 s.c o m*/ this.fieldPermissionsDefinition = fieldPermissionsDefinition; this.originalAutomaton = permittedFieldsAutomaton; this.permittedFieldsAutomaton = new CharacterRunAutomaton(permittedFieldsAutomaton); // we cache the result of isTotal since this might be a costly operation this.permittedFieldsAutomatonIsTotal = Operations.isTotal(permittedFieldsAutomaton); long ramBytesUsed = BASE_FIELD_PERM_DEF_BYTES; for (FieldGrantExcludeGroup group : fieldPermissionsDefinition.getFieldGrantExcludeGroups()) { ramBytesUsed += BASE_FIELD_GROUP_BYTES + BASE_HASHSET_ENTRY_SIZE; if (group.getGrantedFields() != null) { ramBytesUsed += RamUsageEstimator.shallowSizeOf(group.getGrantedFields()); } if (group.getExcludedFields() != null) { ramBytesUsed += RamUsageEstimator.shallowSizeOf(group.getExcludedFields()); } } ramBytesUsed += permittedFieldsAutomaton.ramBytesUsed(); ramBytesUsed += runAutomatonRamBytesUsed(permittedFieldsAutomaton); this.ramBytesUsed = ramBytesUsed; }
From source file:org.elasticsearch.xpack.core.security.authz.permission.FieldPermissions.java
License:Open Source License
/** * Return an estimation of the ram bytes used by a {@link CharacterRunAutomaton} * that wraps the given automaton./*ww w . j av a 2s . c om*/ */ private static long runAutomatonRamBytesUsed(Automaton a) { return a.getNumStates() * 5; // wild guess, better than 0 }
From source file:org.getopt.luke.Luke.java
License:Apache License
private void addAutomaton(Object parent, Automaton a) { Object n = create("node"); setString(n, "text", "Automaton: " + a != null ? a.toDot() : "null"); add(parent, n);/* www .j a v a2 s . c om*/ Transition t = new Transition(); for (int state = 0; state < a.getNumStates(); state++) { Object n1 = create("node"); add(n, n1); StringBuilder msg = new StringBuilder(); msg.append(String.valueOf(state)); // initial state if (state == 0) { msg.append(" INITIAL"); } msg.append(a.isAccept(state) ? " [accept]" : " [reject]"); int numTransitions = a.initTransition(state, t); msg.append(", " + numTransitions + " transitions"); setString(n1, "text", msg.toString()); //System.out.println("toDot: state " + state + " has " + numTransitions + " transitions; t.nextTrans=" + t.transitionUpto); for (int i = 0; i < numTransitions; i++) { a.getNextTransition(t); Object n2 = create("node"); add(n1, n2); setString(n2, "text", t.toString()); assert t.max >= t.min; } } }