public static void main(String[] args) { Scanner scanner = new Scanner(System.in); long n = scanner.nextLong(); long m = scanner.nextLong(); Map<Integer, Integer> nmap = primeDivisorAndCounts(n); Map<Integer, Integer> mmap = primeDivisorAndCounts(m); int sameCount = 1; for (Map.Entry<Integer, Integer> entry : nmap.entrySet()) { int divisor = entry.getKey(); int counts = 0; if (mmap.containsKey(divisor)) { int nc = entry.getValue(); int mc = mmap.get(divisor); counts = nc < mc ? nc : mc; } sameCount *= counts + 1; } int nDiviorsCount = 1; for (Map.Entry<Integer, Integer> entry : nmap.entrySet()) { nDiviorsCount *= entry.getValue() + 1; } int mDiviorsCount = 1; for (Map.Entry<Integer, Integer> entry : mmap.entrySet()) { mDiviorsCount *= entry.getValue() + 1; } int maxCount = nDiviorsCount * mDiviorsCount; int maxDivisor = gcd(maxCount, sameCount); System.out.println(maxCount / maxDivisor + " " + sameCount / maxDivisor); }
@NotNull public List<FileNameMatcher> getAssociations(@NotNull T type) { List<FileNameMatcher> result = new ArrayList<FileNameMatcher>(); for (Pair<FileNameMatcher, T> mapping : myMatchingMappings) { if (mapping.getSecond() == type) { result.add(mapping.getFirst()); } } for (Map.Entry<CharSequence, T> entries : myExactFileNameMappings.entrySet()) { if (entries.getValue() == type) { result.add(new ExactFileNameMatcher(entries.getKey().toString())); } } for (Map.Entry<CharSequence, T> entries : myExactFileNameAnyCaseMappings.entrySet()) { if (entries.getValue() == type) { result.add(new ExactFileNameMatcher(entries.getKey().toString(), true)); } } for (Map.Entry<CharSequence, T> entries : myExtensionMappings.entrySet()) { if (entries.getValue() == type) { result.add(new ExtensionFileNameMatcher(entries.getKey().toString())); } } return result; }
private void exportParameters() { synchronized (exported_parameters) { if (!exported_parameters_dirty) { return; } exported_parameters_dirty = false; try { TreeMap<String, String> tm = new TreeMap<String, String>(); Set<String> exported_keys = new HashSet<String>(); for (String[] entry : exported_parameters.values()) { String key = entry[0]; String value = entry[1]; exported_keys.add(key); if (value != null) { tm.put(key, value); } } for (Map.Entry<String, String> entry : imported_parameters.entrySet()) { String key = entry.getKey(); if (!exported_keys.contains(key)) { tm.put(key, entry.getValue()); } } File parent_dir = new File(SystemProperties.getUserPath()); File props = new File(parent_dir, "exported_params.properties"); PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(props), "UTF-8")); try { for (Map.Entry<String, String> entry : tm.entrySet()) { pw.println(entry.getKey() + "=" + entry.getValue()); } } finally { pw.close(); } } catch (Throwable e) { e.printStackTrace(); } } }
public PropertyMap deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { PropertyMap result = new PropertyMap(); Iterator i$; Map.Entry<String, JsonElement> entry; if ((json instanceof JsonObject)) { JsonObject object = (JsonObject) json; for (i$ = object.entrySet().iterator(); i$.hasNext(); ) { entry = (Map.Entry) i$.next(); if ((entry.getValue() instanceof JsonArray)) { for (JsonElement element : (JsonArray) entry.getValue()) { result.put( entry.getKey(), new Property((String) entry.getKey(), element.getAsString())); } } } } else if ((json instanceof JsonArray)) { for (JsonElement element : (JsonArray) json) { if ((element instanceof JsonObject)) { JsonObject object = (JsonObject) element; String name = object.getAsJsonPrimitive("name").getAsString(); String value = object.getAsJsonPrimitive("value").getAsString(); if (object.has("signature")) { result.put( name, new Property(name, value, object.getAsJsonPrimitive("signature").getAsString())); } else { result.put(name, new Property(name, value)); } } } } return result; }
/** * Provides a “diff report” of how the two sets are similar and how they are different, comparing * the entries by some aspect. * * <p>The transformer is used to generate the value to use to compare the entries by. That is, the * entries are not compared by equals by an attribute or characteristic. * * <p>The transformer is expected to produce a unique value for each entry in a single set. * Behaviour is undefined if this condition is not met. * * @param left The set on the “left” side of the comparison. * @param right The set on the “right” side of the comparison. * @param compareBy Provides the value to compare entries from either side by * @param <T> The type of the entry objects * @return A representation of the difference */ public static <T> SetDiff<T> diffSetsBy( Set<? extends T> left, Set<? extends T> right, Transformer<?, T> compareBy) { if (left == null) { throw new NullPointerException("'left' set is null"); } if (right == null) { throw new NullPointerException("'right' set is null"); } SetDiff<T> setDiff = new SetDiff<T>(); Map<Object, T> indexedLeft = collectMap(left, compareBy); Map<Object, T> indexedRight = collectMap(right, compareBy); for (Map.Entry<Object, T> leftEntry : indexedLeft.entrySet()) { T rightValue = indexedRight.remove(leftEntry.getKey()); if (rightValue == null) { setDiff.leftOnly.add(leftEntry.getValue()); } else { Pair<T, T> pair = Pair.of(leftEntry.getValue(), rightValue); setDiff.common.add(pair); } } for (T rightValue : indexedRight.values()) { setDiff.rightOnly.add(rightValue); } return setDiff; }
public boolean equals(Object o) { if (!(o instanceof Map.Entry)) return false; Map.Entry<?, ?> e = (Map.Entry<?, ?>) o; return (key == null ? e.getKey() == null : key.equals(e.getKey())) && (value == null ? e.getValue() == null : value.equals(e.getValue())); }
public List<Events> getEventsByParams() { ConcurrentHashMap<Integer, Events> eventBeforeSearch = AppStorage.INSTANCE.getEventStorageCopy(); ConcurrentHashMap<Integer, Events> eventAfterSearch = new ConcurrentHashMap<Integer, Events>(); if (city != null && city.length() != 0) { for (Map.Entry<Integer, Events> entry : eventBeforeSearch.entrySet()) { if (city.equalsIgnoreCase(entry.getValue().getCity())) eventAfterSearch.put(entry.getKey(), entry.getValue()); } } eventBeforeSearch.clear(); eventBeforeSearch = AppStorage.INSTANCE.getEventStorageCopy(); if (description != null && description.length() > 0 && !description.equals("")) { eventAfterSearch.clear(); for (Map.Entry<Integer, Events> entry : eventBeforeSearch.entrySet()) { if (entry.getValue().getDescription().contains(description)) eventAfterSearch.put(entry.getKey(), entry.getValue()); } } eventBeforeSearch = new ConcurrentHashMap<Integer, Events>(eventAfterSearch); /* if(date != null){ for(Map.Entry<Integer,Events> entry : eventBeforeSearch.entrySet()){ GregorianCalendar eventDate = entry.getValue().getDate(); GregorianCalendar before = new GregorianCalendar(eventDate.get(1),eventDate.get(2),eventDate.get(4)+1); GregorianCalendar after = new GregorianCalendar(eventDate.get(1),eventDate.get(2),eventDate.get(4)); if(date.after(after) && date.before(before)) eventAfterSearch.put(entry.getKey(),entry.getValue()); } } */ return new ArrayList<Events>(eventAfterSearch.values()); }
/** * This method is going to get the first optionSetId number for the last gouop of produtcs and * accessories records * * @param inputDto * @param endTemplateStartPage * @return */ private static int getLastFirstOptionSetId( LoadEndTemplatePatternInputDto inputDto, String endTemplateStartPage) { Integer firstEndProdAccOptionSetId = Integer.valueOf(0); for (Map.Entry<String, NavigationPointerDto> entry : inputDto.getMapProdAccRows().entrySet()) { String[] arrayNextPage = entry.getValue().getNextPage().split("\\."); if (arrayNextPage != null && arrayNextPage.length > 0 && arrayNextPage[0].equals(endTemplateStartPage)) { firstEndProdAccOptionSetId = Integer.valueOf(entry.getValue().getPageOptionSetID()); break; } } return firstEndProdAccOptionSetId; /* for (Map.Entry<String, OptionSetIdNumber> optionIdIterEntry : inputDto.getMapOptionSetIdNumber().entrySet()) { OptionSetIdNumber optionIdDto = optionIdIterEntry.getValue(); if(optionIdDto != null && optionIdDto.isFirstEndTemplateRow()) { firstEndProdAccOptionSetId = optionIdDto.getOptionSetId(); } } return firstEndProdAccOptionSetId; */ }
private static InputStream generateSoundsJSON() throws IOException { OpenSecurity.logger.info( Minecraft.getMinecraft().mcDataDir + "\\mods\\OpenSecurity\\sounds\\alarms\\"); JsonObject root = new JsonObject(); for (Map.Entry<String, String> entry : sound_map.entrySet()) { JsonObject event = new JsonObject(); event.addProperty("category", "master"); // put under the "record" category for sound options JsonArray sounds = new JsonArray(); // array of sounds (will only ever be one) JsonObject sound = new JsonObject(); // sound object (instead of primitive to use 'stream' flag) sound.addProperty( "name", new File(".") + "\\mods\\OpenSecurity\\sounds\\alarms\\" + entry.getValue().substring(0, entry.getValue().lastIndexOf('.'))); // path to file sound.addProperty("stream", false); // prevents lag for large files sounds.add(sound); event.add("sounds", sounds); root.add( entry.getValue().substring(0, entry.getValue().lastIndexOf('.')), event); // event name (same as name sent to ItemCustomRecord) } // System.out.println(new Gson().toJson(root)); return new ByteArrayInputStream(new Gson().toJson(root).getBytes()); }
private void addTagsToProperties(MethodInfo mi, JSONObject propJ) throws JSONException { // create description object. description tag enables the visual tools to display description of // keys/values // of a map property, items of a list, properties within a complex type. JSONObject descriptionObj = new JSONObject(); if (mi.comment != null) { descriptionObj.put("$", mi.comment); } for (Map.Entry<String, String> descEntry : mi.descriptions.entrySet()) { descriptionObj.put(descEntry.getKey(), descEntry.getValue()); } if (descriptionObj.length() > 0) { propJ.put("descriptions", descriptionObj); } // create useSchema object. useSchema tag is added to enable visual tools to be able to render a // text field // as a dropdown with choices populated from the schema attached to the port. JSONObject useSchemaObj = new JSONObject(); for (Map.Entry<String, String> useSchemaEntry : mi.useSchemas.entrySet()) { useSchemaObj.put(useSchemaEntry.getKey(), useSchemaEntry.getValue()); } if (useSchemaObj.length() > 0) { propJ.put("useSchema", useSchemaObj); } }
public void prepare() { int i = 0; for (Map<String, Object> data : trainParser.getData()) { for (StimuliChooser chooser : stimuliChoosers) { chooser.feed(data); } System.out.println("PHASE 1 " + i++); } i = 0; for (Map<String, Object> data : trainParser.getData()) { for (StimuliChooser chooser : stimuliChoosers) { chooser.reFeed(data); } System.out.println("PHASE 2 " + i++); } for (StimuliChooser chooser : stimuliChoosers) { stimuliScores.put(chooser.getScore(), chooser); } for (Map.Entry<Double, StimuliChooser> e : stimuliScores.entrySet()) { String id = e.getValue().getTarget() + ":" + e.getValue().getAllObservables(); allScores.put(id, e.getKey()); } }
/** * create the info string; assumes that no values are null * * @param infoFields a map of info fields * @throws IOException for writer */ private void writeInfoString(Map<String, String> infoFields) throws IOException { if (infoFields.isEmpty()) { mWriter.write(VCFConstants.EMPTY_INFO_FIELD); return; } boolean isFirst = true; for (Map.Entry<String, String> entry : infoFields.entrySet()) { if (isFirst) isFirst = false; else mWriter.write(VCFConstants.INFO_FIELD_SEPARATOR); String key = entry.getKey(); mWriter.write(key); if (!entry.getValue().equals("")) { VCFInfoHeaderLine metaData = mHeader.getInfoHeaderLine(key); if (metaData == null || metaData.getCountType() != VCFHeaderLineCount.INTEGER || metaData.getCount() != 0) { mWriter.write("="); mWriter.write(entry.getValue()); } } } }
private void exportAttributes(Map<String, Object> attrMap) { for (Map.Entry<String, Object> e : attrMap.entrySet()) { if (e.getKey().equals(WikiPage.CHANGENOTE)) exportProperty("wiki:changeNote", (String) e.getValue(), STRING); else exportProperty(e.getKey(), e.getValue().toString(), STRING); } }
@Override public Set<String> getDefaultGroupNames(String worldName) { ConfigurationSection groups = this.permissions.getConfigurationSection("groups"); if (groups == null) { return Collections.emptySet(); } Set<String> names = new HashSet<String>(); String defaultGroupProperty = "default"; if (worldName != null) { defaultGroupProperty = buildPath("worlds", worldName, defaultGroupProperty); } for (Map.Entry<String, Object> entry : groups.getValues(false).entrySet()) { if (entry.getValue() instanceof ConfigurationSection) { ConfigurationSection groupSection = (ConfigurationSection) entry.getValue(); if (groupSection.getBoolean(defaultGroupProperty, false)) { names.add(entry.getKey()); } } } return Collections.unmodifiableSet(names); }
/** * Adds configured variables to the variable service. * * @param variableService service to add to * @param variables configured variables */ protected static void initVariables( VariableService variableService, Map<String, ConfigurationVariable> variables, EngineImportService engineImportService) { for (Map.Entry<String, ConfigurationVariable> entry : variables.entrySet()) { try { Pair<String, Boolean> arrayType = JavaClassHelper.isGetArrayType(entry.getValue().getType()); variableService.createNewVariable( null, entry.getKey(), arrayType.getFirst(), entry.getValue().isConstant(), arrayType.getSecond(), false, entry.getValue().getInitializationValue(), engineImportService); variableService.allocateVariableState(entry.getKey(), 0, null); } catch (VariableExistsException e) { throw new ConfigurationException("Error configuring variables: " + e.getMessage(), e); } catch (VariableTypeException e) { throw new ConfigurationException("Error configuring variables: " + e.getMessage(), e); } } }
/** * Filters non endpoint configuration parameters from parameter list and puts them together as * parameters string. According to given endpoint configuration type only non endpoint * configuration settings are added to parameter string. * * @param parameters * @param endpointConfigurationType * @return */ protected String getParameterString( Map<String, String> parameters, Class<? extends EndpointConfiguration> endpointConfigurationType) { StringBuilder paramString = new StringBuilder(); for (Map.Entry<String, String> parameterEntry : parameters.entrySet()) { Field field = ReflectionUtils.findField(endpointConfigurationType, parameterEntry.getKey()); if (field == null) { if (paramString.length() == 0) { paramString .append("?") .append(parameterEntry.getKey()) .append("=") .append(parameterEntry.getValue()); } else { paramString .append("&") .append(parameterEntry.getKey()) .append("=") .append(parameterEntry.getValue()); } } } return paramString.toString(); }
private void buildParameters(StringBuilder buf, boolean concat, String[] parameters) { if (getParameters() != null && getParameters().size() > 0) { List<String> includes = (parameters == null || parameters.length == 0 ? null : Arrays.asList(parameters)); boolean first = true; for (Map.Entry<String, String> entry : new TreeMap<String, String>(getParameters()).entrySet()) { if (entry.getKey() != null && entry.getKey().length() > 0 && (includes == null || includes.contains(entry.getKey()))) { if (first) { if (concat) { buf.append("?"); } first = false; } else { buf.append("&"); } buf.append(entry.getKey()); buf.append("="); buf.append(entry.getValue() == null ? "" : entry.getValue().trim()); } } } }
public static int solve() { Map<Integer, Integer> divisorSum = new HashMap<Integer, Integer>(); for (int i = 1; i <= 10000; i++) { divisorSum.put(i, Divisors.getSumDivisors(i)); } Map<Integer, Integer> amicable = new HashMap<Integer, Integer>(); for (Map.Entry e : divisorSum.entrySet()) { if (divisorSum.get(e.getValue()) == null) { continue; } if (divisorSum.get(e.getValue()).equals(e.getKey())) { amicable.put((Integer) e.getValue(), (Integer) e.getKey()); } } // System.out.println("amicable: " + amicable); int res = 0; for (Integer n : amicable.keySet()) { if (!n.equals(amicable.get(n))) { res += n; } } return res; }
@Override public boolean convertRecords2Links() { final Map<OIdentifiable, Change> newChangedValues = new HashMap<OIdentifiable, Change>(); for (Map.Entry<OIdentifiable, Change> entry : changes.entrySet()) { OIdentifiable identifiable = entry.getKey(); if (identifiable instanceof ORecord) { ORID identity = identifiable.getIdentity(); ORecord record = (ORecord) identifiable; identity = record.getIdentity(); newChangedValues.put(identity, entry.getValue()); } else newChangedValues.put(entry.getKey().getIdentity(), entry.getValue()); } for (Map.Entry<OIdentifiable, Change> entry : newChangedValues.entrySet()) { if (entry.getKey() instanceof ORecord) { ORecord record = (ORecord) entry.getKey(); newChangedValues.put(record, entry.getValue()); } else return false; } newEntries.clear(); changes.clear(); changes.putAll(newChangedValues); return true; }
@Test public void getDistinctKeysAndCounts_SortByKeyDescending() { Connection connection = null; ResultSet resultSet = null; try { ConnectionManager connectionManager = temporaryFileDatabase.getConnectionManager(true); initWithTestData(connectionManager); connection = connectionManager.getConnection(null); resultSet = DBQueries.getDistinctKeysAndCounts(true, NAME, connection); Map<String, Integer> resultSetToMap = resultSetToMap(resultSet); assertEquals(3, resultSetToMap.size()); Iterator<Map.Entry<String, Integer>> entriesIterator = resultSetToMap.entrySet().iterator(); Map.Entry entry = entriesIterator.next(); assertEquals("gps", entry.getKey()); assertEquals(1, entry.getValue()); entry = entriesIterator.next(); assertEquals("airbags", entry.getKey()); assertEquals(1, entry.getValue()); entry = entriesIterator.next(); assertEquals("abs", entry.getKey()); assertEquals(2, entry.getValue()); } finally { DBUtils.closeQuietly(resultSet); DBUtils.closeQuietly(connection); } }
private void resolveVariables(Context ctx, Properties initProps) { for (Map.Entry<Object, Object> entry : initProps.entrySet()) { if (entry.getValue() != null) { entry.setValue(ctx.replaceTokens((String) entry.getValue())); } } }
public void clopen(Object... settings) { config = getConfiguration(); if (mgmt != null && mgmt.isOpen()) mgmt.rollback(); if (null != tx && tx.isOpen()) tx.commit(); if (settings != null && settings.length > 0) { Map<TestConfigOption, Object> options = validateConfigOptions(settings); TitanManagement gconf = null; ModifiableConfiguration lconf = new ModifiableConfiguration( GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.LOCAL); for (Map.Entry<TestConfigOption, Object> option : options.entrySet()) { if (option.getKey().option.isLocal()) { lconf.set(option.getKey().option, option.getValue(), option.getKey().umbrella); } else { if (gconf == null) gconf = graph.openManagement(); gconf.set( ConfigElement.getPath(option.getKey().option, option.getKey().umbrella), option.getValue()); } } if (gconf != null) gconf.commit(); lconf.close(); } if (null != graph && graph.isOpen()) graph.close(); Preconditions.checkNotNull(config); open(config); }
/** histograms are sampled, but we just update points */ public void mergeHistograms( MetricInfo metricInfo, String meta, Map<Integer, MetricSnapshot> data, Map<String, Integer> metaCounters, Map<String, Map<Integer, Histogram>> histograms) { Map<Integer, MetricSnapshot> existing = metricInfo.get_metrics().get(meta); if (existing == null) { metricInfo.put_to_metrics(meta, data); Map<Integer, Histogram> histogramMap = new HashMap<>(); for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) { Histogram histogram = MetricUtils.metricSnapshot2Histogram(dataEntry.getValue()); histogramMap.put(dataEntry.getKey(), histogram); } histograms.put(meta, histogramMap); } else { for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) { Integer win = dataEntry.getKey(); MetricSnapshot snapshot = dataEntry.getValue(); MetricSnapshot old = existing.get(win); if (old == null) { existing.put(win, snapshot); histograms.get(meta).put(win, MetricUtils.metricSnapshot2Histogram(snapshot)); } else { if (snapshot.get_ts() >= old.get_ts()) { old.set_ts(snapshot.get_ts()); // update points MetricUtils.updateHistogramPoints(histograms.get(meta).get(win), snapshot.get_points()); } } } } updateMetricCounters(meta, metaCounters); }
public void prepare(String query, InetAddress toExclude) throws InterruptedException { for (Map.Entry<Host, HostConnectionPool> entry : pools.entrySet()) { if (entry.getKey().getAddress().equals(toExclude)) continue; // Let's not wait too long if we can't get a connection. Things // will fix themselves once the user tries a query anyway. Connection c = null; try { c = entry.getValue().borrowConnection(200, TimeUnit.MILLISECONDS); c.write(new PrepareMessage(query)).get(); } catch (ConnectionException e) { // Again, not being able to prepare the query right now is no big deal, so just ignore } catch (BusyConnectionException e) { // Same as above } catch (TimeoutException e) { // Same as above } catch (ExecutionException e) { // We shouldn't really get exception while preparing a // query, so log this (but ignore otherwise as it's not a big deal) logger.error( String.format( "Unexpected error while preparing query (%s) on %s", query, entry.getKey()), e); } finally { if (c != null) entry.getValue().returnConnection(c); } } }
/** * Prints a usage message to the given stream. * * @param out The output stream to write to. */ public void printUsage(OutputStream out) { Formatter formatter = new Formatter(out); Set<CommandLineOption> orderedOptions = new TreeSet<CommandLineOption>(new OptionComparator()); orderedOptions.addAll(optionsByString.values()); Map<String, String> lines = new LinkedHashMap<String, String>(); for (CommandLineOption option : orderedOptions) { Set<String> orderedOptionStrings = new TreeSet<String>(new OptionStringComparator()); orderedOptionStrings.addAll(option.getOptions()); List<String> prefixedStrings = new ArrayList<String>(); for (String optionString : orderedOptionStrings) { if (optionString.length() == 1) { prefixedStrings.add("-" + optionString); } else { prefixedStrings.add("--" + optionString); } } lines.put(GUtil.join(prefixedStrings, ", "), GUtil.elvis(option.getDescription(), "")); } int max = 0; for (String optionStr : lines.keySet()) { max = Math.max(max, optionStr.length()); } for (Map.Entry<String, String> entry : lines.entrySet()) { if (entry.getValue().length() == 0) { formatter.format("%s%n", entry.getKey()); } else { formatter.format("%-" + max + "s %s%n", entry.getKey(), entry.getValue()); } } formatter.flush(); }
public void updateRound() { ListIterator<Action> actionIterator = actions.listIterator(); while (actionIterator.hasNext()) { Action a = actionIterator.next(); if (currentRound >= (a.roundStarted + a.length)) { actionIterator.remove(); } } aliveRounds += 1; updateDrawLoc(); broadcast = (broadcast << 1) & 0x000FFFFF; if (regen > 0) regen--; Iterator<Map.Entry<Animation.AnimationType, Animation>> it = animations.entrySet().iterator(); Map.Entry<Animation.AnimationType, Animation> entry; while (it.hasNext()) { entry = it.next(); entry.getValue().updateRound(); if (!entry.getValue().isAlive()) { if (entry.getKey() != DEATH_EXPLOSION) it.remove(); } } currentRound++; }
protected String preprocessTextResource( String publicName, String category, String defaultName, Map<String, String> pairs, boolean verbose, File publicRoot) throws IOException { URL u = locateResource(publicName, category, defaultName, verbose, publicRoot); InputStream inp = u.openStream(); if (inp == null) { throw new RuntimeException("Jar corrupt? No " + defaultName + " resource!"); } // read fully into memory ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length; while ((length = inp.read(buffer)) != -1) { baos.write(buffer, 0, length); } // substitute String result = new String(baos.toByteArray()); for (Map.Entry<String, String> e : pairs.entrySet()) { if (e.getValue() != null) { result = result.replace(e.getKey(), e.getValue()); } } return result; }
public void addStatement(ContextControllerStatementBase statement, boolean isRecoveringResilient) throws ExprValidationException { // validation down the hierarchy ContextControllerStatementCtxCache caches = factory.validateStatement(statement); // add statement ContextControllerStatementDesc desc = new ContextControllerStatementDesc( statement, new ContextControllerStatementCtxCache[] {caches}); statements.put(statement.getStatementContext().getStatementId(), desc); // activate if this is the first statement if (statements.size() == 1) { activate(); // this may itself trigger a callback } // activate statement in respect to existing context partitions else { for (Map.Entry<Integer, ContextControllerTreeAgentInstanceList> entry : agentInstances.entrySet()) { AgentInstance agentInstance = startStatement( entry.getKey(), desc, rootContext, entry.getValue().getInitPartitionKey(), entry.getValue().getInitContextProperties(), isRecoveringResilient); entry.getValue().getAgentInstances().add(agentInstance); } } }
Entry encode(final T o, final String parentDN) throws LDAPPersistException { // Get the attributes that should be included in the entry. final LinkedHashMap<String, Attribute> attrMap = new LinkedHashMap<String, Attribute>(); attrMap.put("objectClass", objectClassAttribute); for (final Map.Entry<String, FieldInfo> e : fieldMap.entrySet()) { final FieldInfo i = e.getValue(); if (!i.includeInAdd()) { continue; } final Attribute a = i.encode(o, false); if (a != null) { attrMap.put(e.getKey(), a); } } for (final Map.Entry<String, GetterInfo> e : getterMap.entrySet()) { final GetterInfo i = e.getValue(); if (!i.includeInAdd()) { continue; } final Attribute a = i.encode(o); if (a != null) { attrMap.put(e.getKey(), a); } } final String dn = constructDN(o, parentDN, attrMap); final Entry entry = new Entry(dn, attrMap.values()); if (postEncodeMethod != null) { try { postEncodeMethod.invoke(o, entry); } catch (Throwable t) { debugException(t); if (t instanceof InvocationTargetException) { t = ((InvocationTargetException) t).getTargetException(); } throw new LDAPPersistException( ERR_OBJECT_HANDLER_ERROR_INVOKING_POST_ENCODE_METHOD.get( postEncodeMethod.getName(), type.getName(), getExceptionMessage(t)), t); } } setDNAndEntryFields(o, entry); if (superclassHandler != null) { final Entry e = superclassHandler.encode(o, parentDN); for (final Attribute a : e.getAttributes()) { entry.addAttribute(a); } } return entry; }
public void putAll(Map<? extends K, ? extends V> map) { for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) { Checker.checkType(entry.getKey()); Checker.checkType(entry.getValue()); this.map.put(entry.getKey(), entry.getValue()); } }